Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elleai
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
ai-tech
E
ellehuis-group
backend
elleai
Commits
977ef3d8
Commit
977ef3d8
authored
Mar 27, 2025
by
陈立彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ai问答接入deepseek
parent
c8dc39c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
22 deletions
+51
-22
AppChatCompletionService.java
.../elleai/application/service/AppChatCompletionService.java
+51
-22
No files found.
src/main/java/cn/breeze/elleai/application/service/AppChatCompletionService.java
View file @
977ef3d8
...
...
@@ -538,20 +538,20 @@ public class AppChatCompletionService {
// 获取随机问题
final
List
<
HotQaMobileDto
>
hots
=
Lists
.
newArrayList
();
PageResult
<
HotQaMobileDto
>
pageResult
=
this
.
hotQaList
(
new
QaAssistantRequestDto
());
if
(
Objects
.
nonNull
(
pageResult
)
&&
CollectionUtil
.
isNotEmpty
(
pageResult
.
getItems
()))
{
List
<
HotQaMobileDto
>
items
=
pageResult
.
getItems
();
if
(
items
.
size
()
>
2
){
Collections
.
shuffle
(
items
);
items
=
items
.
subList
(
0
,
2
);
}
hots
.
addAll
(
items
);
}
//
PageResult<HotQaMobileDto> pageResult = this.hotQaList(new QaAssistantRequestDto());
//
if(Objects.nonNull(pageResult) && CollectionUtil.isNotEmpty(pageResult.getItems())) {
//
List<HotQaMobileDto> items = pageResult.getItems();
//
if(items.size() > 2){
//
Collections.shuffle(items);
//
items = items.subList(0, 2);
//
}
//
hots.addAll(items);
//
}
List
<
HotQaResponseModel
>
hotQaList
=
chatCompletionService
.
hotQaList
(
new
HotQaRequestModel
());
if
(
CollectionUtil
.
isNotEmpty
(
hotQaList
))
{
Collections
.
shuffle
(
hotQaList
);
if
(
hotQaList
.
size
()
>
2
)
{
hotQaList
=
hotQaList
.
subList
(
0
,
2
);
if
(
hotQaList
.
size
()
>
5
)
{
hotQaList
=
hotQaList
.
subList
(
0
,
5
);
}
hotQaList
.
forEach
(
v
->
{
HotQaMobileDto
dto
=
new
HotQaMobileDto
();
...
...
@@ -566,35 +566,64 @@ public class AppChatCompletionService {
reqBody
.
put
(
"visitor_biz_id"
,
userPrincipal
.
getUserId
());
reqBody
.
put
(
"session_id"
,
sessionId
);
final
StringBuffer
buffer
=
new
StringBuffer
();
// JSONObject customVariables = new JSONObject();
// customVariables.put("Position", userPrincipal.getPosition());
// customVariables.put("Department", userPrincipal.getShopName());
// customVariables.put("UserId", userPrincipal.getUserId());
// reqBody.put("custom_variables", customVariables.toJSONString());
final
String
[]
thoughtContent
=
{
""
};
final
String
[]
replyContent
=
{
""
};
final
String
[]
difySessionId
=
{
""
};
final
Boolean
[]
replyFlag
=
{
false
};
String
finalSessionId
=
sessionId
;
return
webClient
.
post
().
uri
(
dsApiBase
).
accept
(
MediaType
.
TEXT_EVENT_STREAM
).
bodyValue
(
reqBody
.
toJSONString
()).
exchangeToFlux
(
r
->
r
.
bodyToFlux
(
String
.
class
))
.
mapNotNull
(
v
->
{
JSONObject
json
=
JSONObject
.
parseObject
(
v
);
String
type
=
json
.
getString
(
"type"
);
if
(
Objects
.
equals
(
type
,
"error"
))
{
thoughtContent
[
0
]
=
json
.
getJSONObject
(
"error"
).
getString
(
"message"
);
}
JSONObject
payload
=
json
.
getJSONObject
(
"payload"
);
if
(
Objects
.
nonNull
(
payload
))
{
if
(
Objects
.
equals
(
type
,
"thought"
))
{
JSONArray
procedures
=
payload
.
getJSONArray
(
"procedures"
);
if
(
CollectionUtil
.
isNotEmpty
(
procedures
)
&&
procedures
.
size
()
>
1
)
{
String
answer
=
procedures
.
getJSONObject
(
1
).
getJSONObject
(
"debugging"
).
getString
(
"display_content"
);
if
(
StringUtils
.
isNotEmpty
(
answer
))
{
replyContent
[
0
]
=
answer
;
if
(
CollectionUtil
.
isNotEmpty
(
procedures
))
{
String
content
=
procedures
.
getJSONObject
(
0
).
getJSONObject
(
"debugging"
).
getString
(
"content"
);
if
(
StrUtil
.
isNotEmpty
(
content
))
{
thoughtContent
[
0
]
=
"## 大模型正在思考中 ##\n"
;
thoughtContent
[
0
]
+=
content
;
}
}
if
(
ObjectUtil
.
isEmpty
(
difySessionId
[
0
])
&&
ObjectUtil
.
isNotEmpty
(
payload
.
getString
(
"session_id"
)))
{
difySessionId
[
0
]
=
payload
.
getString
(
"session_id"
);
}
if
(
Objects
.
equals
(
type
,
"reply"
)
&&
Objects
.
equals
(
payload
.
getBoolean
(
"is_from_self"
),
false
))
{
if
(
Objects
.
nonNull
(
payload
))
{
String
content
=
payload
.
getString
(
"content"
);
if
(
StrUtil
.
isNotEmpty
(
content
))
{
replyContent
[
0
]
=
"\n\n## 以下是大模型回复 ##\n"
;
replyContent
[
0
]
+=
content
;
replyFlag
[
0
]
=
true
;
}
if
(
ObjectUtil
.
isEmpty
(
difySessionId
[
0
])
&&
ObjectUtil
.
isNotEmpty
(
payload
.
getString
(
"session_id"
)))
{
difySessionId
[
0
]
=
payload
.
getString
(
"session_id"
);
}
}
}
String
finalContent
=
thoughtContent
[
0
];
if
(
replyFlag
[
0
])
{
finalContent
+=
replyContent
[
0
];
}
UserAskResultMobileDto
result
=
new
UserAskResultMobileDto
();
result
.
setReplyContent
(
replyContent
[
0
]
);
result
.
setReplyContent
(
finalContent
);
result
.
setChatCompletionId
(
chatCompletionId
);
result
.
setMessageId
(
userQaRecordId
);
result
.
setHots
(
hots
);
return
result
;
}).
doOnComplete
(
()
->
{
String
finalContent
=
thoughtContent
[
0
]
+
replyContent
[
0
];
// 更新DIFY会话ID
if
(
StrUtil
.
isEmpty
(
finalSessionId
))
{
UserChatCompletionSaveModel
updateModel
=
new
UserChatCompletionSaveModel
();
...
...
@@ -603,7 +632,7 @@ public class AppChatCompletionService {
chatCompletionService
.
saveUserQaSession
(
updateModel
);
}
// 保存AI问答详情
chatCompletionService
.
saveUserQaRecord
(
chatCompletionId
,
1
,
userQaRecordId
,
replyContent
[
0
]
,
request
.
getAssistantId
());
chatCompletionService
.
saveUserQaRecord
(
chatCompletionId
,
1
,
userQaRecordId
,
finalContent
,
request
.
getAssistantId
());
}
).
map
(
v
->
ServerSentEvent
.
builder
(
v
).
build
());
}
...
...
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