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

Function demonstrateSmartFunctionCall

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

* 示例3: 智能选择最佳格式

(qwenLLM: QwenLLM, availableTools: any[])

Source from the content-addressed store, hash-verified

107 * 示例3: 智能选择最佳格式
108 */
109async function demonstrateSmartFunctionCall(qwenLLM: QwenLLM, availableTools: any[]) {
110 console.log('=== 示例3: 智能格式选择 ===');
111
112 try {
113 const selectedTools = availableTools.slice(0, 5);
114
115 console.log('使用智能格式选择,支持的工具:', selectedTools.map(t => t.name).join(', '));
116
117 const messages = [
118 {
119 role: 'user',
120 content: '帮我查看当前目录下的文件列表',
121 },
122 ];
123
124 // 智能选择最佳格式
125 const response = await qwenLLM.smartFunctionCall(messages, selectedTools);
126 const result = qwenLLM.parseToolCallResult(response);
127
128 console.log('LLM 回复:', result.content);
129 if (result.hasToolCalls) {
130 console.log('选择的工具:', result.toolCalls.map(t => t.function.name).join(', '));
131
132 // 显示工具调用参数
133 for (const toolCall of result.toolCalls) {
134 console.log(`${toolCall.function.name} 参数:`, toolCall.function.arguments);
135 }
136 }
137 console.log('');
138 } catch (error) {
139 console.error('智能格式选择失败:', error);
140 console.log('');
141 }
142}
143
144/**
145 * 示例4: 完整的工具调用工作流

Callers 1

mainFunction · 0.85

Calls 4

smartFunctionCallMethod · 0.80
logMethod · 0.45
parseToolCallResultMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected