Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
robot-trans-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
robot-trans-platform
Commits
f09e9537
Commit
f09e9537
authored
Mar 13, 2025
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改配置文件
parent
1ace8571
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/factory/FlowChatSubscriber.java
...a/com/mortals/xhx/webflux/factory/FlowChatSubscriber.java
+6
-0
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/service/impl/BaseChatService.java
...com/mortals/xhx/webflux/service/impl/BaseChatService.java
+10
-0
No files found.
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/factory/FlowChatSubscriber.java
View file @
f09e9537
package
com.mortals.xhx.webflux.factory
;
package
com.mortals.xhx.webflux.factory
;
import
cn.hutool.core.util.StrUtil
;
import
com.mortals.xhx.webflux.common.JsonUtils
;
import
com.mortals.xhx.webflux.common.JsonUtils
;
import
com.mortals.xhx.webflux.service.FlowChatCallBack
;
import
com.mortals.xhx.webflux.service.FlowChatCallBack
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.reactivestreams.Subscriber
;
import
org.reactivestreams.Subscriber
;
import
org.reactivestreams.Subscription
;
import
org.reactivestreams.Subscription
;
import
org.springframework.util.ObjectUtils
;
import
reactor.core.Disposable
;
import
reactor.core.Disposable
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.FluxSink
;
import
reactor.core.publisher.FluxSink
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
...
@@ -55,6 +58,9 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable {
...
@@ -55,6 +58,9 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable {
public
void
onNext
(
String
data
)
{
public
void
onNext
(
String
data
)
{
try
{
try
{
data
=
callBack
.
onNext
(
data
,
context
);
data
=
callBack
.
onNext
(
data
,
context
);
if
(
ObjectUtils
.
isEmpty
(
data
)){
this
.
stopFlag
=
true
;
}
log
.
info
(
" onNext data:{}"
,
data
);
log
.
info
(
" onNext data:{}"
,
data
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"流式问答异常:{}"
,
e
.
getMessage
());
log
.
error
(
"流式问答异常:{}"
,
e
.
getMessage
());
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/service/impl/BaseChatService.java
View file @
f09e9537
package
com.mortals.xhx.webflux.service.impl
;
package
com.mortals.xhx.webflux.service.impl
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.JsonNode
;
...
@@ -49,6 +50,11 @@ public class BaseChatService extends AbstractFlowChatTemplate {
...
@@ -49,6 +50,11 @@ public class BaseChatService extends AbstractFlowChatTemplate {
@Override
@Override
public
String
onNext
(
String
data
,
FlowChatContext
context
)
{
public
String
onNext
(
String
data
,
FlowChatContext
context
)
{
if
(
StrUtil
.
equals
(
"[DONE]"
,
data
))
{
//[DONE]是消息结束标识
return
null
;
}
// 解析响应数据项
// 解析响应数据项
JSONObject
bodyJson
=
JSONObject
.
parseObject
(
data
);
JSONObject
bodyJson
=
JSONObject
.
parseObject
(
data
);
if
(
bodyJson
==
null
)
{
if
(
bodyJson
==
null
)
{
...
@@ -70,6 +76,8 @@ public class BaseChatService extends AbstractFlowChatTemplate {
...
@@ -70,6 +76,8 @@ public class BaseChatService extends AbstractFlowChatTemplate {
obj
.
put
(
"delta"
,
delta
);
obj
.
put
(
"delta"
,
delta
);
jsonArray
.
add
(
obj
);
jsonArray
.
add
(
obj
);
rspJson
.
put
(
"delta"
,
jsonArray
);
rspJson
.
put
(
"delta"
,
jsonArray
);
rspJson
.
put
(
"index"
,
0
);
rspJson
.
put
(
"finish_reason"
,
null
);
num
++;
num
++;
context
.
getEmitter
().
next
(
rspJson
.
toJSONString
());
context
.
getEmitter
().
next
(
rspJson
.
toJSONString
());
...
@@ -113,6 +121,8 @@ public class BaseChatService extends AbstractFlowChatTemplate {
...
@@ -113,6 +121,8 @@ public class BaseChatService extends AbstractFlowChatTemplate {
if
(
"stop"
.
equals
(
finish_reason
))
{
if
(
"stop"
.
equals
(
finish_reason
))
{
delta
.
put
(
"content"
,
""
);
delta
.
put
(
"content"
,
""
);
this
.
num
=
0
;
this
.
num
=
0
;
}
else
{
delta
.
put
(
"finish_reason"
,
null
);
}
}
}
}
...
...
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