From 3a8d7e17feb1f1b8086ad9354876e5d72bf0a13c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=B8=80=E5=90=8C=E5=AD=A6Zelina?= <60708406+mondaylab@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:30:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=85=BC=E5=AE=B9base=5Fapi=5Froute=20(#7?= =?UTF-8?q?77)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat:兼容base_api_route * feat:修改console_md文档 --- docs/javascript/console.md | 6 +++--- javascript/src/utils.ts | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/javascript/console.md b/docs/javascript/console.md index 46005aee..9fd61d20 100644 --- a/docs/javascript/console.md +++ b/docs/javascript/console.md @@ -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); } diff --git a/javascript/src/utils.ts b/javascript/src/utils.ts index 01412cee..958ab817 100644 --- a/javascript/src/utils.ts +++ b/javascript/src/utils.ts @@ -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