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

Function demonstrateToolsFormat

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

* 示例1: 使用现代 OpenAI Tools 格式

(qwenLLM: QwenLLM, availableTools: any[])

Source from the content-addressed store, hash-verified

40 * 示例1: 使用现代 OpenAI Tools 格式
41 */
42async function demonstrateToolsFormat(qwenLLM: QwenLLM, availableTools: any[]) {
43 console.log('=== 示例1: 现代 Tools 格式 ===');
44
45 try {
46 // 选择几个工具进行演示
47 const selectedTools = availableTools.slice(0, 3);
48 const tools = ToolFormatConverter.toOpenAITools(selectedTools);
49
50 console.log('使用的工具:', tools.map(t => t.function.name).join(', '));
51
52 const messages = [
53 {
54 role: 'user',
55 content: '请查看当前时间,并告诉我现在是什么时候',
56 },
57 ];
58
59 const response = await qwenLLM.toolsCall(messages, tools);
60 const result = qwenLLM.parseToolCallResult(response);
61
62 console.log('LLM 回复:', result.content);
63 if (result.hasToolCalls) {
64 console.log('工具调用:', result.toolCalls.map(t => t.function.name).join(', '));
65 }
66 console.log('');
67 } catch (error) {
68 console.error('Tools 格式调用失败:', error);
69 console.log('');
70 }
71}
72
73/**
74 * 示例2: 使用传统 Functions 格式

Callers 1

mainFunction · 0.85

Calls 5

toOpenAIToolsMethod · 0.80
toolsCallMethod · 0.80
logMethod · 0.45
parseToolCallResultMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected