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