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
1ace8571
Commit
1ace8571
authored
Mar 13, 2025
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改配置文件
parent
153680f6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
6 deletions
+30
-6
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/factory/FlowChatContext.java
...java/com/mortals/xhx/webflux/factory/FlowChatContext.java
+3
-0
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/factory/FlowChatSubscriber.java
...a/com/mortals/xhx/webflux/factory/FlowChatSubscriber.java
+4
-3
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/service/impl/BaseChatService.java
...com/mortals/xhx/webflux/service/impl/BaseChatService.java
+22
-3
robot-trans-manager/src/test/java/TestRot.java
robot-trans-manager/src/test/java/TestRot.java
+1
-0
No files found.
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/factory/FlowChatContext.java
View file @
1ace8571
...
...
@@ -5,6 +5,7 @@ import com.mortals.xhx.webflux.req.RobotTransReq;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
reactor.core.publisher.FluxSink
;
/**
* 流式问答上下文
...
...
@@ -36,6 +37,8 @@ public class FlowChatContext {
*/
private
StringBuilder
docs
;
private
FluxSink
<
String
>
emitter
;
public
FlowChatContext
(
RobotTransReq
requestParam
)
{
this
.
requestParam
=
requestParam
;
}
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/factory/FlowChatSubscriber.java
View file @
1ace8571
...
...
@@ -38,6 +38,7 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable {
this
.
context
.
setAnswer
(
new
StringBuilder
());
this
.
context
.
setDocs
(
new
StringBuilder
());
this
.
subscriberMap
=
subscriberMap
;
this
.
context
.
setEmitter
(
emitter
);
log
.
info
(
"subscriberMap in ChatSubscriber before remove: {}"
,
JsonUtils
.
toJson
(
this
.
subscriberMap
));
}
...
...
@@ -65,7 +66,7 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable {
subscription
.
cancel
();
onComplete
();
}
else
{
// 将数据发送给前端
// 将数据发送给前端
如果是起始包 需要要处理一下
emitter
.
next
(
data
);
// 继续请求接收下一个数据项
subscription
.
request
(
1
);
...
...
robot-trans-manager/src/main/java/com/mortals/xhx/webflux/service/impl/BaseChatService.java
View file @
1ace8571
...
...
@@ -38,7 +38,7 @@ public class BaseChatService extends AbstractFlowChatTemplate {
private
String
authValue
;
private
Integer
num
;
private
Integer
num
=
0
;
@Override
...
...
@@ -56,7 +56,25 @@ public class BaseChatService extends AbstractFlowChatTemplate {
}
// String id = bodyJson.getString("id");
String
status
=
bodyJson
.
getString
(
"status"
);
if
(
num
==
0
)
{
JSONObject
rspJson
=
new
JSONObject
();
rspJson
.
put
(
"id"
,
context
.
getMsgId
());
rspJson
.
put
(
"created"
,
new
Date
().
getTime
());
JSONArray
jsonArray
=
new
JSONArray
();
JSONObject
obj
=
new
JSONObject
();
JSONObject
delta
=
new
JSONObject
();
delta
.
put
(
"role"
,
"assistant"
);
delta
.
put
(
"content"
,
""
);
obj
.
put
(
"delta"
,
delta
);
jsonArray
.
add
(
obj
);
rspJson
.
put
(
"delta"
,
jsonArray
);
num
++;
context
.
getEmitter
().
next
(
rspJson
.
toJSONString
());
}
/* String status = bodyJson.getString("status");
if ("running".equals(status)) {
//计数器重置
//this.num=0;
...
...
@@ -75,7 +93,7 @@ public class BaseChatService extends AbstractFlowChatTemplate {
jsonArray.add(obj);
rspJson.put("delta", jsonArray);
return rspJson.toJSONString();
}
}
*/
JSONArray
choices
=
bodyJson
.
getJSONArray
(
"choices"
);
bodyJson
.
put
(
"id"
,
context
.
getMsgId
());
...
...
@@ -94,6 +112,7 @@ public class BaseChatService extends AbstractFlowChatTemplate {
String
finish_reason
=
jsonObject
.
getString
(
"finish_reason"
);
if
(
"stop"
.
equals
(
finish_reason
))
{
delta
.
put
(
"content"
,
""
);
this
.
num
=
0
;
}
}
...
...
robot-trans-manager/src/test/java/TestRot.java
View file @
1ace8571
...
...
@@ -51,6 +51,7 @@ public class TestRot {
Request
request
=
new
Request
.
Builder
()
.
url
(
"http://localhost:18006/chat/base"
)
//.url("http://robot.scsmile.cn/chat/base")
.
headers
(
headers
)
.
post
(
requestBody
)
.
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