Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poc
poc-api
Commits
ec23cc35
Commit
ec23cc35
authored
Aug 21, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat[智能问数]:
1.修改对话接口流程 2.新增生成洞察报告和查询接口 3.智能问数示例接口[猜你想问,数据库示例,文件示例]
parent
1a46b7b2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
1206 additions
and
2 deletions
+1206
-2
AiBiService.java
src/main/java/cn/com/poc/ai_bi/aggregate/AiBiService.java
+32
-0
AiBiServiceImpl.java
...java/cn/com/poc/ai_bi/aggregate/impl/AiBiServiceImpl.java
+351
-0
BizAiBiExampleConvert.java
.../java/cn/com/poc/ai_bi/convert/BizAiBiExampleConvert.java
+53
-0
AIBiExampleDto.java
src/main/java/cn/com/poc/ai_bi/dto/AIBiExampleDto.java
+38
-0
AiBiGenerateInsightReportDto.java
...va/cn/com/poc/ai_bi/dto/AiBiGenerateInsightReportDto.java
+50
-0
BizAiBiExampleDto.java
src/main/java/cn/com/poc/ai_bi/dto/BizAiBiExampleDto.java
+79
-0
BizAiBiExampleEntity.java
...in/java/cn/com/poc/ai_bi/entity/BizAiBiExampleEntity.java
+79
-0
BizAiBiExampleModel.java
...main/java/cn/com/poc/ai_bi/model/BizAiBiExampleModel.java
+124
-0
BizAiBiExampleRepository.java
...cn/com/poc/ai_bi/repository/BizAiBiExampleRepository.java
+6
-0
AiBiRest.java
src/main/java/cn/com/poc/ai_bi/rest/AiBiRest.java
+29
-0
AiBiRestImpl.java
src/main/java/cn/com/poc/ai_bi/rest/impl/AiBiRestImpl.java
+42
-1
BizAiBiExampleService.java
.../java/cn/com/poc/ai_bi/service/BizAiBiExampleService.java
+21
-0
BizAiBiExampleServiceImpl.java
...com/poc/ai_bi/service/impl/BizAiBiExampleServiceImpl.java
+88
-0
LargeModelFunctionEnum.java
...y/resource/demand/ai/function/LargeModelFunctionEnum.java
+3
-0
EChartGenerateFunction.java
...rce/demand/ai/function/echart/EChartGenerateFunction.java
+139
-0
ChainServiceImpl.java
.../cn/com/poc/thirdparty/service/impl/ChainServiceImpl.java
+6
-0
AIBiTest.java
src/test/java/cn/com/poc/ai_bi/AIBiTest.java
+49
-0
ChainServiceTest.java
...irdparty/resource/demand/ai/service/ChainServiceTest.java
+17
-1
No files found.
src/main/java/cn/com/poc/ai_bi/aggregate/AiBiService.java
View file @
ec23cc35
...
@@ -18,6 +18,38 @@ public interface AiBiService {
...
@@ -18,6 +18,38 @@ public interface AiBiService {
* @param databaseIds 数据库ids
* @param databaseIds 数据库ids
* @param userId 用户id
* @param userId 用户id
*/
*/
@Deprecated
void
call
(
String
dialoguesId
,
String
input
,
String
fileUrl
,
Integer
[]
knowledgeIds
,
Integer
[]
databaseIds
,
Long
userId
)
throws
Exception
;
void
call
(
String
dialoguesId
,
String
input
,
String
fileUrl
,
Integer
[]
knowledgeIds
,
Integer
[]
databaseIds
,
Long
userId
)
throws
Exception
;
/**
* 调用智能问数生成式BI服务
*
* @param dialoguesId 对话id
* @param input 问题
* @param fileUrl 文件地址
* @param knowledgeIds 知识库ids
* @param databaseIds 数据库ids
* @param userId 用户id
*/
void
callV2
(
String
dialoguesId
,
String
input
,
String
fileUrl
,
Integer
[]
knowledgeIds
,
Integer
[]
databaseIds
,
Long
userId
)
throws
Exception
;
/**
* 生成洞察报告
*
* @param dialoguesId
* @param fileUrl
* @param SQL
* @param result
* @param question
*/
void
generateInsightReport
(
String
dialoguesId
,
String
fileUrl
,
String
SQL
,
String
result
,
String
question
)
throws
Exception
;
/**
* 获取洞察报告
*
* @param dialoguesId
*/
String
getInsightReport
(
String
dialoguesId
);
}
}
src/main/java/cn/com/poc/ai_bi/aggregate/impl/AiBiServiceImpl.java
View file @
ec23cc35
This diff is collapsed.
Click to expand it.
src/main/java/cn/com/poc/ai_bi/convert/BizAiBiExampleConvert.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
convert
;
import
cn.com.poc.ai_bi.model.BizAiBiExampleModel
;
import
cn.com.poc.ai_bi.entity.BizAiBiExampleEntity
;
import
cn.com.poc.ai_bi.dto.BizAiBiExampleDto
;
public
class
BizAiBiExampleConvert
{
public
static
BizAiBiExampleEntity
modelToEntity
(
BizAiBiExampleModel
model
){
BizAiBiExampleEntity
entity
=
new
BizAiBiExampleEntity
();
entity
.
setId
(
model
.
getId
());
entity
.
setTitle
(
model
.
getTitle
());
entity
.
setDataType
(
model
.
getDataType
());
entity
.
setDataRelation
(
model
.
getDataRelation
());
entity
.
setExampleDesc
(
model
.
getExampleDesc
());
entity
.
setQuestion
(
model
.
getQuestion
());
return
entity
;
}
public
static
BizAiBiExampleModel
entityToModel
(
BizAiBiExampleEntity
entity
){
BizAiBiExampleModel
model
=
new
BizAiBiExampleModel
();
model
.
setId
(
entity
.
getId
());
model
.
setTitle
(
entity
.
getTitle
());
model
.
setDataType
(
entity
.
getDataType
());
model
.
setDataRelation
(
entity
.
getDataRelation
());
model
.
setExampleDesc
(
entity
.
getExampleDesc
());
model
.
setQuestion
(
entity
.
getQuestion
());
return
model
;
}
public
static
BizAiBiExampleDto
entityToDto
(
BizAiBiExampleEntity
entity
){
BizAiBiExampleDto
dto
=
new
BizAiBiExampleDto
();
dto
.
setId
(
entity
.
getId
());
dto
.
setTitle
(
entity
.
getTitle
());
dto
.
setDataType
(
entity
.
getDataType
());
dto
.
setDataRelation
(
entity
.
getDataRelation
());
dto
.
setExampleDesc
(
entity
.
getExampleDesc
());
dto
.
setQuestion
(
entity
.
getQuestion
());
return
dto
;
}
public
static
BizAiBiExampleEntity
dtoToEntity
(
BizAiBiExampleDto
dto
){
BizAiBiExampleEntity
entity
=
new
BizAiBiExampleEntity
();
entity
.
setId
(
dto
.
getId
());
entity
.
setTitle
(
dto
.
getTitle
());
entity
.
setDataType
(
dto
.
getDataType
());
entity
.
setDataRelation
(
dto
.
getDataRelation
());
entity
.
setExampleDesc
(
dto
.
getExampleDesc
());
entity
.
setQuestion
(
dto
.
getQuestion
());
return
entity
;
}
}
\ No newline at end of file
src/main/java/cn/com/poc/ai_bi/dto/AIBiExampleDto.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
dto
;
import
java.util.List
;
/**
* @author 52747
* @date 2025/8/20
*/
public
class
AIBiExampleDto
{
private
List
<
BizAiBiExampleDto
>
featuredExamples
;
private
List
<
BizAiBiExampleDto
>
databaseExamples
;
private
List
<
BizAiBiExampleDto
>
fileExamples
;
public
List
<
BizAiBiExampleDto
>
getFeaturedExamples
()
{
return
featuredExamples
;
}
public
void
setFeaturedExamples
(
List
<
BizAiBiExampleDto
>
featuredExamples
)
{
this
.
featuredExamples
=
featuredExamples
;
}
public
List
<
BizAiBiExampleDto
>
getDatabaseExamples
()
{
return
databaseExamples
;
}
public
void
setDatabaseExamples
(
List
<
BizAiBiExampleDto
>
databaseExamples
)
{
this
.
databaseExamples
=
databaseExamples
;
}
public
List
<
BizAiBiExampleDto
>
getFileExamples
()
{
return
fileExamples
;
}
public
void
setFileExamples
(
List
<
BizAiBiExampleDto
>
fileExamples
)
{
this
.
fileExamples
=
fileExamples
;
}
}
src/main/java/cn/com/poc/ai_bi/dto/AiBiGenerateInsightReportDto.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
dto
;
/**
* @author 52747
* @date 2025/8/20
*/
public
class
AiBiGenerateInsightReportDto
{
private
String
fileUrl
,
SQL
,
result
,
question
,
dialoguesId
;
public
String
getFileUrl
()
{
return
fileUrl
;
}
public
void
setFileUrl
(
String
fileUrl
)
{
this
.
fileUrl
=
fileUrl
;
}
public
String
getDialoguesId
()
{
return
dialoguesId
;
}
public
void
setDialoguesId
(
String
dialoguesId
)
{
this
.
dialoguesId
=
dialoguesId
;
}
public
String
getSQL
()
{
return
SQL
;
}
public
void
setSQL
(
String
SQL
)
{
this
.
SQL
=
SQL
;
}
public
String
getResult
()
{
return
result
;
}
public
void
setResult
(
String
result
)
{
this
.
result
=
result
;
}
public
String
getQuestion
()
{
return
question
;
}
public
void
setQuestion
(
String
question
)
{
this
.
question
=
question
;
}
}
src/main/java/cn/com/poc/ai_bi/dto/BizAiBiExampleDto.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
dto
;
public
class
BizAiBiExampleDto
{
private
static
final
long
serialVersionUID
=
1L
;
/** id
*
*/
private
java
.
lang
.
Long
id
;
public
java
.
lang
.
Long
getId
(){
return
this
.
id
;
}
public
void
setId
(
java
.
lang
.
Long
id
){
this
.
id
=
id
;
}
/** title
*标题
*/
private
java
.
lang
.
String
title
;
public
java
.
lang
.
String
getTitle
(){
return
this
.
title
;
}
public
void
setTitle
(
java
.
lang
.
String
title
){
this
.
title
=
title
;
}
/** data_type
*
*/
private
java
.
lang
.
String
dataType
;
public
java
.
lang
.
String
getDataType
(){
return
this
.
dataType
;
}
public
void
setDataType
(
java
.
lang
.
String
dataType
){
this
.
dataType
=
dataType
;
}
/** data_relation
*
*/
private
java
.
lang
.
String
dataRelation
;
public
java
.
lang
.
String
getDataRelation
(){
return
this
.
dataRelation
;
}
public
void
setDataRelation
(
java
.
lang
.
String
dataRelation
){
this
.
dataRelation
=
dataRelation
;
}
/** example_desc
*
*/
private
java
.
lang
.
String
exampleDesc
;
public
java
.
lang
.
String
getExampleDesc
(){
return
this
.
exampleDesc
;
}
public
void
setExampleDesc
(
java
.
lang
.
String
exampleDesc
){
this
.
exampleDesc
=
exampleDesc
;
}
/** question
*
*/
private
java
.
lang
.
String
question
;
public
java
.
lang
.
String
getQuestion
(){
return
this
.
question
;
}
public
void
setQuestion
(
java
.
lang
.
String
question
){
this
.
question
=
question
;
}
}
\ No newline at end of file
src/main/java/cn/com/poc/ai_bi/entity/BizAiBiExampleEntity.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
entity
;
public
class
BizAiBiExampleEntity
{
private
static
final
long
serialVersionUID
=
1L
;
/** id
*
*/
private
java
.
lang
.
Long
id
;
public
java
.
lang
.
Long
getId
(){
return
this
.
id
;
}
public
void
setId
(
java
.
lang
.
Long
id
){
this
.
id
=
id
;
}
/** title
*标题
*/
private
java
.
lang
.
String
title
;
public
java
.
lang
.
String
getTitle
(){
return
this
.
title
;
}
public
void
setTitle
(
java
.
lang
.
String
title
){
this
.
title
=
title
;
}
/** data_type
*
*/
private
java
.
lang
.
String
dataType
;
public
java
.
lang
.
String
getDataType
(){
return
this
.
dataType
;
}
public
void
setDataType
(
java
.
lang
.
String
dataType
){
this
.
dataType
=
dataType
;
}
/** data_relation
*
*/
private
java
.
lang
.
String
dataRelation
;
public
java
.
lang
.
String
getDataRelation
(){
return
this
.
dataRelation
;
}
public
void
setDataRelation
(
java
.
lang
.
String
dataRelation
){
this
.
dataRelation
=
dataRelation
;
}
/** example_desc
*
*/
private
java
.
lang
.
String
exampleDesc
;
public
java
.
lang
.
String
getExampleDesc
(){
return
this
.
exampleDesc
;
}
public
void
setExampleDesc
(
java
.
lang
.
String
exampleDesc
){
this
.
exampleDesc
=
exampleDesc
;
}
/** question
*
*/
private
java
.
lang
.
String
question
;
public
java
.
lang
.
String
getQuestion
(){
return
this
.
question
;
}
public
void
setQuestion
(
java
.
lang
.
String
question
){
this
.
question
=
question
;
}
}
\ No newline at end of file
src/main/java/cn/com/poc/ai_bi/model/BizAiBiExampleModel.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
model
;
import
java.io.Serializable
;
import
cn.com.yict.framemax.data.model.BaseModelClass
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
javax.persistence.Id
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
/**
* Model class for biz_ai_bi_example
* AIBI示例表
*/
@Entity
@Table
(
name
=
"biz_ai_bi_example"
)
@DynamicInsert
@DynamicUpdate
public
class
BizAiBiExampleModel
extends
BaseModelClass
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/** id
*
*/
private
java
.
lang
.
Long
id
;
@Column
(
name
=
"id"
,
length
=
19
)
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
public
java
.
lang
.
Long
getId
(){
return
this
.
id
;
}
public
void
setId
(
java
.
lang
.
Long
id
){
this
.
id
=
id
;
super
.
addValidField
(
"id"
);
}
/** title
*标题
*/
private
java
.
lang
.
String
title
;
@Column
(
name
=
"title"
,
length
=
100
)
public
java
.
lang
.
String
getTitle
(){
return
this
.
title
;
}
public
void
setTitle
(
java
.
lang
.
String
title
){
this
.
title
=
title
;
super
.
addValidField
(
"title"
);
}
/** data_type
*
*/
private
java
.
lang
.
String
dataType
;
@Column
(
name
=
"data_type"
,
length
=
100
)
public
java
.
lang
.
String
getDataType
(){
return
this
.
dataType
;
}
public
void
setDataType
(
java
.
lang
.
String
dataType
){
this
.
dataType
=
dataType
;
super
.
addValidField
(
"dataType"
);
}
/** data_relation
*
*/
private
java
.
lang
.
String
dataRelation
;
@Column
(
name
=
"data_relation"
,
length
=
100
)
public
java
.
lang
.
String
getDataRelation
(){
return
this
.
dataRelation
;
}
public
void
setDataRelation
(
java
.
lang
.
String
dataRelation
){
this
.
dataRelation
=
dataRelation
;
super
.
addValidField
(
"dataRelation"
);
}
/** example_desc
*
*/
private
java
.
lang
.
String
exampleDesc
;
@Column
(
name
=
"example_desc"
,
length
=
2147483647
)
public
java
.
lang
.
String
getExampleDesc
(){
return
this
.
exampleDesc
;
}
public
void
setExampleDesc
(
java
.
lang
.
String
exampleDesc
){
this
.
exampleDesc
=
exampleDesc
;
super
.
addValidField
(
"exampleDesc"
);
}
/** question
*
*/
private
java
.
lang
.
String
question
;
@Column
(
name
=
"question"
,
length
=
100
)
public
java
.
lang
.
String
getQuestion
(){
return
this
.
question
;
}
public
void
setQuestion
(
java
.
lang
.
String
question
){
this
.
question
=
question
;
super
.
addValidField
(
"question"
);
}
}
\ No newline at end of file
src/main/java/cn/com/poc/ai_bi/repository/BizAiBiExampleRepository.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
repository
;
import
cn.com.yict.framemax.data.repository.Repository
;
import
cn.com.poc.ai_bi.model.BizAiBiExampleModel
;
public
interface
BizAiBiExampleRepository
extends
Repository
<
BizAiBiExampleModel
,
java
.
lang
.
Long
>
{
}
\ No newline at end of file
src/main/java/cn/com/poc/ai_bi/rest/AiBiRest.java
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
rest
;
package
cn
.
com
.
poc
.
ai_bi
.
rest
;
import
cn.com.poc.ai_bi.dto.AIBiExampleDto
;
import
cn.com.poc.ai_bi.dto.AiBiDialoguesDto
;
import
cn.com.poc.ai_bi.dto.AiBiDialoguesDto
;
import
cn.com.poc.ai_bi.dto.AiBiGenerateInsightReportDto
;
import
cn.com.poc.common.utils.SSEUtil
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Permission
;
import
cn.com.yict.framemax.web.permission.Permission
;
import
org.springframework.security.core.parameters.P
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
java.io.IOException
;
/**
/**
* 智数:智能问数生成式BI服务接口
* 智数:智能问数生成式BI服务接口
...
@@ -21,4 +28,26 @@ public interface AiBiRest extends BaseRest {
...
@@ -21,4 +28,26 @@ public interface AiBiRest extends BaseRest {
*/
*/
void
call
(
@RequestBody
AiBiDialoguesDto
dto
)
throws
Exception
;
void
call
(
@RequestBody
AiBiDialoguesDto
dto
)
throws
Exception
;
/**
* 生成洞察报告
* <p>
* sse
*
* @param dto
*/
void
generateInsightReport
(
@RequestBody
AiBiGenerateInsightReportDto
dto
)
throws
Exception
;
/**
* 获取洞察报告
*
* @param dialoguesId
*/
String
getInsightReport
(
@RequestParam
String
dialoguesId
);
/**
* 获取示例
* @return
* @throws Exception
*/
AIBiExampleDto
getExample
()
throws
Exception
;
}
}
src/main/java/cn/com/poc/ai_bi/rest/impl/AiBiRestImpl.java
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
rest
.
impl
;
package
cn
.
com
.
poc
.
ai_bi
.
rest
.
impl
;
import
cn.com.poc.ai_bi.aggregate.AiBiService
;
import
cn.com.poc.ai_bi.aggregate.AiBiService
;
import
cn.com.poc.ai_bi.convert.BizAiBiExampleConvert
;
import
cn.com.poc.ai_bi.dto.AIBiExampleDto
;
import
cn.com.poc.ai_bi.dto.AiBiDialoguesDto
;
import
cn.com.poc.ai_bi.dto.AiBiDialoguesDto
;
import
cn.com.poc.ai_bi.dto.AiBiGenerateInsightReportDto
;
import
cn.com.poc.ai_bi.dto.BizAiBiExampleDto
;
import
cn.com.poc.ai_bi.rest.AiBiRest
;
import
cn.com.poc.ai_bi.rest.AiBiRest
;
import
cn.com.poc.ai_bi.service.BizAiBiExampleService
;
import
cn.com.poc.common.utils.Assert
;
import
cn.com.poc.common.utils.Assert
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.StringUtils
;
import
cn.com.poc.support.security.oauth.entity.UserBaseEntity
;
import
cn.com.poc.support.security.oauth.entity.UserBaseEntity
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
/**
* @author alex.yao
* @author alex.yao
...
@@ -23,6 +31,10 @@ public class AiBiRestImpl implements AiBiRest {
...
@@ -23,6 +31,10 @@ public class AiBiRestImpl implements AiBiRest {
@Resource
@Resource
private
AiBiService
aiBiService
;
private
AiBiService
aiBiService
;
@Resource
private
BizAiBiExampleService
bizAiBiExampleService
;
@Override
@Override
public
void
call
(
AiBiDialoguesDto
dto
)
throws
Exception
{
public
void
call
(
AiBiDialoguesDto
dto
)
throws
Exception
{
Assert
.
notNull
(
dto
);
Assert
.
notNull
(
dto
);
...
@@ -33,11 +45,40 @@ public class AiBiRestImpl implements AiBiRest {
...
@@ -33,11 +45,40 @@ public class AiBiRestImpl implements AiBiRest {
if
(
ObjectUtils
.
isEmpty
(
userBaseEntity
))
{
if
(
ObjectUtils
.
isEmpty
(
userBaseEntity
))
{
throw
new
BusinessException
(
"用户未登录"
);
throw
new
BusinessException
(
"用户未登录"
);
}
}
aiBiService
.
call
(
dto
.
getDialoguesId
(),
aiBiService
.
call
V2
(
dto
.
getDialoguesId
(),
dto
.
getInput
(),
dto
.
getInput
(),
dto
.
getFileUrl
(),
dto
.
getFileUrl
(),
dto
.
getKnowledgeIds
(),
dto
.
getKnowledgeIds
(),
dto
.
getDatabaseIds
(),
dto
.
getDatabaseIds
(),
userBaseEntity
.
getUserId
());
userBaseEntity
.
getUserId
());
}
}
@Override
public
void
generateInsightReport
(
AiBiGenerateInsightReportDto
dto
)
throws
Exception
{
Assert
.
notBlank
(
dto
.
getDialoguesId
(),
"对话id不能为空"
);
Assert
.
notBlank
(
dto
.
getResult
(),
"数据集不能为空"
);
Assert
.
notBlank
(
dto
.
getQuestion
(),
"问题不能为空"
);
Assert
.
isTrue
(
StringUtils
.
isNotBlank
(
dto
.
getFileUrl
())
||
StringUtils
.
isNotBlank
(
dto
.
getSQL
()),
"SQL 或 fileUrl 不能同时为空"
);
aiBiService
.
generateInsightReport
(
dto
.
getDialoguesId
(),
dto
.
getFileUrl
(),
dto
.
getSQL
(),
dto
.
getResult
(),
dto
.
getQuestion
());
}
@Override
public
String
getInsightReport
(
String
dialoguesId
)
{
Assert
.
notBlank
(
dialoguesId
,
"对话id不能为空"
);
return
aiBiService
.
getInsightReport
(
dialoguesId
);
}
@Override
public
AIBiExampleDto
getExample
()
throws
Exception
{
List
<
BizAiBiExampleDto
>
exampleDtos
=
bizAiBiExampleService
.
findByExample
(
BizAiBiExampleConvert
.
dtoToEntity
(
new
BizAiBiExampleDto
()),
null
)
.
stream
()
.
map
(
BizAiBiExampleConvert:
:
entityToDto
)
.
collect
(
Collectors
.
toList
());
AIBiExampleDto
aiBiExampleDto
=
new
AIBiExampleDto
();
aiBiExampleDto
.
setDatabaseExamples
(
exampleDtos
.
stream
().
filter
(
dto
->
dto
.
getDataType
().
equals
(
"FILE"
)).
collect
(
Collectors
.
toList
()));
aiBiExampleDto
.
setFileExamples
(
exampleDtos
.
stream
().
filter
(
dto
->
dto
.
getDataType
().
equals
(
"DATA_BASE"
)).
collect
(
Collectors
.
toList
()));
aiBiExampleDto
.
setFeaturedExamples
(
exampleDtos
.
stream
().
filter
(
dto
->
dto
.
getDataType
().
equals
(
"FEATURED"
)).
collect
(
Collectors
.
toList
()));
return
aiBiExampleDto
;
}
}
}
src/main/java/cn/com/poc/ai_bi/service/BizAiBiExampleService.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
service
;
import
cn.com.yict.framemax.core.service.BaseService
;
import
cn.com.poc.ai_bi.entity.BizAiBiExampleEntity
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
import
java.util.Collection
;
import
java.util.List
;
public
interface
BizAiBiExampleService
extends
BaseService
{
BizAiBiExampleEntity
get
(
java
.
lang
.
Long
id
)
throws
Exception
;
List
<
BizAiBiExampleEntity
>
findByExample
(
BizAiBiExampleEntity
example
,
PagingInfo
pagingInfo
)
throws
Exception
;
BizAiBiExampleEntity
save
(
BizAiBiExampleEntity
entity
)
throws
Exception
;
BizAiBiExampleEntity
update
(
BizAiBiExampleEntity
entity
)
throws
Exception
;
void
deletedById
(
java
.
lang
.
Long
id
)
throws
Exception
;
}
\ No newline at end of file
src/main/java/cn/com/poc/ai_bi/service/impl/BizAiBiExampleServiceImpl.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
.
service
.
impl
;
import
cn.com.yict.framemax.core.service.impl.BaseServiceImpl
;
import
cn.com.poc.ai_bi.service.BizAiBiExampleService
;
import
cn.com.poc.ai_bi.model.BizAiBiExampleModel
;
import
cn.com.poc.ai_bi.entity.BizAiBiExampleEntity
;
import
cn.com.poc.ai_bi.convert.BizAiBiExampleConvert
;
import
cn.com.poc.ai_bi.repository.BizAiBiExampleRepository
;
import
cn.com.yict.framemax.data.model.PagingInfo
;
import
org.springframework.stereotype.Service
;
import
org.apache.commons.collections4.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.stream.Collectors
;
import
java.util.List
;
import
javax.annotation.Resource
;
import
org.springframework.util.Assert
;
@Service
public
class
BizAiBiExampleServiceImpl
extends
BaseServiceImpl
implements
BizAiBiExampleService
{
@Resource
private
BizAiBiExampleRepository
repository
;
public
BizAiBiExampleEntity
get
(
java
.
lang
.
Long
id
)
throws
Exception
{
Assert
.
notNull
(
id
);
BizAiBiExampleModel
model
=
this
.
repository
.
get
(
id
);
if
(
model
==
null
){
return
null
;
}
return
BizAiBiExampleConvert
.
modelToEntity
(
model
);
}
public
List
<
BizAiBiExampleEntity
>
findByExample
(
BizAiBiExampleEntity
example
,
PagingInfo
pagingInfo
)
throws
Exception
{
List
<
BizAiBiExampleEntity
>
result
=
new
ArrayList
<
BizAiBiExampleEntity
>();
BizAiBiExampleModel
model
=
new
BizAiBiExampleModel
();
if
(
example
!=
null
){
model
=
BizAiBiExampleConvert
.
entityToModel
(
example
);
}
List
<
BizAiBiExampleModel
>
models
=
this
.
repository
.
findByExample
(
model
,
pagingInfo
);
if
(
CollectionUtils
.
isNotEmpty
(
models
))
{
result
=
models
.
stream
().
map
(
BizAiBiExampleConvert:
:
modelToEntity
).
collect
(
Collectors
.
toList
());
}
return
result
;
}
public
BizAiBiExampleEntity
save
(
BizAiBiExampleEntity
entity
)
throws
Exception
{
Assert
.
notNull
(
entity
);
entity
.
setId
(
null
);
BizAiBiExampleModel
model
=
BizAiBiExampleConvert
.
entityToModel
(
entity
);
BizAiBiExampleModel
saveModel
=
this
.
repository
.
save
(
model
);
return
BizAiBiExampleConvert
.
modelToEntity
(
saveModel
);
}
public
BizAiBiExampleEntity
update
(
BizAiBiExampleEntity
entity
)
throws
Exception
{
Assert
.
notNull
(
entity
);
Assert
.
notNull
(
entity
.
getId
(),
"update pk can not be null"
);
BizAiBiExampleModel
model
=
this
.
repository
.
get
(
entity
.
getId
());
if
(
entity
.
getTitle
()
!=
null
){
model
.
setTitle
(
entity
.
getTitle
());
}
if
(
entity
.
getDataType
()
!=
null
){
model
.
setDataType
(
entity
.
getDataType
());
}
if
(
entity
.
getDataRelation
()
!=
null
){
model
.
setDataRelation
(
entity
.
getDataRelation
());
}
if
(
entity
.
getExampleDesc
()
!=
null
){
model
.
setExampleDesc
(
entity
.
getExampleDesc
());
}
if
(
entity
.
getQuestion
()
!=
null
){
model
.
setQuestion
(
entity
.
getQuestion
());
}
BizAiBiExampleModel
saveModel
=
this
.
repository
.
save
(
model
);
return
BizAiBiExampleConvert
.
modelToEntity
(
saveModel
);
}
public
void
deletedById
(
java
.
lang
.
Long
id
)
throws
Exception
{
Assert
.
notNull
(
id
);
BizAiBiExampleModel
model
=
this
.
repository
.
get
(
id
);
if
(
model
!=
null
){
}
}
}
\ No newline at end of file
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/LargeModelFunctionEnum.java
View file @
ec23cc35
...
@@ -6,6 +6,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.function.chart_generate.ChartGen
...
@@ -6,6 +6,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.function.chart_generate.ChartGen
import
cn.com.poc.thirdparty.resource.demand.ai.function.csv_data_analysis.CSVFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.csv_data_analysis.CSVFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.document_reader.DocumentReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.document_reader.DocumentReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.document_understanding.DocumentUnderstandIngFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.document_understanding.DocumentUnderstandIngFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.echart.EChartGenerateFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.extraction.ContractExtractionFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.extraction.ContractExtractionFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.html_reader.HtmlReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.html_reader.HtmlReaderFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.image_ocr.ImageOCRFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.image_ocr.ImageOCRFunction
;
...
@@ -54,6 +55,8 @@ public enum LargeModelFunctionEnum {
...
@@ -54,6 +55,8 @@ public enum LargeModelFunctionEnum {
chart_generate
(
ChartGenerateFunction
.
class
),
chart_generate
(
ChartGenerateFunction
.
class
),
echart_generate
(
EChartGenerateFunction
.
class
),
csv_data_analysis
(
CSVFunction
.
class
),
csv_data_analysis
(
CSVFunction
.
class
),
completion_of_travel_v2_form
(
TravelFormV2Function
.
class
),
completion_of_travel_v2_form
(
TravelFormV2Function
.
class
),
...
...
src/main/java/cn/com/poc/thirdparty/resource/demand/ai/function/echart/EChartGenerateFunction.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
function
.
echart
;
import
cn.com.poc.agent_application.entity.KnowledgeContentResult
;
import
cn.com.poc.agent_application.entity.Variable
;
import
cn.com.poc.common.utils.JsonUtils
;
import
cn.com.poc.common.utils.StringUtils
;
import
cn.com.poc.thirdparty.resource.demand.ai.constants.LLMRoleEnum
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Message
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDemandResult
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.Thinking
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.AbstractFunctionResult
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.AbstractLargeModelFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.chart_generate.ChartGenerateFunction
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.entity.FunctionLLMConfig
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.entity.Parameters
;
import
cn.com.poc.thirdparty.resource.demand.ai.function.entity.Properties
;
import
cn.com.poc.thirdparty.service.LLMService
;
import
cn.hutool.core.collection.ListUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* @author 52747
* @date 2025/8/19
*/
@Component
public
class
EChartGenerateFunction
extends
AbstractLargeModelFunction
{
@Resource
private
LLMService
llmService
;
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ChartGenerateFunction
.
class
);
private
final
String
DESC
=
"根据用户问题、SQL和SQL执行结果,生成折线图,饼图,柱状图"
;
private
final
FunctionLLMConfig
functionLLMConfig
=
new
FunctionLLMConfig
.
FunctionLLMConfigBuilder
()
.
name
(
"eChart_generate"
)
.
description
(
DESC
)
.
parameters
(
new
Parameters
(
"object"
)
.
addProperties
(
"question"
,
new
Properties
(
"string"
,
"用户问题优化后的问题"
))
.
addProperties
(
"sql"
,
new
Properties
(
"string"
,
"如果用户问题中存在数据则解析或截取对应的数据"
))
.
addProperties
(
"sql_result"
,
new
Properties
(
"string"
,
"根据用户问题和上下文生成的图表主题"
)))
.
build
();
private
static
String
PROMPT
=
"## 角色\n"
+
"你的任务是根据数据和用户提问生成EChart 的Option Json\n"
+
"\n"
+
"## 限制\n"
+
"- 输出格式: 适用JSON格式输出\n"
+
"- 仅输出JSON内容\n"
+
"- 图表限制: 折线图、饼图、柱状图\n"
+
"- 如果数据与问题不能生成图表,则输出 : { \"skip\" : true }\n"
+
"\n"
+
"## 用户提问\n"
+
"${QUESTION}\n"
+
"\n"
+
"## SQL\n"
+
"${SQL}\n"
+
"\n"
+
"## SQL Result\n"
+
"${SQL_RESULT}"
;
@Override
public
AbstractFunctionResult
<
String
>
doFunction
(
String
content
,
String
identifier
,
List
<
DBChainResult
>
dbChainResults
,
List
<
KnowledgeContentResult
>
knowledgeContentResults
)
{
AbstractFunctionResult
<
String
>
result
=
new
AbstractFunctionResult
<>();
result
.
setFunctionResult
(
StringUtils
.
EMPTY
);
result
.
setPromptContent
(
StringUtils
.
EMPTY
);
if
(
StringUtils
.
isBlank
(
content
))
{
return
result
;
}
JSONObject
jsonObject
=
JSON
.
parseObject
(
content
);
if
(!
jsonObject
.
containsKey
(
"question"
)
||
!
jsonObject
.
containsKey
(
"sql"
)
||
!
jsonObject
.
containsKey
(
"sql_result"
))
{
logger
.
warn
(
"缺少必要参数,无法生成图表,content:{}"
,
content
);
return
result
;
}
String
question
=
jsonObject
.
getString
(
"question"
);
String
sql
=
jsonObject
.
getString
(
"sql"
);
String
sqlResult
=
jsonObject
.
getString
(
"sql_result"
);
String
option
=
generateEChart
(
sql
,
sqlResult
,
question
);
JSONObject
optionJSONObject
=
JSON
.
parseObject
(
option
);
if
(
optionJSONObject
.
containsKey
(
"skip"
))
{
return
result
;
}
result
.
setPromptContent
(
option
);
result
.
setFunctionResult
(
option
);
return
result
;
}
@Override
public
String
getDesc
()
{
return
DESC
;
}
@Override
public
List
<
String
>
getLLMConfig
()
{
return
ListUtil
.
toList
(
JsonUtils
.
serialize
(
functionLLMConfig
));
}
@Override
public
List
<
String
>
getLLMConfig
(
List
<
Variable
>
variableStructure
)
{
return
this
.
getLLMConfig
();
}
private
String
generateEChart
(
String
SQL
,
String
SQLResult
,
String
question
)
{
String
model
=
"ep-20250814152748-6jlnx"
;
String
prompt
=
PROMPT
.
replace
(
"${QUESTION}"
,
question
)
.
replace
(
"${SQL}"
,
SQL
)
.
replace
(
"${SQL_RESULT}"
,
SQLResult
);
Message
systemMessage
=
new
Message
();
systemMessage
.
setRole
(
LLMRoleEnum
.
SYSTEM
.
getRole
());
systemMessage
.
setContent
(
prompt
);
Message
userMessage
=
new
Message
();
userMessage
.
setRole
(
LLMRoleEnum
.
USER
.
getRole
());
userMessage
.
setContent
(
question
);
LargeModelResponse
largeModelResponse
=
new
LargeModelResponse
();
largeModelResponse
.
setThinking
(
new
Thinking
()
{{
setType
(
"disabled"
);
}});
largeModelResponse
.
setModel
(
model
);
largeModelResponse
.
setMessages
(
new
Message
[]{
systemMessage
,
userMessage
});
largeModelResponse
.
setStream
(
false
);
largeModelResponse
.
setUser
(
"GENERATE_E_CHART"
);
LargeModelDemandResult
largeModelDemandResult
=
llmService
.
chat
(
largeModelResponse
);
return
largeModelDemandResult
.
getMessage
();
}
}
src/main/java/cn/com/poc/thirdparty/service/impl/ChainServiceImpl.java
View file @
ec23cc35
...
@@ -9,6 +9,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult;
...
@@ -9,6 +9,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult;
import
cn.com.poc.thirdparty.service.ChainService
;
import
cn.com.poc.thirdparty.service.ChainService
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
...
@@ -22,6 +23,10 @@ public class ChainServiceImpl implements ChainService {
...
@@ -22,6 +23,10 @@ public class ChainServiceImpl implements ChainService {
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ChainServiceImpl
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ChainServiceImpl
.
class
);
@Value
(
value
=
"${large-model.apikey}"
)
private
String
API_KEY
;
@Resource
@Resource
private
AIDialogueService
aiDialogueService
;
private
AIDialogueService
aiDialogueService
;
...
@@ -43,6 +48,7 @@ public class ChainServiceImpl implements ChainService {
...
@@ -43,6 +48,7 @@ public class ChainServiceImpl implements ChainService {
@Override
@Override
public
CSVChainResult
csvChain
(
CSVChainResponse
response
)
{
public
CSVChainResult
csvChain
(
CSVChainResponse
response
)
{
logger
.
info
(
"csvChain response : {}"
,
response
);
logger
.
info
(
"csvChain response : {}"
,
response
);
response
.
setApiKey
(
API_KEY
);
CSVChainResult
csvChainResult
=
aiDialogueService
.
csvChain
(
response
);
CSVChainResult
csvChainResult
=
aiDialogueService
.
csvChain
(
response
);
if
(
csvChainResult
==
null
||
csvChainResult
.
getStatus
().
equals
(
"error"
))
{
if
(
csvChainResult
==
null
||
csvChainResult
.
getStatus
().
equals
(
"error"
))
{
logger
.
error
(
"csvChain result error : {} , response:{}"
,
csvChainResult
,
response
);
logger
.
error
(
"csvChain result error : {} , response:{}"
,
csvChainResult
,
response
);
...
...
src/test/java/cn/com/poc/ai_bi/AIBiTest.java
0 → 100644
View file @
ec23cc35
package
cn
.
com
.
poc
.
ai_bi
;
import
cn.com.poc.common.utils.DocumentLoad
;
import
cn.com.poc.common.utils.JsonUtils
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
cn.com.yict.framemax.core.spring.SingleContextInitializer
;
import
org.apache.commons.csv.CSVFormat
;
import
org.apache.commons.csv.CSVParser
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.Reader
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @author 52747
* @date 2025/8/21
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
initializers
=
SingleContextInitializer
.
class
)
@WebAppConfiguration
public
class
AIBiTest
{
@Test
public
void
test_readCSVHeader
()
{
String
fileUrl
=
"https://gsst-poe-sit.gz.bcebos.com/v1/weather_district_id.csv"
;
File
file
=
DocumentLoad
.
downloadURLDocument
(
fileUrl
);
try
(
Reader
reader
=
new
FileReader
(
file
))
{
CSVParser
csvParser
=
new
CSVParser
(
reader
,
CSVFormat
.
DEFAULT
.
withFirstRecordAsHeader
()
.
withIgnoreHeaderCase
()
.
withTrim
());
Map
<
String
,
Integer
>
headerMap
=
csvParser
.
getHeaderMap
();
Set
<
String
>
headerSet
=
headerMap
.
keySet
();
System
.
out
.
println
(
JsonUtils
.
serialize
(
headerSet
));
}
catch
(
Exception
e
)
{
throw
new
BusinessException
(
"获取文件失败"
);
}
}
}
src/test/java/cn/com/poc/thirdparty/resource/demand/ai/service/ChainServiceTest.java
View file @
ec23cc35
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
service
;
package
cn
.
com
.
poc
.
thirdparty
.
resource
.
demand
.
ai
.
service
;
import
cn.com.poc.common.utils.JsonUtils
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.csvchain.CSVChainResponse
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.csvchain.CSVChainResult
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResponse
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResponse
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult
;
import
cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult
;
import
cn.com.poc.thirdparty.service.ChainService
;
import
cn.com.poc.thirdparty.service.ChainService
;
...
@@ -27,7 +30,7 @@ public class ChainServiceTest {
...
@@ -27,7 +30,7 @@ public class ChainServiceTest {
@Test
@Test
public
void
test_dbChain
(){
public
void
test_dbChain
()
{
DBChainResponse
response
=
new
DBChainResponse
();
DBChainResponse
response
=
new
DBChainResponse
();
response
.
setQuestion
(
"查询百度插件详情"
);
response
.
setQuestion
(
"查询百度插件详情"
);
...
@@ -43,4 +46,17 @@ public class ChainServiceTest {
...
@@ -43,4 +46,17 @@ public class ChainServiceTest {
}
}
@Test
public
void
test_csvChain
()
{
CSVChainResponse
csvChainResponse
=
new
CSVChainResponse
();
csvChainResponse
.
setQuestion
(
"张家市口的所有地区经纬度"
);
csvChainResponse
.
setContext
(
""
);
csvChainResponse
.
setFilePath
(
"https://gsst-poe-sit.gz.bcebos.com/v1/weather_district_id.csv"
);
csvChainResponse
.
setApiKey
(
"sk-bNzgFwFtw3k4jR7CE3575a19C3304a53Bb803cCeDeC154F2"
);
CSVChainResult
csvChainResult
=
chainService
.
csvChain
(
csvChainResponse
);
System
.
out
.
println
(
JsonUtils
.
serialize
(
csvChainResult
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment