MCPcopy Create free account
hub / github.com/echoVic/blade-code / demonstrateFunctionsFormat

Function demonstrateFunctionsFormat

examples/qwen-function-call-example.ts:76–104  ·  view source on GitHub ↗

* 示例2: 使用传统 Functions 格式

(qwenLLM: QwenLLM, availableTools: any[])

Source from the content-addressed store, hash-verified

74 * 示例2: 使用传统 Functions 格式
75 */
76async function demonstrateFunctionsFormat(qwenLLM: QwenLLM, availableTools: any[]) {
77 console.log('=== 示例2: 传统 Functions 格式 ===');
78
79 try {
80 const selectedTools = availableTools.slice(0, 3);
81 const functions = ToolFormatConverter.toOpenAIFunctions(selectedTools);
82
83 console.log('使用的函数:', functions.map(f => f.name).join(', '));
84
85 const messages = [
86 {
87 role: 'user',
88 content: '帮我生成一个UUID',
89 },
90 ];
91
92 const response = await qwenLLM.functionCall(messages, functions);
93 const result = qwenLLM.parseToolCallResult(response);
94
95 console.log('LLM 回复:', result.content);
96 if (result.hasToolCalls) {
97 console.log('函数调用:', result.toolCalls.map(t => t.function.name).join(', '));
98 }
99 console.log('');
100 } catch (error) {
101 console.error('Functions 格式调用失败:', error);
102 console.log('');
103 }
104}
105
106/**
107 * 示例3: 智能选择最佳格式

Callers 1

mainFunction · 0.85

Calls 5

toOpenAIFunctionsMethod · 0.80
logMethod · 0.45
functionCallMethod · 0.45
parseToolCallResultMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected