universal-llm-client 4.2.0 → 4.3.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +139 -103
  2. package/LICENSE +21 -21
  3. package/README.md +591 -591
  4. package/dist/ai-model.js.map +1 -1
  5. package/dist/auditor.js.map +1 -1
  6. package/dist/client.js.map +1 -1
  7. package/dist/http.js.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/interfaces.d.ts +20 -0
  10. package/dist/interfaces.d.ts.map +1 -1
  11. package/dist/interfaces.js.map +1 -1
  12. package/dist/mcp.js.map +1 -1
  13. package/dist/providers/anthropic.js.map +1 -1
  14. package/dist/providers/google.d.ts.map +1 -1
  15. package/dist/providers/google.js +2 -0
  16. package/dist/providers/google.js.map +1 -1
  17. package/dist/providers/index.js.map +1 -1
  18. package/dist/providers/ollama.js.map +1 -1
  19. package/dist/providers/openai.js.map +1 -1
  20. package/dist/router.js.map +1 -1
  21. package/dist/stream-decoder.js.map +1 -1
  22. package/dist/structured-output.js.map +1 -1
  23. package/dist/tools.js.map +1 -1
  24. package/dist/zod-adapter.js.map +1 -1
  25. package/package.json +115 -116
  26. package/src/ai-model.ts +0 -350
  27. package/src/auditor.ts +0 -213
  28. package/src/client.ts +0 -402
  29. package/src/debug/debug-google-streaming.ts +0 -97
  30. package/src/debug/debug-tool-execution.ts +0 -86
  31. package/src/debug/test-lmstudio-tools.ts +0 -155
  32. package/src/demos/README.md +0 -47
  33. package/src/demos/basic/universal-llm-examples.ts +0 -161
  34. package/src/demos/mcp/astrid-memory-demo.ts +0 -295
  35. package/src/demos/mcp/astrid-persona-memory.ts +0 -357
  36. package/src/demos/mcp/mcp-mongodb-demo.ts +0 -275
  37. package/src/demos/mcp/simple-astrid-memory.ts +0 -148
  38. package/src/demos/mcp/simple-mcp-demo.ts +0 -68
  39. package/src/demos/mcp/working-mcp-demo.ts +0 -62
  40. package/src/demos/model-alias-demo.ts +0 -0
  41. package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +0 -267
  42. package/src/demos/tools/astrid-memory-demo.ts +0 -270
  43. package/src/demos/tools/astrid-production-memory-clean.ts +0 -785
  44. package/src/demos/tools/astrid-production-memory.ts +0 -558
  45. package/src/demos/tools/basic-translation-test.ts +0 -66
  46. package/src/demos/tools/chromadb-similarity-tuning.ts +0 -390
  47. package/src/demos/tools/clean-multilingual-conversation.ts +0 -209
  48. package/src/demos/tools/clean-translation-test.ts +0 -119
  49. package/src/demos/tools/clean-universal-multilingual-test.ts +0 -131
  50. package/src/demos/tools/complete-rag-demo.ts +0 -369
  51. package/src/demos/tools/complete-tool-demo.ts +0 -132
  52. package/src/demos/tools/demo-tool-calling.ts +0 -124
  53. package/src/demos/tools/dynamic-language-switching-test.ts +0 -251
  54. package/src/demos/tools/hybrid-thinking-test.ts +0 -154
  55. package/src/demos/tools/memory-integration-test.ts +0 -420
  56. package/src/demos/tools/multilingual-memory-system.ts +0 -802
  57. package/src/demos/tools/ondemand-translation-demo.ts +0 -655
  58. package/src/demos/tools/production-tool-demo.ts +0 -245
  59. package/src/demos/tools/revolutionary-multilingual-test.ts +0 -151
  60. package/src/demos/tools/rigorous-language-analysis.ts +0 -218
  61. package/src/demos/tools/test-universal-memory-system.ts +0 -126
  62. package/src/demos/tools/translation-integration-guide.ts +0 -346
  63. package/src/demos/tools/universal-memory-system.ts +0 -560
  64. package/src/http.ts +0 -247
  65. package/src/index.ts +0 -161
  66. package/src/interfaces.ts +0 -657
  67. package/src/mcp.ts +0 -345
  68. package/src/providers/anthropic.ts +0 -762
  69. package/src/providers/google.ts +0 -620
  70. package/src/providers/index.ts +0 -8
  71. package/src/providers/ollama.ts +0 -469
  72. package/src/providers/openai.ts +0 -392
  73. package/src/router.ts +0 -780
  74. package/src/stream-decoder.ts +0 -361
  75. package/src/structured-output.ts +0 -759
  76. package/src/test-scripts/test-advanced-tools.ts +0 -310
  77. package/src/test-scripts/test-google-streaming-enhanced.ts +0 -147
  78. package/src/test-scripts/test-google-streaming.ts +0 -63
  79. package/src/test-scripts/test-google-system-prompt-comprehensive.ts +0 -189
  80. package/src/test-scripts/test-mcp-config.ts +0 -28
  81. package/src/test-scripts/test-mcp-connection.ts +0 -29
  82. package/src/test-scripts/test-system-message-positions.ts +0 -163
  83. package/src/test-scripts/test-system-prompt-improvement-demo.ts +0 -83
  84. package/src/test-scripts/test-tool-calling.ts +0 -231
  85. package/src/tests/ai-model.test.ts +0 -1614
  86. package/src/tests/auditor.test.ts +0 -224
  87. package/src/tests/http.test.ts +0 -200
  88. package/src/tests/interfaces.test.ts +0 -117
  89. package/src/tests/providers/google.test.ts +0 -660
  90. package/src/tests/providers/ollama.test.ts +0 -954
  91. package/src/tests/providers/openai.test.ts +0 -1122
  92. package/src/tests/router.test.ts +0 -254
  93. package/src/tests/stream-decoder.test.ts +0 -179
  94. package/src/tests/structured-output.test.ts +0 -1450
  95. package/src/tests/tools.test.ts +0 -175
  96. package/src/tools.ts +0 -246
  97. package/src/zod-adapter.ts +0 -72
@@ -1,231 +0,0 @@
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 };