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,97 +0,0 @@
1
- import {request} from 'undici';
2
-
3
- /**
4
- * Debug Google streaming by examining raw responses
5
- */
6
- async function debugGoogleStreaming() {
7
- console.log('๐Ÿ” Debugging Google Generative AI Streaming...\n');
8
-
9
- const apiKey = 'AIzaSyBDbo7iVNEuCcRNTgDIgRrkGpFKisXXnm0';
10
- const model = 'gemma-3-4b-it';
11
- const endpoint = `https://generativelanguage.googleapis.com/v1beta/models/${model}:streamGenerateContent`;
12
-
13
- // First, let's try the raw Google API call to see what the response looks like
14
- const url = new URL(endpoint);
15
- url.searchParams.set('key', apiKey);
16
-
17
- const requestBody = {
18
- contents: [
19
- {
20
- role: 'user',
21
- parts: [{ text: 'Count from 1 to 3 briefly.' }]
22
- }
23
- ],
24
- generationConfig: {
25
- responseMimeType: 'text/plain'
26
- }
27
- };
28
-
29
- console.log('๐Ÿ“ก Making raw request to:', url.toString());
30
- console.log('๐Ÿ“ฆ Request body:', JSON.stringify(requestBody, null, 2));
31
-
32
- try {
33
- const response = await request(url.toString(), {
34
- method: 'POST',
35
- headers: {
36
- 'Content-Type': 'application/json',
37
- 'Accept': 'text/event-stream',
38
- },
39
- body: JSON.stringify(requestBody)
40
- });
41
-
42
- console.log('๐Ÿ“‹ Response status:', response.statusCode);
43
- console.log('๐Ÿ“‹ Response headers:', response.headers);
44
-
45
- if (response.statusCode >= 400) {
46
- const errorText = await response.body.text();
47
- console.error('โŒ Error response:', errorText);
48
- return;
49
- }
50
-
51
- console.log('\n๐ŸŒŠ Raw streaming response:');
52
- console.log('---');
53
-
54
- const decoder = new TextDecoder();
55
- let chunkCount = 0;
56
-
57
- for await (const chunk of response.body) {
58
- chunkCount++;
59
- const text = decoder.decode(chunk, { stream: true });
60
- console.log(`[Raw Chunk ${chunkCount}]:`, JSON.stringify(text));
61
-
62
- // Parse each line
63
- const lines = text.split('\n').filter(line => line.trim());
64
- for (const line of lines) {
65
- console.log(`[Line]: "${line}"`);
66
-
67
- if (line.startsWith('data: ')) {
68
- const data = line.slice(6);
69
- console.log(`[Data]: "${data}"`);
70
-
71
- if (data !== '[DONE]') {
72
- try {
73
- const parsed = JSON.parse(data);
74
- console.log('[Parsed JSON]:', JSON.stringify(parsed, null, 2));
75
-
76
- // Check Google's response structure
77
- if (parsed.candidates?.[0]?.content?.parts?.[0]?.text) {
78
- console.log('[Content]:', parsed.candidates[0].content.parts[0].text);
79
- }
80
- } catch (parseError) {
81
- console.log('[Parse Error]:', parseError);
82
- }
83
- }
84
- }
85
- }
86
- }
87
-
88
- console.log('---');
89
- console.log(`โœ… Raw test completed with ${chunkCount} chunks`);
90
-
91
- } catch (error) {
92
- console.error('โŒ Raw test failed:', error);
93
- }
94
- }
95
-
96
- // Run the debug test
97
- debugGoogleStreaming();
@@ -1,86 +0,0 @@
1
- /**
2
- * Debug tool calling execution
3
- */
4
-
5
- import { AIModelFactory, ToolBuilder } from './index';
6
-
7
- async function debugToolCalling() {
8
- console.log('๐Ÿ” Debug Tool Calling Execution\n');
9
-
10
- const model = AIModelFactory.createOllamaChatModel('qwen3:8b');
11
-
12
- // Simple calculator tool
13
- const calcTool = ToolBuilder.createTool<{ expression: string }>(
14
- 'calculator',
15
- 'Calculate mathematical expressions',
16
- {
17
- properties: {
18
- expression: { type: 'string', description: 'Math expression to evaluate' }
19
- },
20
- required: ['expression']
21
- },
22
- (args) => {
23
- console.log('๐Ÿ”ง TOOL EXECUTING: calculator with', args);
24
- try {
25
- const result = Function(`"use strict"; return (${args.expression})`)();
26
- return { expression: args.expression, result, answer: `${args.expression} = ${result}` };
27
- } catch (error) {
28
- return { expression: args.expression, error: 'Invalid expression', result: null };
29
- }
30
- }
31
- );
32
-
33
- model.registerTool(calcTool.name, calcTool.description, calcTool.parameters, calcTool.handler);
34
-
35
- try {
36
- await model.ensureReady();
37
-
38
- console.log('๐Ÿ“‹ Test 1: Manual Tool Call Detection\n');
39
-
40
- const response1 = await model.chat([
41
- { role: 'user', content: 'What is 5 + 3?' }
42
- ], {}, { tool_choice: 'auto' });
43
-
44
- console.log('Response content:', response1.content);
45
- console.log('Tool calls detected:', response1.tool_calls?.length || 0);
46
-
47
- if (response1.tool_calls) {
48
- console.log('Tool call details:');
49
- response1.tool_calls.forEach((call, index) => {
50
- console.log(` ${index + 1}. ${call.function.name}: ${call.function.arguments}`);
51
- console.log(` Raw tool call:`, JSON.stringify(call, null, 2));
52
- });
53
-
54
- // Manual tool execution
55
- console.log('\n๐Ÿ”ง Manual Tool Execution:');
56
- for (const toolCall of response1.tool_calls) {
57
- try {
58
- const args = JSON.parse(toolCall.function.arguments);
59
- console.log('Parsed arguments:', args);
60
- const result = await calcTool.handler(args);
61
- console.log('Tool result:', result);
62
- } catch (error) {
63
- console.log('Tool execution error:', error);
64
- }
65
- }
66
- }
67
-
68
- console.log('\n๐Ÿ“‹ Test 2: Automatic Tool Execution\n');
69
-
70
- const response2 = await model.chatWithTools([
71
- { role: 'user', content: 'Calculate 10 * 7 for me' }
72
- ]);
73
-
74
- console.log('Automatic response:', response2.content);
75
-
76
- } catch (error) {
77
- console.error('โŒ Debug failed:', error);
78
- } finally {
79
- model.dispose();
80
- }
81
- }
82
-
83
- // Run the debug
84
- if (require.main === module) {
85
- debugToolCalling().catch(console.error);
86
- }
@@ -1,155 +0,0 @@
1
- /**
2
- * Debug test specifically for LM Studio tool calling with OpenAI API
3
- */
4
-
5
- async function testLMStudioTools() {
6
- console.log('๐Ÿ”ง Testing LM Studio Tool Calling with OpenAI API\n');
7
-
8
- // Create LM Studio model using OpenAI-compatible API
9
- const model = AIModelFactory.createOpenAIChatModel(
10
- 'qwen/qwen3-8b', // Tool-trained model
11
- 'http://192.168.100.136:1234/v1' // LM Studio URL
12
- );
13
-
14
- // Create simple test tools (same as our router test)
15
- const testTools = [
16
- ToolBuilder.createTool<{ expression: string }>(
17
- 'calculate',
18
- 'Perform mathematical calculations',
19
- {
20
- properties: {
21
- expression: {
22
- type: 'string',
23
- description: 'Mathematical expression to evaluate'
24
- }
25
- },
26
- required: ['expression']
27
- },
28
- (args) => {
29
- try {
30
- const result = eval(args.expression); // Safe for testing
31
- console.log(`๐Ÿ”ง Tool executed: calculate(${args.expression}) = ${result}`);
32
- return `The result of ${args.expression} is ${result}`;
33
- } catch (error) {
34
- console.log(`โŒ Tool error: calculate(${args.expression}) failed`);
35
- return `Error calculating ${args.expression}: ${error}`;
36
- }
37
- }
38
- ),
39
-
40
- ToolBuilder.createTool<{ location: string }>(
41
- 'get_weather',
42
- 'Get weather information',
43
- {
44
- properties: {
45
- location: {
46
- type: 'string',
47
- description: 'City and state/country'
48
- }
49
- },
50
- required: ['location']
51
- },
52
- (args) => {
53
- console.log(`๐Ÿ”ง Tool executed: get_weather(${args.location})`);
54
- return `The weather in ${args.location} is sunny and 72ยฐF.`;
55
- }
56
- )
57
- ];
58
-
59
- // Register tools
60
- model.registerTools(testTools);
61
-
62
- console.log('๐Ÿ“ Registered tools:', testTools.map(t => t.name).join(', '));
63
- console.log('');
64
-
65
- try {
66
- await model.ensureReady();
67
- console.log('โœ… LM Studio model ready\n');
68
-
69
- // Test 1: Basic calculation
70
- console.log('๐Ÿงฎ Test 1: Basic Calculation');
71
- console.log('Question: What is 15 multiplied by 23?');
72
-
73
- const response1 = await model.chatWithTools([
74
- { role: 'user', content: 'What is 15 multiplied by 23? Use the calculate tool.' }
75
- ]);
76
-
77
- console.log('Response:', response1.message?.content || 'No content');
78
- console.log('Usage:', response1.usage);
79
- console.log('');
80
-
81
- // Test 2: Weather query
82
- console.log('๐ŸŒค๏ธ Test 2: Weather Query');
83
- console.log('Question: Weather in San Francisco');
84
-
85
- const response2 = await model.chatWithTools([
86
- { role: 'user', content: 'What is the weather in San Francisco, CA?' }
87
- ]);
88
-
89
- console.log('Response:', response2.message?.content || 'No content');
90
- console.log('');
91
-
92
- // Test 3: Manual tool call inspection (without auto-execution)
93
- console.log('๐Ÿ” Test 3: Manual Tool Call Inspection');
94
- console.log('Question: Calculate 100 / 4 (without auto-execution)');
95
-
96
- const response3 = await model.chat([
97
- { role: 'user', content: 'Calculate 100 divided by 4 using the calculate tool.' }
98
- ], {}, {
99
- tool_choice: 'auto',
100
- executeTools: false // Don't auto-execute
101
- });
102
-
103
- console.log('Response content:', response3.message?.content || 'No content');
104
- console.log('Tool calls detected:', response3.message?.tool_calls?.length || 0);
105
-
106
- if (response3.message?.tool_calls) {
107
- response3.message.tool_calls.forEach((call, i) => {
108
- console.log(` Tool ${i + 1}: ${call.function.name}(${call.function.arguments})`);
109
- });
110
- }
111
- console.log('');
112
-
113
- // Test 4: Different tool_choice settings
114
- console.log('๐ŸŽฏ Test 4: Different tool_choice Settings');
115
-
116
- const testCases = [
117
- { choice: 'auto', desc: 'Auto (let model decide)' },
118
- { choice: 'required', desc: 'Required (force tool use)' },
119
- { choice: { type: 'function', function: { name: 'calculate' } }, desc: 'Specific tool' }
120
- ];
121
-
122
- for (const testCase of testCases) {
123
- console.log(`Testing tool_choice: ${testCase.desc}`);
124
- try {
125
- const response = await model.chat([
126
- { role: 'user', content: 'What is 50 + 50?' }
127
- ], {}, {
128
- tool_choice: testCase.choice as any,
129
- executeTools: false
130
- });
131
-
132
- console.log(` Content: ${response.message?.content?.substring(0, 100) || 'No content'}${(response.message?.content?.length || 0) > 100 ? '...' : ''}`);
133
- console.log(` Tool calls: ${response.message?.tool_calls?.length || 0}`);
134
-
135
- } catch (error) {
136
- console.log(` Error: ${(error as Error).message}`);
137
- }
138
- console.log('');
139
- }
140
-
141
- } catch (error) {
142
- console.error('โŒ Test failed:', (error as Error).message);
143
- console.error('Stack:', (error as Error).stack);
144
- } finally {
145
- model.dispose();
146
- console.log('๐Ÿ Test completed!\n');
147
- }
148
- }
149
-
150
- // Run the test
151
- if (require.main === module) {
152
- testLMStudioTools().catch(console.error);
153
- }
154
-
155
- export { testLMStudioTools };
@@ -1,47 +0,0 @@
1
- # Universal LLM Client Demos
2
-
3
- This directory contains various demonstration files for the Universal LLM Client.
4
-
5
- ## Directory Structure
6
-
7
- ### `/basic`
8
-
9
- Basic usage examples and simple demonstrations.
10
-
11
- ### `/tools`
12
-
13
- Tool calling demonstrations and examples:
14
-
15
- - `demo-tool-calling.ts` - Basic tool calling demo
16
- - `complete-tool-demo.ts` - Comprehensive tool calling examples
17
- - `production-tool-demo.ts` - Production-ready tool calling implementation
18
-
19
- ### `/mcp`
20
-
21
- Model Context Protocol (MCP) integration demos:
22
-
23
- - `simple-mcp-demo.ts` - Clean MCP MongoDB demo (recommended)
24
- - `mcp-mongodb-demo.ts` - Detailed MCP MongoDB integration
25
- - `working-mcp-demo.ts` - Working MCP implementation example
26
-
27
- ## Running Demos
28
-
29
- From the root directory (`universal-llm-client/`):
30
-
31
- ```bash
32
- # Tool calling demos
33
- bun run demos/tools/production-tool-demo.ts
34
-
35
- # MCP demos (requires MongoDB MCP server)
36
- bun run demos/mcp/simple-mcp-demo.ts
37
-
38
- # Basic usage
39
- bun run demos/basic/[demo-file].ts
40
- ```
41
-
42
- ## Requirements
43
-
44
- - Node.js/Bun runtime
45
- - Configured Ollama instance (for Ollama provider)
46
- - MongoDB MCP server (for MCP demos)
47
- - API keys for external providers (OpenAI, Google)
@@ -1,161 +0,0 @@
1
- import { AIModelFactory } from "./factory";
2
-
3
- /**
4
- * Example: Complete AI Application Setup
5
- *
6
- * This example shows how to set up a complete AI application
7
- * with both chat and embedding capabilities using the factory.
8
- */
9
- export async function createAIApplicationExample() {
10
-
11
- console.log('\n๐Ÿ—๏ธ Example: Setting up a complete AI application...\n');
12
-
13
- // Method 1: Using the factory for easy setup
14
- const aiSetup = AIModelFactory.createCompleteSetup({
15
- ollama: {
16
- chatModel: 'gemma3:4b-it-qat',
17
- embeddingModel: 'snowflake-arctic-embed2:latest',
18
- url: 'http://localhost:11434'
19
- },
20
- openai: {
21
- chatModel: 'google/gemma-3-4b',
22
- embeddingModel: 'text-embedding-snowflake-arctic-embed-l-v2.0',
23
- url: 'http://localhost:1234/v1'
24
- // apiKey: 'your-api-key-here' // For real OpenAI API
25
- },
26
- google: {
27
- chatModel: 'gemma-3-4b-it',
28
- apiKey: 'AIzaSyBDbo7iVNEuCcRNTgDIgRrkGpFKisXXnm0'
29
- }
30
- });
31
-
32
- // Method 2: Individual setup for specific use cases
33
- const chatModel = AIModelFactory.createOllamaChatModel('gemma3:4b-it-qat');
34
- const embeddingModel = AIModelFactory.createOllamaEmbeddingModel('snowflake-arctic-embed2:latest');
35
-
36
- // Method 3: Google-specific setup
37
- const googleChatModel = AIModelFactory.createGoogleChatModel(
38
- 'gemma-3-4b-it',
39
- 'AIzaSyBDbo7iVNEuCcRNTgDIgRrkGpFKisXXnm0'
40
- );
41
-
42
- // Example usage patterns:
43
-
44
- console.log('๐Ÿค– Testing Google Generative AI...');
45
- try {
46
- const googleResponse = await googleChatModel.chat([
47
- { role: 'user', content: 'What is the capital of France?' }
48
- ]);
49
- console.log('Google Response:', googleResponse.content);
50
- } catch (error) {
51
- console.error('Google API Error:', error);
52
- }
53
-
54
- console.log('\n๐ŸŒŠ Testing Google Streaming...');
55
- try {
56
- const streamingGenerator = googleChatModel.chatStream([
57
- { role: 'user', content: 'Count from 1 to 5, explaining each number briefly.' }
58
- ]);
59
-
60
- for await (const chunk of streamingGenerator) {
61
- process.stdout.write(chunk);
62
- }
63
- console.log('\nโœ… Google streaming completed');
64
- } catch (error) {
65
- console.error('Google Streaming Error:', error);
66
- }
67
-
68
- // 1. Simple chat
69
- const chatResponse = await aiSetup.ollama.chat.chat([
70
- { role: 'user', content: 'What is machine learning?' }
71
- ]);
72
-
73
- // 2. Document embedding for search
74
- const documents = [
75
- 'Machine learning is a subset of AI',
76
- 'Neural networks are inspired by the brain',
77
- 'TypeScript is a typed superset of JavaScript'
78
- ];
79
-
80
- const embeddings = await Promise.all(
81
- documents.map(doc => aiSetup.ollama.embedding.embed(doc))
82
- );
83
-
84
- // 3. Cross-provider comparison including Google
85
- const comparisons = await Promise.all([
86
- aiSetup.ollama?.chat?.chat([{ role: 'user', content: 'What is the capital of France?' }]).catch(() => null),
87
- aiSetup.openai?.chat?.chat([{ role: 'user', content: 'What is the capital of France?' }]).catch(() => null),
88
- aiSetup.google?.chat?.chat([{ role: 'user', content: 'What is the capital of France?' }]).catch(() => null)
89
- ]);
90
-
91
- return {
92
- aiSetup,
93
- chatModel,
94
- embeddingModel,
95
- googleChatModel,
96
- examples: {
97
- chatResponse,
98
- embeddings,
99
- comparisons: {
100
- ollama: comparisons[0],
101
- openai: comparisons[1],
102
- google: comparisons[2]
103
- }
104
- }
105
- };
106
- }
107
-
108
- /**
109
- * Test Google API specifically
110
- */
111
- export async function testGoogleAPI() {
112
- console.log('๐Ÿงช Testing Google Generative AI API...\n');
113
-
114
- const googleModel = AIModelFactory.createGoogleChatModel(
115
- 'gemma-3-4b-it',
116
- 'AIzaSyBDbo7iVNEuCcRNTgDIgRrkGpFKisXXnm0'
117
- );
118
-
119
- try {
120
- // Test basic chat
121
- console.log('๐Ÿ’ฌ Basic chat test...');
122
- const response = await googleModel.chat([
123
- { role: 'user', content: 'Hello! Can you tell me about TypeScript?' }
124
- ]);
125
- console.log('Response:', response.content);
126
-
127
- // Test streaming
128
- console.log('\n๐ŸŒŠ Streaming test...');
129
- const streamResponse = googleModel.chatStream([
130
- { role: 'user', content: 'Tell me a short story about a robot learning to code.' }
131
- ]);
132
-
133
- let fullResponse = '';
134
- for await (const chunk of streamResponse) {
135
- process.stdout.write(chunk);
136
- fullResponse += chunk;
137
- }
138
- console.log('\nโœ… Streaming completed');
139
-
140
- // Test conversation with context
141
- console.log('\n๐Ÿ’ญ Conversation with context...');
142
- const conversationResponse = await googleModel.chat([
143
- { role: 'user', content: 'What is the capital of France?' },
144
- { role: 'assistant', content: 'The capital of France is Paris.' },
145
- { role: 'user', content: 'What is its population?' }
146
- ]);
147
- console.log('Conversation Response:', conversationResponse.content);
148
-
149
- console.log('\nโœ… All Google API tests completed successfully!');
150
- return { success: true, model: googleModel };
151
-
152
- } catch (error) {
153
- console.error('โŒ Google API test failed:', error);
154
- return { success: false, error };
155
- }
156
- }
157
-
158
- // Uncomment to run the examples
159
- // testGoogleAPI().then(result => {
160
- // console.log('Google API test complete:', result.success);
161
- // });