Commit 1ace8571 authored by 赵啸非's avatar 赵啸非

修改配置文件

parent 153680f6
...@@ -5,6 +5,7 @@ import com.mortals.xhx.webflux.req.RobotTransReq; ...@@ -5,6 +5,7 @@ import com.mortals.xhx.webflux.req.RobotTransReq;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import reactor.core.publisher.FluxSink;
/** /**
* 流式问答上下文 * 流式问答上下文
...@@ -36,6 +37,8 @@ public class FlowChatContext { ...@@ -36,6 +37,8 @@ public class FlowChatContext {
*/ */
private StringBuilder docs; private StringBuilder docs;
private FluxSink<String> emitter;
public FlowChatContext(RobotTransReq requestParam) { public FlowChatContext(RobotTransReq requestParam) {
this.requestParam = requestParam; this.requestParam = requestParam;
} }
......
...@@ -38,6 +38,7 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable { ...@@ -38,6 +38,7 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable {
this.context.setAnswer(new StringBuilder()); this.context.setAnswer(new StringBuilder());
this.context.setDocs(new StringBuilder()); this.context.setDocs(new StringBuilder());
this.subscriberMap = subscriberMap; this.subscriberMap = subscriberMap;
this.context.setEmitter(emitter);
log.info("subscriberMap in ChatSubscriber before remove: {}", JsonUtils.toJson(this.subscriberMap)); log.info("subscriberMap in ChatSubscriber before remove: {}", JsonUtils.toJson(this.subscriberMap));
} }
...@@ -65,7 +66,7 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable { ...@@ -65,7 +66,7 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable {
subscription.cancel(); subscription.cancel();
onComplete(); onComplete();
} else { } else {
// 将数据发送给前端 // 将数据发送给前端 如果是起始包 需要要处理一下
emitter.next(data); emitter.next(data);
// 继续请求接收下一个数据项 // 继续请求接收下一个数据项
subscription.request(1); subscription.request(1);
......
...@@ -38,7 +38,7 @@ public class BaseChatService extends AbstractFlowChatTemplate { ...@@ -38,7 +38,7 @@ public class BaseChatService extends AbstractFlowChatTemplate {
private String authValue; private String authValue;
private Integer num; private Integer num = 0;
@Override @Override
...@@ -56,7 +56,25 @@ public class BaseChatService extends AbstractFlowChatTemplate { ...@@ -56,7 +56,25 @@ public class BaseChatService extends AbstractFlowChatTemplate {
} }
// String id = bodyJson.getString("id"); // 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)) { if ("running".equals(status)) {
//计数器重置 //计数器重置
//this.num=0; //this.num=0;
...@@ -75,7 +93,7 @@ public class BaseChatService extends AbstractFlowChatTemplate { ...@@ -75,7 +93,7 @@ public class BaseChatService extends AbstractFlowChatTemplate {
jsonArray.add(obj); jsonArray.add(obj);
rspJson.put("delta", jsonArray); rspJson.put("delta", jsonArray);
return rspJson.toJSONString(); return rspJson.toJSONString();
} }*/
JSONArray choices = bodyJson.getJSONArray("choices"); JSONArray choices = bodyJson.getJSONArray("choices");
bodyJson.put("id", context.getMsgId()); bodyJson.put("id", context.getMsgId());
...@@ -94,6 +112,7 @@ public class BaseChatService extends AbstractFlowChatTemplate { ...@@ -94,6 +112,7 @@ public class BaseChatService extends AbstractFlowChatTemplate {
String finish_reason = jsonObject.getString("finish_reason"); String finish_reason = jsonObject.getString("finish_reason");
if ("stop".equals(finish_reason)) { if ("stop".equals(finish_reason)) {
delta.put("content", ""); delta.put("content", "");
this.num = 0;
} }
} }
......
...@@ -51,6 +51,7 @@ public class TestRot { ...@@ -51,6 +51,7 @@ public class TestRot {
Request request = new Request.Builder() Request request = new Request.Builder()
.url("http://localhost:18006/chat/base") .url("http://localhost:18006/chat/base")
//.url("http://robot.scsmile.cn/chat/base")
.headers(headers) .headers(headers)
.post(requestBody) .post(requestBody)
.build(); .build();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment