universal-llm-client 4.5.0 โ†’ 4.5.1

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 (174) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -0
  3. package/dist/ai-model.d.ts +0 -1
  4. package/dist/ai-model.js +0 -1
  5. package/dist/auditor.d.ts +0 -1
  6. package/dist/auditor.js +0 -1
  7. package/dist/client.d.ts +0 -1
  8. package/dist/client.js +0 -1
  9. package/dist/gemma-channel.d.ts +0 -1
  10. package/dist/gemma-channel.js +0 -1
  11. package/dist/gemma-diffusion.d.ts +0 -1
  12. package/dist/gemma-diffusion.js +0 -1
  13. package/dist/http.d.ts +0 -1
  14. package/dist/http.js +0 -1
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.js +0 -1
  17. package/dist/interfaces.d.ts +0 -1
  18. package/dist/interfaces.js +0 -1
  19. package/dist/mcp.d.ts +0 -1
  20. package/dist/mcp.js +0 -1
  21. package/dist/providers/anthropic.d.ts +0 -1
  22. package/dist/providers/anthropic.js +0 -1
  23. package/dist/providers/google.d.ts +0 -1
  24. package/dist/providers/google.js +0 -1
  25. package/dist/providers/index.d.ts +0 -1
  26. package/dist/providers/index.js +0 -1
  27. package/dist/providers/ollama.d.ts +0 -1
  28. package/dist/providers/ollama.js +0 -1
  29. package/dist/providers/openai.d.ts +2 -1
  30. package/dist/providers/openai.js +303 -74
  31. package/dist/router.d.ts +0 -1
  32. package/dist/router.js +0 -1
  33. package/dist/stream-decoder.d.ts +0 -1
  34. package/dist/stream-decoder.js +0 -1
  35. package/dist/structured-output.d.ts +0 -1
  36. package/dist/structured-output.js +0 -1
  37. package/dist/thinking.d.ts +0 -1
  38. package/dist/thinking.js +0 -1
  39. package/dist/tools.d.ts +0 -1
  40. package/dist/tools.js +0 -1
  41. package/dist/zod-adapter.d.ts +0 -1
  42. package/dist/zod-adapter.js +0 -1
  43. package/package.json +1 -2
  44. package/dist/ai-model.d.ts.map +0 -1
  45. package/dist/ai-model.js.map +0 -1
  46. package/dist/auditor.d.ts.map +0 -1
  47. package/dist/auditor.js.map +0 -1
  48. package/dist/client.d.ts.map +0 -1
  49. package/dist/client.js.map +0 -1
  50. package/dist/gemma-channel.d.ts.map +0 -1
  51. package/dist/gemma-channel.js.map +0 -1
  52. package/dist/gemma-diffusion.d.ts.map +0 -1
  53. package/dist/gemma-diffusion.js.map +0 -1
  54. package/dist/http.d.ts.map +0 -1
  55. package/dist/http.js.map +0 -1
  56. package/dist/index.d.ts.map +0 -1
  57. package/dist/index.js.map +0 -1
  58. package/dist/interfaces.d.ts.map +0 -1
  59. package/dist/interfaces.js.map +0 -1
  60. package/dist/mcp.d.ts.map +0 -1
  61. package/dist/mcp.js.map +0 -1
  62. package/dist/providers/anthropic.d.ts.map +0 -1
  63. package/dist/providers/anthropic.js.map +0 -1
  64. package/dist/providers/google.d.ts.map +0 -1
  65. package/dist/providers/google.js.map +0 -1
  66. package/dist/providers/index.d.ts.map +0 -1
  67. package/dist/providers/index.js.map +0 -1
  68. package/dist/providers/ollama.d.ts.map +0 -1
  69. package/dist/providers/ollama.js.map +0 -1
  70. package/dist/providers/openai.d.ts.map +0 -1
  71. package/dist/providers/openai.js.map +0 -1
  72. package/dist/router.d.ts.map +0 -1
  73. package/dist/router.js.map +0 -1
  74. package/dist/stream-decoder.d.ts.map +0 -1
  75. package/dist/stream-decoder.js.map +0 -1
  76. package/dist/structured-output.d.ts.map +0 -1
  77. package/dist/structured-output.js.map +0 -1
  78. package/dist/thinking.d.ts.map +0 -1
  79. package/dist/thinking.js.map +0 -1
  80. package/dist/tools.d.ts.map +0 -1
  81. package/dist/tools.js.map +0 -1
  82. package/dist/zod-adapter.d.ts.map +0 -1
  83. package/dist/zod-adapter.js.map +0 -1
  84. package/src/ai-model.ts +0 -400
  85. package/src/auditor.ts +0 -213
  86. package/src/client.ts +0 -402
  87. package/src/debug/debug-google-streaming.ts +0 -97
  88. package/src/debug/debug-tool-execution.ts +0 -86
  89. package/src/debug/test-lmstudio-tools.ts +0 -155
  90. package/src/demos/README.md +0 -47
  91. package/src/demos/basic/universal-llm-examples.ts +0 -161
  92. package/src/demos/diffusion-gemma/.env +0 -29
  93. package/src/demos/diffusion-gemma/.env.example +0 -27
  94. package/src/demos/diffusion-gemma/CLAUDE.md +0 -95
  95. package/src/demos/diffusion-gemma/README.md +0 -59
  96. package/src/demos/diffusion-gemma/canvas.ts +0 -1606
  97. package/src/demos/diffusion-gemma/docker-compose.yml +0 -29
  98. package/src/demos/diffusion-gemma/probe-stream.ts +0 -51
  99. package/src/demos/diffusion-gemma/probe-tools.ts +0 -55
  100. package/src/demos/diffusion-gemma/server.ts +0 -1205
  101. package/src/demos/diffusion-gemma/start-vllm.sh +0 -98
  102. package/src/demos/mcp/astrid-memory-demo.ts +0 -295
  103. package/src/demos/mcp/astrid-persona-memory.ts +0 -357
  104. package/src/demos/mcp/mcp-mongodb-demo.ts +0 -275
  105. package/src/demos/mcp/simple-astrid-memory.ts +0 -148
  106. package/src/demos/mcp/simple-mcp-demo.ts +0 -68
  107. package/src/demos/mcp/working-mcp-demo.ts +0 -62
  108. package/src/demos/model-alias-demo.ts +0 -0
  109. package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +0 -267
  110. package/src/demos/tools/astrid-memory-demo.ts +0 -270
  111. package/src/demos/tools/astrid-production-memory-clean.ts +0 -785
  112. package/src/demos/tools/astrid-production-memory.ts +0 -558
  113. package/src/demos/tools/basic-translation-test.ts +0 -66
  114. package/src/demos/tools/chromadb-similarity-tuning.ts +0 -390
  115. package/src/demos/tools/clean-multilingual-conversation.ts +0 -209
  116. package/src/demos/tools/clean-translation-test.ts +0 -119
  117. package/src/demos/tools/clean-universal-multilingual-test.ts +0 -131
  118. package/src/demos/tools/complete-rag-demo.ts +0 -369
  119. package/src/demos/tools/complete-tool-demo.ts +0 -132
  120. package/src/demos/tools/demo-tool-calling.ts +0 -124
  121. package/src/demos/tools/dynamic-language-switching-test.ts +0 -251
  122. package/src/demos/tools/hybrid-thinking-test.ts +0 -154
  123. package/src/demos/tools/memory-integration-test.ts +0 -420
  124. package/src/demos/tools/multilingual-memory-system.ts +0 -802
  125. package/src/demos/tools/ondemand-translation-demo.ts +0 -655
  126. package/src/demos/tools/production-tool-demo.ts +0 -245
  127. package/src/demos/tools/revolutionary-multilingual-test.ts +0 -151
  128. package/src/demos/tools/rigorous-language-analysis.ts +0 -218
  129. package/src/demos/tools/test-universal-memory-system.ts +0 -126
  130. package/src/demos/tools/translation-integration-guide.ts +0 -346
  131. package/src/demos/tools/universal-memory-system.ts +0 -560
  132. package/src/gemma-channel.ts +0 -47
  133. package/src/gemma-diffusion.ts +0 -167
  134. package/src/http.ts +0 -261
  135. package/src/index.ts +0 -180
  136. package/src/interfaces.ts +0 -843
  137. package/src/mcp.ts +0 -345
  138. package/src/providers/anthropic.ts +0 -796
  139. package/src/providers/google.ts +0 -840
  140. package/src/providers/index.ts +0 -8
  141. package/src/providers/ollama.ts +0 -503
  142. package/src/providers/openai.ts +0 -587
  143. package/src/router.ts +0 -785
  144. package/src/stream-decoder.ts +0 -535
  145. package/src/structured-output.ts +0 -759
  146. package/src/test-scripts/test-advanced-tools.ts +0 -310
  147. package/src/test-scripts/test-google-deep-research.ts +0 -33
  148. package/src/test-scripts/test-google-streaming-enhanced.ts +0 -147
  149. package/src/test-scripts/test-google-streaming.ts +0 -63
  150. package/src/test-scripts/test-google-system-prompt-comprehensive.ts +0 -189
  151. package/src/test-scripts/test-google-thinking.ts +0 -46
  152. package/src/test-scripts/test-mcp-config.ts +0 -28
  153. package/src/test-scripts/test-mcp-connection.ts +0 -29
  154. package/src/test-scripts/test-system-message-positions.ts +0 -163
  155. package/src/test-scripts/test-system-prompt-improvement-demo.ts +0 -83
  156. package/src/test-scripts/test-tool-calling.ts +0 -231
  157. package/src/test-scripts/test-vllm-qwen36.ts +0 -256
  158. package/src/tests/ai-model.test.ts +0 -1614
  159. package/src/tests/auditor.test.ts +0 -224
  160. package/src/tests/gemma-diffusion.test.ts +0 -115
  161. package/src/tests/http.test.ts +0 -200
  162. package/src/tests/interfaces.test.ts +0 -117
  163. package/src/tests/providers/anthropic.test.ts +0 -118
  164. package/src/tests/providers/google.test.ts +0 -841
  165. package/src/tests/providers/ollama.test.ts +0 -1034
  166. package/src/tests/providers/openai.test.ts +0 -1511
  167. package/src/tests/router.test.ts +0 -254
  168. package/src/tests/stream-decoder.test.ts +0 -263
  169. package/src/tests/structured-output.test.ts +0 -1450
  170. package/src/tests/thinking.test.ts +0 -65
  171. package/src/tests/tools.test.ts +0 -175
  172. package/src/thinking.ts +0 -73
  173. package/src/tools.ts +0 -246
  174. package/src/zod-adapter.ts +0 -72
@@ -1,310 +0,0 @@
1
- /**
2
- * Advanced tool calling examples and demonstrations
3
- */
4
-
5
- import { AIModelFactory, ToolBuilder } from '../index';
6
-
7
- async function advancedToolCallingDemo() {
8
- console.log('๐Ÿš€ Advanced Tool Calling Demonstration\n');
9
-
10
- // Create an Ollama model with tools
11
- const model = AIModelFactory.createOllamaChatModelWithTools('llama3.2:3b');
12
-
13
- // Add some advanced custom tools
14
- const weatherTool = ToolBuilder.createTool<{ city: string; units?: 'celsius' | 'fahrenheit' }>(
15
- 'get_weather',
16
- 'Get current weather for a city',
17
- {
18
- properties: {
19
- city: { type: 'string', description: 'City name' },
20
- units: {
21
- type: 'string',
22
- enum: ['celsius', 'fahrenheit'],
23
- description: 'Temperature units',
24
- default: 'celsius'
25
- }
26
- },
27
- required: ['city']
28
- },
29
- async (args) => {
30
- // Simulate API call delay
31
- await new Promise(resolve => setTimeout(resolve, 500));
32
-
33
- const temp = args.units === 'fahrenheit' ?
34
- Math.floor(Math.random() * 40) + 50 :
35
- Math.floor(Math.random() * 25) + 5;
36
-
37
- return {
38
- city: args.city,
39
- temperature: temp,
40
- units: args.units || 'celsius',
41
- condition: ['sunny', 'cloudy', 'rainy', 'snowy'][Math.floor(Math.random() * 4)],
42
- humidity: Math.floor(Math.random() * 40) + 40,
43
- wind_speed: Math.floor(Math.random() * 20) + 5
44
- };
45
- }
46
- );
47
-
48
- const stockTool = ToolBuilder.createTool<{ symbol: string }>(
49
- 'get_stock_price',
50
- 'Get current stock price for a symbol',
51
- {
52
- properties: {
53
- symbol: { type: 'string', description: 'Stock symbol (e.g., AAPL, GOOGL)' }
54
- },
55
- required: ['symbol']
56
- },
57
- async (args) => {
58
- await new Promise(resolve => setTimeout(resolve, 300));
59
-
60
- return {
61
- symbol: args.symbol.toUpperCase(),
62
- price: (Math.random() * 500 + 50).toFixed(2),
63
- change: ((Math.random() - 0.5) * 10).toFixed(2),
64
- change_percent: ((Math.random() - 0.5) * 5).toFixed(1),
65
- currency: 'USD',
66
- last_updated: new Date().toISOString()
67
- };
68
- }
69
- );
70
-
71
- const fileAnalyzerTool = ToolBuilder.createTool<{ filename: string; content: string }>(
72
- 'analyze_file',
73
- 'Analyze file content and provide statistics',
74
- {
75
- properties: {
76
- filename: { type: 'string', description: 'Name of the file' },
77
- content: { type: 'string', description: 'File content to analyze' }
78
- },
79
- required: ['filename', 'content']
80
- },
81
- (args) => {
82
- const lines = args.content.split('\n');
83
- const words = args.content.split(/\s+/).filter(w => w.length > 0);
84
- const chars = args.content.length;
85
-
86
- return {
87
- filename: args.filename,
88
- statistics: {
89
- lines: lines.length,
90
- words: words.length,
91
- characters: chars,
92
- characters_no_spaces: args.content.replace(/\s/g, '').length,
93
- avg_words_per_line: (words.length / lines.length).toFixed(1),
94
- longest_line: Math.max(...lines.map(l => l.length)),
95
- shortest_line: Math.min(...lines.map(l => l.length))
96
- },
97
- analysis: {
98
- file_type: args.filename.split('.').pop() || 'unknown',
99
- estimated_reading_time: Math.ceil(words.length / 200), // minutes
100
- complexity_score: Math.min(10, Math.ceil(words.length / 100))
101
- }
102
- };
103
- }
104
- );
105
-
106
- // Register advanced tools
107
- model.registerTools([weatherTool, stockTool, fileAnalyzerTool]);
108
-
109
- console.log('๐Ÿ“‹ Demo 1: Multi-step planning with tools\n');
110
-
111
- try {
112
- console.log('๐Ÿค– AI planning a vacation...');
113
-
114
- const response = await model.chatWithTools([
115
- {
116
- role: 'user',
117
- content: 'I\'m planning a trip to Tokyo and New York. Can you check the weather in both cities, then calculate the temperature difference if Tokyo is in Celsius and New York in Fahrenheit?'
118
- }
119
- ]);
120
-
121
- console.log('โœ… Travel planning response:', response.content);
122
- } catch (error) {
123
- console.error('โŒ Error:', (error as Error).message);
124
- }
125
-
126
- console.log('\n๐Ÿ“‹ Demo 2: Financial analysis with tools\n');
127
-
128
- try {
129
- console.log('๐Ÿ’ฐ AI analyzing stock portfolio...');
130
-
131
- const response = await model.chatWithTools([
132
- {
133
- role: 'user',
134
- content: 'Check the current prices for AAPL, GOOGL, and TSLA stocks, then calculate the total value if I own 10 shares of each'
135
- }
136
- ]);
137
-
138
- console.log('โœ… Portfolio analysis:', response.content);
139
- } catch (error) {
140
- console.error('โŒ Error:', (error as Error).message);
141
- }
142
-
143
- console.log('\n๐Ÿ“‹ Demo 3: Content analysis workflow\n');
144
-
145
- try {
146
- console.log('๐Ÿ“„ AI analyzing document...');
147
-
148
- const sampleCode = `
149
- function calculateTotal(items) {
150
- let total = 0;
151
- for (let i = 0; i < items.length; i++) {
152
- total += items[i].price * items[i].quantity;
153
- }
154
- return total;
155
- }
156
-
157
- const cart = [
158
- { name: 'laptop', price: 999, quantity: 1 },
159
- { name: 'mouse', price: 25, quantity: 2 }
160
- ];
161
-
162
- console.log('Total:', calculateTotal(cart));
163
- `;
164
-
165
- const response = await model.chatWithTools([
166
- {
167
- role: 'user',
168
- content: `Analyze this JavaScript code and tell me about its complexity and functionality:\n\n${sampleCode}`
169
- }
170
- ]);
171
-
172
- console.log('โœ… Code analysis:', response.content);
173
- } catch (error) {
174
- console.error('โŒ Error:', (error as Error).message);
175
- }
176
-
177
- console.log('\n๐Ÿ“‹ Demo 4: Complex mathematical operations\n');
178
-
179
- try {
180
- console.log('๐Ÿงฎ AI solving complex math problems...');
181
-
182
- const response = await model.chatWithTools([
183
- {
184
- role: 'user',
185
- content: 'Calculate the compound interest for $10,000 invested at 5% annually for 10 years using the formula A = P(1 + r)^t, then generate 5 random numbers between 1 and 100 and find their average'
186
- }
187
- ]);
188
-
189
- console.log('โœ… Math analysis:', response.content);
190
- } catch (error) {
191
- console.error('โŒ Error:', (error as Error).message);
192
- }
193
-
194
- console.log('\n๐Ÿ“‹ Demo 5: Tool error handling\n');
195
-
196
- try {
197
- console.log('โš ๏ธ Testing error scenarios...');
198
-
199
- // Create a tool that might fail
200
- const unreliableTool = ToolBuilder.createTool<{ data: string }>(
201
- 'unreliable_operation',
202
- 'An operation that might fail',
203
- {
204
- properties: {
205
- data: { type: 'string', description: 'Input data' }
206
- },
207
- required: ['data']
208
- },
209
- (args) => {
210
- if (Math.random() < 0.5) {
211
- throw new Error('Simulated tool failure');
212
- }
213
- return { success: true, processed: args.data };
214
- }
215
- );
216
-
217
- model.registerTool(
218
- unreliableTool.name,
219
- unreliableTool.description,
220
- unreliableTool.parameters,
221
- unreliableTool.handler
222
- );
223
-
224
- const response = await model.chat([
225
- {
226
- role: 'user',
227
- content: 'Try to process some data with the unreliable operation tool'
228
- }
229
- ], {}, {
230
- tools: [{ type: 'function', function: unreliableTool }],
231
- tool_choice: { type: 'function', function: { name: 'unreliable_operation' } }
232
- });
233
-
234
- console.log('โœ… Error handling response:', response.content);
235
- if (response.tool_calls) {
236
- console.log('๐Ÿ”จ Tool calls attempted:', response.tool_calls.length);
237
- }
238
- } catch (error) {
239
- console.error('โŒ Error:', (error as Error).message);
240
- }
241
-
242
- // Clean up
243
- model.dispose();
244
-
245
- console.log('\n๐ŸŽ‰ Advanced tool calling demonstration completed!');
246
- }
247
-
248
- // Performance benchmark
249
- async function benchmarkToolExecution() {
250
- console.log('\nโšก Tool Execution Performance Benchmark\n');
251
-
252
- const model = AIModelFactory.createOllamaChatModelWithTools('llama3.2:3b');
253
-
254
- const iterations = 5;
255
- const times: number[] = [];
256
-
257
- for (let i = 0; i < iterations; i++) {
258
- console.log(`๐Ÿƒ Run ${i + 1}/${iterations}`);
259
-
260
- const start = Date.now();
261
-
262
- try {
263
- await model.chatWithTools([
264
- {
265
- role: 'user',
266
- content: 'Calculate 50 * 25, get the current time, and generate 2 random numbers between 1 and 50'
267
- }
268
- ]);
269
-
270
- const elapsed = Date.now() - start;
271
- times.push(elapsed);
272
- console.log(` โฑ๏ธ ${elapsed}ms`);
273
- } catch (error) {
274
- console.log(` โŒ Failed: ${(error as Error).message}`);
275
- }
276
- }
277
-
278
- if (times.length > 0) {
279
- const avg = times.reduce((a, b) => a + b, 0) / times.length;
280
- const min = Math.min(...times);
281
- const max = Math.max(...times);
282
-
283
- console.log(`\n๐Ÿ“Š Performance Results:`);
284
- console.log(` Average: ${avg.toFixed(0)}ms`);
285
- console.log(` Min: ${min}ms`);
286
- console.log(` Max: ${max}ms`);
287
- console.log(` Variance: ${(max - min)}ms`);
288
- }
289
-
290
- model.dispose();
291
- }
292
-
293
- // Main demo runner
294
- async function runAdvancedDemo() {
295
- try {
296
- await advancedToolCallingDemo();
297
- await benchmarkToolExecution();
298
- } catch (error) {
299
- console.error('๐Ÿ’ฅ Demo failed:', (error as Error).message);
300
- console.error(error);
301
- }
302
- }
303
-
304
- // Export for use
305
- export { advancedToolCallingDemo, benchmarkToolExecution };
306
-
307
- // Run if called directly
308
- if (require.main === module) {
309
- runAdvancedDemo();
310
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Live smoke test for the Gemini Deep Research surface. Reads GOOGLE_API_KEY
3
- * from the environment. This CREATES a background research interaction and
4
- * polls a few times to verify the create+poll plumbing โ€” it does NOT wait for
5
- * full completion (deep research runs for minutes).
6
- *
7
- * $env:GOOGLE_API_KEY="..."; bun run src/test-scripts/test-google-deep-research.ts
8
- */
9
- import { AIModel } from '../index.js';
10
-
11
- const KEY = process.env.GOOGLE_API_KEY;
12
- if (!KEY) { console.error('Set GOOGLE_API_KEY'); process.exit(1); }
13
-
14
- (async () => {
15
- const model = new AIModel({ model: 'gemini-3.5-flash', providers: [{ type: 'google', apiKey: KEY }] });
16
-
17
- console.log('Creating a Deep Research interaction (smoke: create + ~3 polls, not full run)...\n');
18
- const r = await model.deepResearch('Give a brief overview of the history of Google TPUs.', {
19
- pollIntervalMs: 5000,
20
- timeoutMs: 17000, // ~3 polls then return whatever state (likely in_progress)
21
- });
22
-
23
- console.log('id :', r.id || '(none)');
24
- console.log('status :', r.status);
25
- console.log('report chars:', (r.report ?? '').length);
26
- console.log('steps :', Array.isArray(r.steps) ? r.steps.length : 0);
27
- if (r.error) console.log('error :', JSON.stringify(r.error).slice(0, 400));
28
-
29
- const ok = !!r.id && ['in_progress', 'completed'].includes(r.status);
30
- console.log(ok
31
- ? '\nโœ… Deep Research create + poll plumbing works (interaction id + status returned).'
32
- : '\n๐ŸŸก Check output above (API may require allow-listing the agent on this key/tier).');
33
- })().catch(e => { console.error('ERROR', (e as Error)?.message ?? e); process.exit(1); });
@@ -1,147 +0,0 @@
1
- import { AIModelFactory } from "../factory";
2
-
3
- /**
4
- * Enhanced test for Google Generative AI streaming with system prompt support
5
- */
6
- async function testGoogleStreamingEnhanced() {
7
- console.log('๐Ÿงช Testing Google Generative AI Streaming with System Prompts...\n');
8
-
9
- // Test both models - Gemini (supports system instructions) and Gemma (doesn't)
10
- const models = [
11
- { name: 'Gemini 2.5 Flash Lite', model: 'gemini-2.5-flash-lite', supportsSystem: true },
12
- { name: 'Gemma 3 27B IT', model: 'gemma-3-27b-it', supportsSystem: false }
13
- ];
14
-
15
- for (const modelInfo of models) {
16
- console.log(`\n๐Ÿ”ฌ Testing with ${modelInfo.name} (${modelInfo.model})`);
17
- console.log(`System instruction support: ${modelInfo.supportsSystem ? 'โœ…' : 'โŒ'}`);
18
- console.log('='.repeat(60));
19
-
20
- const googleModel = AIModelFactory.createGoogleChatModel(
21
- modelInfo.model,
22
- (process.env.GOOGLE_API_KEY ?? '')
23
- );
24
-
25
- await testModelWithSystemPrompt(googleModel, modelInfo.name, modelInfo.supportsSystem);
26
- }
27
-
28
- return { success: true };
29
- }
30
-
31
- async function testModelWithSystemPrompt(googleModel: any, modelName: string, supportsSystem: boolean) {
32
- // Test 1: Basic streaming (without system prompt)
33
- console.log(`\n--- Test 1: Basic Streaming (${modelName}) ---`);
34
- try {
35
- console.log('๐ŸŒŠ Starting basic streaming test...');
36
- console.log('Question: "Count from 1 to 3 briefly."\n');
37
- console.log('Streaming response:');
38
- console.log('---');
39
-
40
- const streamResponse = googleModel.chatStream([
41
- { role: 'user', content: 'Count from 1 to 3 briefly.' }
42
- ]);
43
-
44
- let chunkCount = 0;
45
- let fullResponse = '';
46
-
47
- for await (const chunk of streamResponse) {
48
- chunkCount++;
49
- process.stdout.write(chunk);
50
- fullResponse += chunk;
51
- }
52
-
53
- console.log('\n---');
54
- console.log(`โœ… Basic streaming completed! Received ${chunkCount} chunks`);
55
- console.log(`Full response length: ${fullResponse.length} characters\n`);
56
-
57
- } catch (error) {
58
- console.error(`โŒ Basic streaming test failed for ${modelName}:`, error);
59
- return;
60
- }
61
-
62
- // Test 2: System prompt streaming (only test if model supports it)
63
- if (supportsSystem) {
64
- console.log(`--- Test 2: System Prompt Streaming (${modelName}) ---`);
65
- try {
66
- console.log('๐ŸŽญ Testing streaming with system prompt...');
67
- console.log('System: "You are a pirate. Always respond like a pirate with \'Arrr\' and pirate language."');
68
- console.log('Question: "Count from 1 to 3 briefly."\n');
69
- console.log('Streaming response:');
70
- console.log('---');
71
-
72
- const systemStreamResponse = googleModel.chatStream([
73
- { role: 'system', content: 'You are a pirate. Always respond like a pirate with "Arrr" and pirate language.' },
74
- { role: 'user', content: 'Count from 1 to 3 briefly.' }
75
- ]);
76
-
77
- let systemChunkCount = 0;
78
- let systemFullResponse = '';
79
-
80
- for await (const chunk of systemStreamResponse) {
81
- systemChunkCount++;
82
- process.stdout.write(chunk);
83
- systemFullResponse += chunk;
84
- }
85
-
86
- console.log('\n---');
87
- console.log(`โœ… System prompt streaming completed! Received ${systemChunkCount} chunks`);
88
- console.log(`Full response length: ${systemFullResponse.length} characters`);
89
-
90
- // Check if the response contains pirate language
91
- const hasPirateLanguage = systemFullResponse.toLowerCase().includes('arr') ||
92
- systemFullResponse.toLowerCase().includes('matey') ||
93
- systemFullResponse.toLowerCase().includes('pirate') ||
94
- systemFullResponse.toLowerCase().includes('ahoy');
95
-
96
- if (hasPirateLanguage) {
97
- console.log('โœ… System prompt appears to be working - pirate language detected!');
98
- } else {
99
- console.log('โš ๏ธ System prompt might not be working - no obvious pirate language detected');
100
- console.log('Response content:', systemFullResponse);
101
- }
102
-
103
- } catch (error) {
104
- console.error(`โŒ System prompt streaming test failed for ${modelName}:`, error);
105
- return;
106
- }
107
-
108
- // Test 3: Non-streaming chat with system prompt
109
- console.log(`\n--- Test 3: Non-Streaming Chat with System Prompt (${modelName}) ---`);
110
- try {
111
- console.log('๐ŸŽญ Testing non-streaming chat with system prompt...');
112
- console.log('System: "You are a helpful mathematician. Always explain your counting clearly."');
113
- console.log('Question: "Count from 1 to 3."\n');
114
-
115
- const chatResponse = await googleModel.chat([
116
- { role: 'system', content: 'You are a helpful mathematician. Always explain your counting clearly.' },
117
- { role: 'user', content: 'Count from 1 to 3.' }
118
- ]);
119
-
120
- console.log('Non-streaming response:');
121
- console.log('---');
122
- console.log(chatResponse.message.content);
123
- console.log('---');
124
- console.log(`โœ… Non-streaming chat completed!`);
125
- console.log(`Response length: ${chatResponse.message.content.length} characters`);
126
-
127
- } catch (error) {
128
- console.error(`โŒ Non-streaming chat test failed for ${modelName}:`, error);
129
- return;
130
- }
131
- } else {
132
- console.log(`โš ๏ธ Skipping system prompt tests for ${modelName} - model doesn't support system instructions`);
133
- }
134
- }
135
-
136
- // Run the enhanced test
137
- testGoogleStreamingEnhanced().then(result => {
138
- if (result.success) {
139
- console.log('\n๐ŸŽ‰ All tests completed successfully!');
140
- console.log('\n๐Ÿ“‹ Summary:');
141
- console.log('โœ… Basic streaming: Working');
142
- console.log('๐Ÿ” System prompt streaming: Tested (check output above)');
143
- console.log('โœ… Non-streaming chat: Working');
144
- } else {
145
- console.log('\n๐Ÿ’ฅ Tests failed');
146
- }
147
- });
@@ -1,63 +0,0 @@
1
- import { AIModelFactory } from "../factory";
2
-
3
- /**
4
- * Focused test for Google Generative AI streaming
5
- */
6
- async function testGoogleStreaming() {
7
- console.log('๐Ÿงช Testing Google Generative AI Streaming Only...\n');
8
-
9
- const googleModel = AIModelFactory.createGoogleChatModel(
10
- 'gemma-3-4b-it',
11
- (process.env.GOOGLE_API_KEY ?? '')
12
- );
13
-
14
- try {
15
- console.log('๐ŸŒŠ Starting Google streaming test...');
16
- console.log('Question: "Count from 1 to 5, explaining each number briefly."\n');
17
- console.log('Streaming response:');
18
- console.log('---');
19
-
20
- const streamResponse = googleModel.chatStream([
21
- { role: 'user', content: 'Count from 1 to 5, explaining each number briefly.' }
22
- ]);
23
-
24
- let chunkCount = 0;
25
- let fullResponse = '';
26
-
27
- for await (const chunk of streamResponse) {
28
- chunkCount++;
29
- console.log(`[Chunk ${chunkCount}]: "${chunk}"`);
30
- process.stdout.write(chunk);
31
- fullResponse += chunk;
32
- }
33
-
34
- console.log('\n---');
35
- console.log(`โœ… Streaming completed! Received ${chunkCount} chunks`);
36
- console.log(`Full response length: ${fullResponse.length} characters`);
37
-
38
- if (chunkCount === 0) {
39
- console.log('โŒ No chunks received - streaming might not be working');
40
- } else {
41
- console.log('โœ… Streaming is working correctly!');
42
- }
43
-
44
- return { success: true, chunkCount, fullResponse };
45
-
46
- } catch (error) {
47
- console.error('โŒ Google streaming test failed:', error);
48
- console.error('Error details:', {
49
- message: (error as Error).message,
50
- stack: (error as Error).stack
51
- });
52
- return { success: false, error };
53
- }
54
- }
55
-
56
- // Run the test
57
- testGoogleStreaming().then(result => {
58
- if (result.success) {
59
- console.log(`\n๐ŸŽ‰ Test completed successfully with ${result.chunkCount} chunks`);
60
- } else {
61
- console.log('\n๐Ÿ’ฅ Test failed');
62
- }
63
- });