Skip to content

Commit 4e3f166

Browse files
feat: 阿里巴巴千问模型支持 Function calling
1 parent fe484fd commit 4e3f166

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

app/client/platforms/alibaba.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
useChatStore,
1212
ChatMessageTool,
1313
usePluginStore,
14+
FunctionToolItem,
1415
} from "@/app/store";
1516
import {
1617
preProcessImageContentForAlibabaDashScope,
@@ -56,6 +57,7 @@ interface RequestParam {
5657
repetition_penalty?: number;
5758
top_p: number;
5859
max_tokens?: number;
60+
tools?: FunctionToolItem[];
5961
}
6062
interface RequestPayload {
6163
model: string;
@@ -229,11 +231,16 @@ export class QwenApi implements LLMApi {
229231
.getAsTools(
230232
useChatStore.getState().currentSession().mask?.plugin || [],
231233
);
234+
// console.log("getAsTools", tools, funcs);
235+
const _tools = tools as unknown as FunctionToolItem[];
236+
if (_tools && _tools.length > 0) {
237+
requestPayload.parameters.tools = _tools;
238+
}
232239
return streamWithThink(
233240
chatPath,
234241
requestPayload,
235242
headers,
236-
tools as any,
243+
[],
237244
funcs,
238245
controller,
239246
// parseSSE
@@ -266,7 +273,7 @@ export class QwenApi implements LLMApi {
266273
});
267274
} else {
268275
// @ts-ignore
269-
runTools[index]["function"]["arguments"] += args;
276+
runTools[index]["function"]["arguments"] += args || "";
270277
}
271278
}
272279

app/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ export function showPlugins(provider: ServiceProvider, model: string) {
347347
if (provider == ServiceProvider.Google && !model.includes("vision")) {
348348
return true;
349349
}
350+
if (
351+
provider == ServiceProvider.Alibaba &&
352+
(model.includes("qwen") || model.includes("deepseek"))
353+
) {
354+
return true;
355+
}
350356
return false;
351357
}
352358

0 commit comments

Comments
 (0)