Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 支持百度千帆SDK #5095

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ ANTHROPIC_API_VERSION=
ANTHROPIC_URL=

### (optional)
WHITE_WEBDEV_ENDPOINTS=
WHITE_WEBDEV_ENDPOINTS=

## Baidu Qianfan Access Key & Secret Key
QIANFAN_AK=
QIANFAN_SK=
23 changes: 18 additions & 5 deletions app/client/platforms/baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@/app/constant";
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
import { getAccessToken } from "@/app/utils/baidu";
import { ChatCompletion } from "@baiducloud/qianfan";

import {
ChatOptions,
Expand Down Expand Up @@ -247,12 +248,24 @@ export class ErnieApi implements LLMApi {
openWhenHidden: true,
});
} else {
const res = await fetch(chatPath, chatPayload);
clearTimeout(requestTimeoutId);
// SDK替换
const accessStore = useAccessStore.getState();
const client = new ChatCompletion({
QIANFAN_AK: accessStore.baiduApiKey,
QIANFAN_SK: accessStore.baiduSecretKey,
QIANFAN_BASE_URL: `${window.location.origin}${
accessStore.baiduUrl || "/api/baidu"
}`,
});

const resp = await client.chat(
{
...requestPayload,
},
modelConfig.model.toUpperCase(),
);

const resJson = await res.json();
const message = resJson?.result;
options.onFinish(message);
options.onFinish(resp?.result);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"sass": "^1.59.2",
"spark-md5": "^3.0.2",
"use-debounce": "^9.0.4",
"zustand": "^4.3.8"
"zustand": "^4.3.8",
"@baiducloud/qianfan": "0.1.5"
},
"devDependencies": {
"@tauri-apps/cli": "1.5.11",
Expand Down
Loading
Loading