review code
This commit is contained in:
parent
f3e3f08377
commit
f68cd2c5c0
|
@ -2,7 +2,7 @@
|
||||||
import {
|
import {
|
||||||
ApiPath,
|
ApiPath,
|
||||||
Baidu,
|
Baidu,
|
||||||
DEFAULT_API_HOST,
|
BAIDU_BASE_URL,
|
||||||
REQUEST_TIMEOUT_MS,
|
REQUEST_TIMEOUT_MS,
|
||||||
} from "@/app/constant";
|
} from "@/app/constant";
|
||||||
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
|
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
|
||||||
|
@ -21,7 +21,7 @@ import {
|
||||||
} from "@fortaine/fetch-event-source";
|
} from "@fortaine/fetch-event-source";
|
||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
import { getClientConfig } from "@/app/config/client";
|
import { getClientConfig } from "@/app/config/client";
|
||||||
import { getMessageTextContent, isVisionModel } from "@/app/utils";
|
import { getMessageTextContent } from "@/app/utils";
|
||||||
|
|
||||||
export interface OpenAIListModelResponse {
|
export interface OpenAIListModelResponse {
|
||||||
object: string;
|
object: string;
|
||||||
|
@ -58,7 +58,8 @@ export class ErnieApi implements LLMApi {
|
||||||
|
|
||||||
if (baseUrl.length === 0) {
|
if (baseUrl.length === 0) {
|
||||||
const isApp = !!getClientConfig()?.isApp;
|
const isApp = !!getClientConfig()?.isApp;
|
||||||
baseUrl = isApp ? DEFAULT_API_HOST + "/api/proxy/baidu" : ApiPath.Baidu;
|
// do not use proxy for baidubce api
|
||||||
|
baseUrl = isApp ? BAIDU_BASE_URL : ApiPath.Baidu;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baseUrl.endsWith("/")) {
|
if (baseUrl.endsWith("/")) {
|
||||||
|
@ -78,10 +79,9 @@ export class ErnieApi implements LLMApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
async chat(options: ChatOptions) {
|
async chat(options: ChatOptions) {
|
||||||
const visionModel = isVisionModel(options.config.model);
|
|
||||||
const messages = options.messages.map((v) => ({
|
const messages = options.messages.map((v) => ({
|
||||||
role: v.role,
|
role: v.role,
|
||||||
content: visionModel ? v.content : getMessageTextContent(v),
|
content: getMessageTextContent(v),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const modelConfig = {
|
const modelConfig = {
|
||||||
|
|
|
@ -112,9 +112,20 @@ export const Google = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Baidu = {
|
export const Baidu = {
|
||||||
ExampleEndpoint: "https://aip.baidubce.com",
|
ExampleEndpoint: BAIDU_BASE_URL,
|
||||||
ChatPath: (modelName: string) =>
|
ChatPath: (modelName: string) => {
|
||||||
`/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/${modelName}`,
|
let endpoint = modelName;
|
||||||
|
if (modelName === "ernie-4.0-8k") {
|
||||||
|
endpoint = "completions_pro";
|
||||||
|
}
|
||||||
|
if (modelName === "ernie-4.0-8k-preview-0518") {
|
||||||
|
endpoint = "completions_adv_pro";
|
||||||
|
}
|
||||||
|
if (modelName === "ernie-3.5-8k") {
|
||||||
|
endpoint = "completions";
|
||||||
|
}
|
||||||
|
return `/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/${endpoint}`;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
|
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
|
||||||
|
@ -188,11 +199,11 @@ const anthropicModels = [
|
||||||
|
|
||||||
const baiduModels = [
|
const baiduModels = [
|
||||||
"ernie-4.0-turbo-8k",
|
"ernie-4.0-turbo-8k",
|
||||||
"completions_pro=ernie-4.0-8k",
|
"ernie-4.0-8k",
|
||||||
"ernie-4.0-8k-preview",
|
"ernie-4.0-8k-preview",
|
||||||
"completions_adv_pro=ernie-4.0-8k-preview-0518",
|
"ernie-4.0-8k-preview-0518",
|
||||||
"ernie-4.0-8k-latest",
|
"ernie-4.0-8k-latest",
|
||||||
"completions=ernie-3.5-8k",
|
"ernie-3.5-8k",
|
||||||
"ernie-3.5-8k-0205",
|
"ernie-3.5-8k-0205",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,11 @@ export function collectModelTable(
|
||||||
|
|
||||||
// default models
|
// default models
|
||||||
models.forEach((m) => {
|
models.forEach((m) => {
|
||||||
// supoort name=displayName eg:completions_pro=ernie-4.0-8k
|
|
||||||
const [name, displayName] = m.name?.split("=");
|
|
||||||
// using <modelName>@<providerId> as fullName
|
// using <modelName>@<providerId> as fullName
|
||||||
modelTable[`${name}@${m?.provider?.id}`] = {
|
modelTable[`${m.name}@${m?.provider?.id}`] = {
|
||||||
...m,
|
...m,
|
||||||
name,
|
name,
|
||||||
displayName: displayName || name, // 'provider' is copied over if it exists
|
displayName: m.name, // 'provider' is copied over if it exists
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue