Skip to content

Commit 5883b49

Browse files
committed
merge
2 parents 54bfdcf + f461d9d commit 5883b49

6 files changed

Lines changed: 18 additions & 22 deletions

File tree

chat2db-client/src/typings/ai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export enum AIType {
22
CHAT2DBAI = 'CHAT2DBAI',
33
ZHIPUAI = 'ZHIPUAI',
44
BAICHUANAI='BAICHUANAI',
5-
// WENXINAI='WENXINAI',
5+
WENXINAI='WENXINAI',
66
// TONGYIQIANWENAI='TONGYIQIANWENAI',
77
OPENAI = 'OPENAI',
88
AZUREAI = 'AZUREAI',

chat2db-server/chat2db-server-start/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ chatgpt:
7373
# 可以选择GPT3或GPT35
7474
version: GPT35
7575
context:
76-
length: 4
76+
length: 1
7777

7878
# Print the HTTP log
7979
logbook:

chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ private List<FastChatMessage> getFastChatMessage(String uid, String prompt) {
480480
private SseEmitter chatWithWenxinAi(ChatQueryRequest queryRequest, SseEmitter sseEmitter, String uid) throws IOException {
481481
String prompt = buildPrompt(queryRequest);
482482
List<FastChatMessage> messages = getFastChatMessage(uid, prompt);
483+
if (messages.size() >= 2 && messages.size() % 2 == 0) {
484+
messages.remove(messages.size() - 1);
485+
}
483486

484487
buildSseEmitter(sseEmitter, uid);
485488

chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/client/WenxinAIClient.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,21 @@ private static WenxinAIStreamClient singleton() {
5858
}
5959

6060
public static void refresh() {
61-
String apiHost = "";
61+
String apiHost = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro";
6262
String accessToken = "";
63-
String model = "";
6463
ConfigService configService = ApplicationContextUtil.getBean(ConfigService.class);
6564
Config apiHostConfig = configService.find(WENXIN_HOST).getData();
6665
if (apiHostConfig != null && StringUtils.isNotBlank(apiHostConfig.getContent())) {
6766
apiHost = apiHostConfig.getContent();
67+
if (apiHost.endsWith("/")) {
68+
apiHost = apiHost.substring(0, apiHost.length() - 1);
69+
}
6870
}
6971
Config config = configService.find(WENXIN_ACCESS_TOKEN).getData();
7072
if (config != null && StringUtils.isNotBlank(config.getContent())) {
7173
accessToken = config.getContent();
7274
}
73-
Config deployConfig = configService.find(WENXIN_MODEL).getData();
74-
if (deployConfig != null && StringUtils.isNotBlank(deployConfig.getContent())) {
75-
model = deployConfig.getContent();
76-
}
77-
WENXIN_AI_CLIENT = WenxinAIStreamClient.builder().accessToken(accessToken).apiHost(apiHost).model(model)
78-
.build();
75+
WENXIN_AI_CLIENT = WenxinAIStreamClient.builder().accessToken(accessToken).apiHost(apiHost).build();
7976
}
8077

8178
}

chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/client/WenxinAIStreamClient.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import com.fasterxml.jackson.databind.ObjectMapper;
99
import lombok.Getter;
1010
import lombok.extern.slf4j.Slf4j;
11-
import okhttp3.MediaType;
12-
import okhttp3.OkHttpClient;
13-
import okhttp3.Request;
14-
import okhttp3.RequestBody;
11+
import okhttp3.*;
1512
import okhttp3.sse.EventSource;
1613
import okhttp3.sse.EventSourceListener;
1714
import okhttp3.sse.EventSources;
@@ -179,7 +176,6 @@ public void streamCompletions(List<FastChatMessage> chatMessages, EventSourceLis
179176

180177
FastChatCompletionsOptions chatCompletionsOptions = new FastChatCompletionsOptions(chatMessages);
181178
chatCompletionsOptions.setStream(true);
182-
chatCompletionsOptions.setModel(this.model);
183179

184180
EventSource.Factory factory = EventSources.createFactory(this.okHttpClient);
185181
ObjectMapper mapper = new ObjectMapper();
@@ -192,7 +188,7 @@ public void streamCompletions(List<FastChatMessage> chatMessages, EventSourceLis
192188
EventSource eventSource = factory.newEventSource(request, eventSourceListener);
193189
log.info("finish invoking fast chat ai");
194190
} catch (Exception e) {
195-
log.error("fast chat ai error", e);
191+
log.error("wenxin chat ai error", e);
196192
eventSourceListener.onFailure(null, e, null);
197193
throw new ParamBusinessException();
198194
}

chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/listener/WenxinAIEventSourceListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public WenxinAIEventSourceListener(SseEmitter sseEmitter) {
3838
*/
3939
@Override
4040
public void onOpen(EventSource eventSource, Response response) {
41-
log.info("Fast Chat Sse connecting...");
41+
log.info("Wenxin chat Sse connecting...");
4242
}
4343

4444
/**
@@ -81,7 +81,7 @@ public void onClosed(EventSource eventSource) {
8181
throw new RuntimeException(e);
8282
}
8383
sseEmitter.complete();
84-
log.info("FastChatAI close sse connection...");
84+
log.info("WenxinChatAI close sse connection...");
8585
}
8686

8787
@Override
@@ -107,13 +107,13 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) {
107107
if (StringUtils.isBlank(bodyString) && Objects.nonNull(t)) {
108108
bodyString = t.getMessage();
109109
}
110-
log.error("Fast Chat AI sse response:{}", bodyString);
110+
log.error("Wenxin chat AI sse response:{}", bodyString);
111111
} else {
112-
log.error("Fast Chat AI sse response:{},error:{}", response, t);
112+
log.error("Wenxin chat AI sse response:{},error:{}", response, t);
113113
}
114114
eventSource.cancel();
115115
Message message = new Message();
116-
message.setContent("Fast Chat AI error:" + bodyString);
116+
message.setContent("Wenxin chat AI error:" + bodyString);
117117
sseEmitter.send(SseEmitter.event()
118118
.id("[ERROR]")
119119
.data(message));
@@ -122,7 +122,7 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) {
122122
.data("[DONE]"));
123123
sseEmitter.complete();
124124
} catch (Exception exception) {
125-
log.error("Fast Chat AI send data error:", exception);
125+
log.error("Wenxin chat AI send data error:", exception);
126126
}
127127
}
128128
}

0 commit comments

Comments
 (0)