baichuan update

This commit is contained in:
robin
2023-11-01 19:23:27 +08:00
parent f360a5b58d
commit 218222a6ac
3 changed files with 46 additions and 6 deletions

View File

@ -63,8 +63,8 @@ public class BaichuanAIClient {
public static void refresh() {
String apiKey = "";
String apiHost = "";
String model = "";
String apiHost = "https://api.baichuan-ai.com/v1/chat/";
String model = "Baichuan2-53B";
String secretKey = "";
ConfigService configService = ApplicationContextUtil.getBean(ConfigService.class);
Config apiHostConfig = configService.find(BAICHUAN_HOST).getData();
@ -83,8 +83,8 @@ public class BaichuanAIClient {
if (deployConfig != null && StringUtils.isNotBlank(deployConfig.getContent())) {
model = deployConfig.getContent();
}
BAICHUAN_AI_CLIENT = BaichuanAIStreamClient.builder().apiKey(apiKey).apiHost(apiHost).model(model)
.build();
BAICHUAN_AI_CLIENT = BaichuanAIStreamClient.builder().apiKey(apiKey).secretKey(secretKey)
.apiHost(apiHost).model(model).build();
}
}

View File

@ -2,6 +2,7 @@ package ai.chat2db.server.web.api.controller.ai.baichuan.client;
import ai.chat2db.server.tools.common.exception.ParamBusinessException;
import ai.chat2db.server.web.api.controller.ai.baichuan.interceptor.BaichuanHeaderAuthorizationInterceptor;
import ai.chat2db.server.web.api.controller.ai.baichuan.model.BaichuanChatCompletionsOptions;
import ai.chat2db.server.web.api.controller.ai.fastchat.interceptor.FastChatHeaderAuthorizationInterceptor;
import ai.chat2db.server.web.api.controller.ai.fastchat.model.FastChatCompletionsOptions;
import ai.chat2db.server.web.api.controller.ai.fastchat.model.FastChatMessage;
@ -190,9 +191,9 @@ public class BaichuanAIStreamClient {
log.info("Baichuan AI, prompt:{}", chatMessages.get(chatMessages.size() - 1).getContent());
try {
FastChatCompletionsOptions chatCompletionsOptions = new FastChatCompletionsOptions(chatMessages);
chatCompletionsOptions.setStream(true);
BaichuanChatCompletionsOptions chatCompletionsOptions = new BaichuanChatCompletionsOptions();
chatCompletionsOptions.setModel(this.model);
chatCompletionsOptions.setMessages(chatMessages);
EventSource.Factory factory = EventSources.createFactory(this.okHttpClient);
ObjectMapper mapper = new ObjectMapper();

View File

@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.
package ai.chat2db.server.web.api.controller.ai.baichuan.model;
import ai.chat2db.server.web.api.controller.ai.fastchat.model.FastChatMessage;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* The configuration information for a chat completions request. Completions support a wide variety of tasks and
* generate text that continues from or "completes" provided prompt data.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public final class BaichuanChatCompletionsOptions {
/*
* The collection of context messages associated with this chat completions request.
* Typical usage begins with a chat message for the System role that provides instructions for
* the behavior of the assistant, followed by alternating messages between the User and
* Assistant roles.
*/
private List<FastChatMessage> messages;
//
/*
* The model name to provide as part of this completions request.
* Not applicable to Fast Chat AI, where deployment information should be included in the Fast Chat
* resource URI that's connected to.
*/
private String model;
}