Skip to content

Commit

Permalink
feat:兼容base_api_route (#777)
Browse files Browse the repository at this point in the history
* feat:兼容base_api_route

* feat:修改console_md文档
  • Loading branch information
mondaylab authored Sep 3, 2024
1 parent 5b7413c commit 3a8d7e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/javascript/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ yarn add @baiducloud/qianfan
import {consoleAction, setEnvVariable} from "@baiducloud/qianfan";

async function consoleApi() {
const res = await consoleAction({base_api_route: 'v2/finetuning', action: 'CreateFineTuningJob', data: {"name":"test_name",
const res = await consoleAction({base_api_route: '/v2/finetuning', action: 'CreateFineTuningJob', data: {"name":"test_name",
"description":"test_description",
"model":"ERNIE-Lite-8K-0922",
"trainMode":"SFT"}});
"trainMode":"SFT"}});

// 注意:name自定义,不可重名
console.log(res);
}
Expand Down
6 changes: 5 additions & 1 deletion javascript/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,13 @@ export async function consoleAction({base_api_route, data, action}: ConsoleActio
config.QIANFAN_CONSOLE_API_BASE_URL
);
const client = new HttpClient(httpClientConfig);

const normalizedRoute = base_api_route.startsWith('/') ? base_api_route.slice(1) : base_api_route;
const apiRoute = `${config.QIANFAN_CONSOLE_API_BASE_URL}/${normalizedRoute}`;

const baseParams = {
httpMethod: 'POST',
path: `${config.QIANFAN_CONSOLE_API_BASE_URL}/${base_api_route}`,
path: apiRoute,
body: data && JSON.stringify(data),
headers: {
...DEFAULT_HEADERS
Expand Down

0 comments on commit 3a8d7e1

Please sign in to comment.