Commit f09e9537 authored by 赵啸非's avatar 赵啸非

修改配置文件

parent 1ace8571
package com.mortals.xhx.webflux.factory;
import cn.hutool.core.util.StrUtil;
import com.mortals.xhx.webflux.common.JsonUtils;
import com.mortals.xhx.webflux.service.FlowChatCallBack;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.springframework.util.ObjectUtils;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink;
import java.util.concurrent.ConcurrentHashMap;
......@@ -55,6 +58,9 @@ public class FlowChatSubscriber implements Subscriber<String>, Disposable {
public void onNext(String data) {
try {
data = callBack.onNext(data, context);
if(ObjectUtils.isEmpty(data)){
this.stopFlag=true;
}
log.info(" onNext data:{}", data);
} catch (Exception e) {
log.error("流式问答异常:{}", e.getMessage());
......
package com.mortals.xhx.webflux.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
......@@ -49,6 +50,11 @@ public class BaseChatService extends AbstractFlowChatTemplate {
@Override
public String onNext(String data, FlowChatContext context) {
if (StrUtil.equals("[DONE]", data)) {//[DONE]是消息结束标识
return null;
}
// 解析响应数据项
JSONObject bodyJson = JSONObject.parseObject(data);
if (bodyJson == null) {
......@@ -70,6 +76,8 @@ public class BaseChatService extends AbstractFlowChatTemplate {
obj.put("delta", delta);
jsonArray.add(obj);
rspJson.put("delta", jsonArray);
rspJson.put("index", 0);
rspJson.put("finish_reason", null);
num++;
context.getEmitter().next(rspJson.toJSONString());
......@@ -113,6 +121,8 @@ public class BaseChatService extends AbstractFlowChatTemplate {
if ("stop".equals(finish_reason)) {
delta.put("content", "");
this.num = 0;
}else{
delta.put("finish_reason", null);
}
}
......
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