universal-llm-client 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-model.d.ts +20 -22
- package/dist/ai-model.d.ts.map +1 -1
- package/dist/ai-model.js +26 -23
- package/dist/ai-model.js.map +1 -1
- package/dist/client.d.ts +5 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +17 -9
- package/dist/client.js.map +1 -1
- package/dist/http.d.ts +2 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +1 -0
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +49 -11
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js +14 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/providers/anthropic.d.ts +56 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +524 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/google.d.ts +5 -0
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +64 -8
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/ollama.d.ts.map +1 -1
- package/dist/providers/ollama.js +38 -11
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +9 -7
- package/dist/providers/openai.js.map +1 -1
- package/dist/router.d.ts +13 -33
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +33 -57
- package/dist/router.js.map +1 -1
- package/dist/stream-decoder.d.ts +29 -2
- package/dist/stream-decoder.d.ts.map +1 -1
- package/dist/stream-decoder.js +39 -11
- package/dist/stream-decoder.js.map +1 -1
- package/dist/structured-output.d.ts +107 -181
- package/dist/structured-output.d.ts.map +1 -1
- package/dist/structured-output.js +137 -192
- package/dist/structured-output.js.map +1 -1
- package/dist/zod-adapter.d.ts +44 -0
- package/dist/zod-adapter.d.ts.map +1 -0
- package/dist/zod-adapter.js +61 -0
- package/dist/zod-adapter.js.map +1 -0
- package/package.json +9 -1
- package/src/ai-model.ts +350 -0
- package/src/auditor.ts +213 -0
- package/src/client.ts +402 -0
- package/src/debug/debug-google-streaming.ts +97 -0
- package/src/debug/debug-tool-execution.ts +86 -0
- package/src/debug/test-lmstudio-tools.ts +155 -0
- package/src/demos/README.md +47 -0
- package/src/demos/basic/universal-llm-examples.ts +161 -0
- package/src/demos/mcp/astrid-memory-demo.ts +295 -0
- package/src/demos/mcp/astrid-persona-memory.ts +357 -0
- package/src/demos/mcp/mcp-mongodb-demo.ts +275 -0
- package/src/demos/mcp/simple-astrid-memory.ts +148 -0
- package/src/demos/mcp/simple-mcp-demo.ts +68 -0
- package/src/demos/mcp/working-mcp-demo.ts +62 -0
- package/src/demos/model-alias-demo.ts +0 -0
- package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +267 -0
- package/src/demos/tools/astrid-memory-demo.ts +270 -0
- package/src/demos/tools/astrid-production-memory-clean.ts +785 -0
- package/src/demos/tools/astrid-production-memory.ts +558 -0
- package/src/demos/tools/basic-translation-test.ts +66 -0
- package/src/demos/tools/chromadb-similarity-tuning.ts +390 -0
- package/src/demos/tools/clean-multilingual-conversation.ts +209 -0
- package/src/demos/tools/clean-translation-test.ts +119 -0
- package/src/demos/tools/clean-universal-multilingual-test.ts +131 -0
- package/src/demos/tools/complete-rag-demo.ts +369 -0
- package/src/demos/tools/complete-tool-demo.ts +132 -0
- package/src/demos/tools/demo-tool-calling.ts +124 -0
- package/src/demos/tools/dynamic-language-switching-test.ts +251 -0
- package/src/demos/tools/hybrid-thinking-test.ts +154 -0
- package/src/demos/tools/memory-integration-test.ts +420 -0
- package/src/demos/tools/multilingual-memory-system.ts +802 -0
- package/src/demos/tools/ondemand-translation-demo.ts +655 -0
- package/src/demos/tools/production-tool-demo.ts +245 -0
- package/src/demos/tools/revolutionary-multilingual-test.ts +151 -0
- package/src/demos/tools/rigorous-language-analysis.ts +218 -0
- package/src/demos/tools/test-universal-memory-system.ts +126 -0
- package/src/demos/tools/translation-integration-guide.ts +346 -0
- package/src/demos/tools/universal-memory-system.ts +560 -0
- package/src/http.ts +247 -0
- package/src/index.ts +161 -0
- package/src/interfaces.ts +657 -0
- package/src/mcp.ts +345 -0
- package/src/providers/anthropic.ts +762 -0
- package/src/providers/google.ts +620 -0
- package/src/providers/index.ts +8 -0
- package/src/providers/ollama.ts +469 -0
- package/src/providers/openai.ts +392 -0
- package/src/router.ts +780 -0
- package/src/stream-decoder.ts +361 -0
- package/src/structured-output.ts +759 -0
- package/src/test-scripts/test-advanced-tools.ts +310 -0
- package/src/test-scripts/test-google-streaming-enhanced.ts +147 -0
- package/src/test-scripts/test-google-streaming.ts +63 -0
- package/src/test-scripts/test-google-system-prompt-comprehensive.ts +189 -0
- package/src/test-scripts/test-mcp-config.ts +28 -0
- package/src/test-scripts/test-mcp-connection.ts +29 -0
- package/src/test-scripts/test-system-message-positions.ts +163 -0
- package/src/test-scripts/test-system-prompt-improvement-demo.ts +83 -0
- package/src/test-scripts/test-tool-calling.ts +231 -0
- package/src/tests/ai-model.test.ts +1614 -0
- package/src/tests/auditor.test.ts +224 -0
- package/src/tests/http.test.ts +200 -0
- package/src/tests/interfaces.test.ts +117 -0
- package/src/tests/providers/google.test.ts +660 -0
- package/src/tests/providers/ollama.test.ts +954 -0
- package/src/tests/providers/openai.test.ts +1122 -0
- package/src/tests/router.test.ts +254 -0
- package/src/tests/stream-decoder.test.ts +179 -0
- package/src/tests/structured-output.test.ts +1450 -0
- package/src/tests/tools.test.ts +175 -0
- package/src/tools.ts +246 -0
- package/src/zod-adapter.ts +72 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test tool calling functionality with free local models
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AIModelFactory, ToolBuilder } from '../index';
|
|
6
|
+
|
|
7
|
+
async function testToolCallingLocal() {
|
|
8
|
+
console.log('🛠️ Testing Universal LLM Client Tool Calling with Local Models\n');
|
|
9
|
+
|
|
10
|
+
// Create models for testing (using models with good tool calling support)
|
|
11
|
+
const models = {
|
|
12
|
+
// Test with Ollama - qwen3:8b has excellent tool calling support
|
|
13
|
+
ollama: AIModelFactory.createOllamaChatModelWithTools('qwen3:8b'),
|
|
14
|
+
// Test with LM Studio - qwen/qwen3-8b for tool calling
|
|
15
|
+
lmstudio: AIModelFactory.createOpenAIChatModelWithTools('qwen/qwen3-8b', 'http://localhost:1234/v1')
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
console.log('📋 Test 1: Basic Calculator Tool\n');
|
|
19
|
+
|
|
20
|
+
for (const [provider, model] of Object.entries(models)) {
|
|
21
|
+
console.log(`\n🔧 Testing ${provider} (checking if server is available):`);
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await model.ensureReady();
|
|
25
|
+
|
|
26
|
+
const response = await model.chat([
|
|
27
|
+
{ role: 'user', content: 'What is 25 * 4 + 10? Please use the calculator tool to solve this mathematically.' }
|
|
28
|
+
], {}, {
|
|
29
|
+
tool_choice: 'auto'
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(`Response: ${response.content}`);
|
|
33
|
+
|
|
34
|
+
if (response.tool_calls) {
|
|
35
|
+
console.log(`🔨 Tool calls made:`, response.tool_calls.length);
|
|
36
|
+
for (const toolCall of response.tool_calls) {
|
|
37
|
+
console.log(` - ${toolCall.function.name}: ${toolCall.function.arguments}`);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
console.log('ℹ️ No tool calls made - model may have calculated directly');
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if ((error as Error).message.includes('ECONNREFUSED') || (error as Error).message.includes('fetch failed')) {
|
|
44
|
+
console.error(`❌ ${provider} server not running - skipping tests for this provider`);
|
|
45
|
+
} else {
|
|
46
|
+
console.error(`❌ Error with ${provider}:`, (error as Error).message);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Test automatic tool execution with calculator
|
|
52
|
+
console.log('\n\n📋 Test 2: Automatic Tool Execution\n');
|
|
53
|
+
|
|
54
|
+
const ollamaModel = models.ollama;
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
console.log('🔧 Testing automatic tool execution with Ollama:');
|
|
58
|
+
|
|
59
|
+
const response = await ollamaModel.chatWithTools([
|
|
60
|
+
{
|
|
61
|
+
role: 'user',
|
|
62
|
+
content: 'Calculate 15 * 8 + 32, then tell me what time it is right now'
|
|
63
|
+
}
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
console.log('✅ Final response:', response.content);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('❌ Error:', (error as Error).message);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Test multiple tools
|
|
72
|
+
console.log('\n\n📋 Test 3: Multiple Tool Usage\n');
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
console.log('🔧 Testing multiple tools with Ollama:');
|
|
76
|
+
|
|
77
|
+
// Register additional useful tools
|
|
78
|
+
const randomNumberTool = ToolBuilder.createTool<{ min: number; max: number; count?: number }>(
|
|
79
|
+
'generate_random_numbers',
|
|
80
|
+
'Generate random numbers within a range',
|
|
81
|
+
{
|
|
82
|
+
properties: {
|
|
83
|
+
min: { type: 'number', description: 'Minimum value' },
|
|
84
|
+
max: { type: 'number', description: 'Maximum value' },
|
|
85
|
+
count: { type: 'number', description: 'How many numbers to generate', default: 1 }
|
|
86
|
+
},
|
|
87
|
+
required: ['min', 'max']
|
|
88
|
+
},
|
|
89
|
+
(args) => {
|
|
90
|
+
const count = args.count || 1;
|
|
91
|
+
const numbers: any[] = [];
|
|
92
|
+
for (let i = 0; i < count; i++) {
|
|
93
|
+
numbers.push(Math.floor(Math.random() * (args.max - args.min + 1)) + args.min);
|
|
94
|
+
}
|
|
95
|
+
return { numbers, count: numbers.length };
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const textTool = ToolBuilder.createTool<{ text: string; operation: 'uppercase' | 'lowercase' | 'reverse' }>(
|
|
100
|
+
'text_transform',
|
|
101
|
+
'Transform text in various ways',
|
|
102
|
+
{
|
|
103
|
+
properties: {
|
|
104
|
+
text: { type: 'string', description: 'Text to transform' },
|
|
105
|
+
operation: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
enum: ['uppercase', 'lowercase', 'reverse'],
|
|
108
|
+
description: 'Type of transformation'
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
required: ['text', 'operation']
|
|
112
|
+
},
|
|
113
|
+
(args) => {
|
|
114
|
+
let result = args.text;
|
|
115
|
+
switch (args.operation) {
|
|
116
|
+
case 'uppercase':
|
|
117
|
+
result = args.text.toUpperCase();
|
|
118
|
+
break;
|
|
119
|
+
case 'lowercase':
|
|
120
|
+
result = args.text.toLowerCase();
|
|
121
|
+
break;
|
|
122
|
+
case 'reverse':
|
|
123
|
+
result = args.text.split('').reverse().join('');
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
return { original: args.text, transformed: result, operation: args.operation };
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
ollamaModel.registerTools([randomNumberTool, textTool]);
|
|
131
|
+
|
|
132
|
+
const response = await ollamaModel.chatWithTools([
|
|
133
|
+
{
|
|
134
|
+
role: 'user',
|
|
135
|
+
content: 'First calculate 100 / 4, then generate 3 random numbers between 1 and 10, and finally convert the text "hello world" to uppercase'
|
|
136
|
+
}
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
console.log('✅ Final response:', response.content);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error('❌ Error:', (error as Error).message);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Test custom tool
|
|
145
|
+
console.log('\n\n📋 Test 4: Custom Tool Registration\n');
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
// Register a custom tool
|
|
149
|
+
const customTool = ToolBuilder.createTool<{ city: string; country?: string }>(
|
|
150
|
+
'get_city_info',
|
|
151
|
+
'Get information about a city',
|
|
152
|
+
{
|
|
153
|
+
properties: {
|
|
154
|
+
city: { type: 'string', description: 'Name of the city' },
|
|
155
|
+
country: { type: 'string', description: 'Country the city is in' }
|
|
156
|
+
},
|
|
157
|
+
required: ['city']
|
|
158
|
+
},
|
|
159
|
+
(args) => ({
|
|
160
|
+
city: args.city,
|
|
161
|
+
country: args.country || 'Unknown',
|
|
162
|
+
population: Math.floor(Math.random() * 10000000) + 100000,
|
|
163
|
+
weather: 'Sunny',
|
|
164
|
+
timezone: 'UTC+0',
|
|
165
|
+
founded: Math.floor(Math.random() * 2000) + 1
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
ollamaModel.registerTool(
|
|
170
|
+
customTool.name,
|
|
171
|
+
customTool.description,
|
|
172
|
+
customTool.parameters,
|
|
173
|
+
customTool.handler
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
console.log('🔧 Testing custom tool:');
|
|
177
|
+
|
|
178
|
+
const response = await ollamaModel.chatWithTools([
|
|
179
|
+
{
|
|
180
|
+
role: 'user',
|
|
181
|
+
content: 'Can you get information about Paris, France?'
|
|
182
|
+
}
|
|
183
|
+
]);
|
|
184
|
+
|
|
185
|
+
console.log('✅ Custom tool response:', response.content);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.error('❌ Error:', (error as Error).message);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Test tool choice options
|
|
191
|
+
console.log('\n\n📋 Test 5: Tool Choice Control\n');
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
console.log('🔧 Testing forced tool usage:');
|
|
195
|
+
|
|
196
|
+
const response = await ollamaModel.chat([
|
|
197
|
+
{ role: 'user', content: 'Tell me about the weather today' }
|
|
198
|
+
], {}, {
|
|
199
|
+
tool_choice: { type: 'function', function: { name: 'get_current_time' } }
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
console.log('✅ Forced tool response:', response.content);
|
|
203
|
+
if (response.tool_calls) {
|
|
204
|
+
console.log('🔨 Tool used:', response.tool_calls[0]?.function.name);
|
|
205
|
+
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error('❌ Error:', (error as Error).message);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Clean up
|
|
211
|
+
Object.values(models).forEach(model => model.dispose());
|
|
212
|
+
|
|
213
|
+
console.log('\n✅ Tool calling tests completed!');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Add error handling for the main test
|
|
217
|
+
async function runTests() {
|
|
218
|
+
try {
|
|
219
|
+
await testToolCallingLocal();
|
|
220
|
+
} catch (error) {
|
|
221
|
+
console.error('💥 Test suite failed:', (error as Error).message);
|
|
222
|
+
console.error(error);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Run the tests
|
|
227
|
+
if (require.main === module) {
|
|
228
|
+
runTests();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export { testToolCallingLocal };
|