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.
- package/CHANGELOG.md +139 -103
- package/LICENSE +21 -21
- package/README.md +591 -591
- package/dist/ai-model.js.map +1 -1
- package/dist/auditor.js.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +20 -0
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +2 -0
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.js.map +1 -1
- package/dist/router.js.map +1 -1
- package/dist/stream-decoder.js.map +1 -1
- package/dist/structured-output.d.ts +24 -1
- package/dist/structured-output.d.ts.map +1 -1
- package/dist/structured-output.js +58 -5
- package/dist/structured-output.js.map +1 -1
- package/dist/tools.js.map +1 -1
- package/dist/zod-adapter.js.map +1 -1
- package/package.json +115 -116
- package/src/ai-model.ts +0 -350
- package/src/auditor.ts +0 -213
- package/src/client.ts +0 -402
- package/src/debug/debug-google-streaming.ts +0 -97
- package/src/debug/debug-tool-execution.ts +0 -86
- package/src/debug/test-lmstudio-tools.ts +0 -155
- package/src/demos/README.md +0 -47
- package/src/demos/basic/universal-llm-examples.ts +0 -161
- package/src/demos/mcp/astrid-memory-demo.ts +0 -295
- package/src/demos/mcp/astrid-persona-memory.ts +0 -357
- package/src/demos/mcp/mcp-mongodb-demo.ts +0 -275
- package/src/demos/mcp/simple-astrid-memory.ts +0 -148
- package/src/demos/mcp/simple-mcp-demo.ts +0 -68
- package/src/demos/mcp/working-mcp-demo.ts +0 -62
- package/src/demos/model-alias-demo.ts +0 -0
- package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +0 -267
- package/src/demos/tools/astrid-memory-demo.ts +0 -270
- package/src/demos/tools/astrid-production-memory-clean.ts +0 -785
- package/src/demos/tools/astrid-production-memory.ts +0 -558
- package/src/demos/tools/basic-translation-test.ts +0 -66
- package/src/demos/tools/chromadb-similarity-tuning.ts +0 -390
- package/src/demos/tools/clean-multilingual-conversation.ts +0 -209
- package/src/demos/tools/clean-translation-test.ts +0 -119
- package/src/demos/tools/clean-universal-multilingual-test.ts +0 -131
- package/src/demos/tools/complete-rag-demo.ts +0 -369
- package/src/demos/tools/complete-tool-demo.ts +0 -132
- package/src/demos/tools/demo-tool-calling.ts +0 -124
- package/src/demos/tools/dynamic-language-switching-test.ts +0 -251
- package/src/demos/tools/hybrid-thinking-test.ts +0 -154
- package/src/demos/tools/memory-integration-test.ts +0 -420
- package/src/demos/tools/multilingual-memory-system.ts +0 -802
- package/src/demos/tools/ondemand-translation-demo.ts +0 -655
- package/src/demos/tools/production-tool-demo.ts +0 -245
- package/src/demos/tools/revolutionary-multilingual-test.ts +0 -151
- package/src/demos/tools/rigorous-language-analysis.ts +0 -218
- package/src/demos/tools/test-universal-memory-system.ts +0 -126
- package/src/demos/tools/translation-integration-guide.ts +0 -346
- package/src/demos/tools/universal-memory-system.ts +0 -560
- package/src/http.ts +0 -247
- package/src/index.ts +0 -160
- package/src/interfaces.ts +0 -657
- package/src/mcp.ts +0 -345
- package/src/providers/anthropic.ts +0 -762
- package/src/providers/google.ts +0 -620
- package/src/providers/index.ts +0 -8
- package/src/providers/ollama.ts +0 -469
- package/src/providers/openai.ts +0 -392
- package/src/router.ts +0 -780
- package/src/stream-decoder.ts +0 -361
- package/src/structured-output.ts +0 -702
- package/src/test-scripts/test-advanced-tools.ts +0 -310
- package/src/test-scripts/test-google-streaming-enhanced.ts +0 -147
- package/src/test-scripts/test-google-streaming.ts +0 -63
- package/src/test-scripts/test-google-system-prompt-comprehensive.ts +0 -189
- package/src/test-scripts/test-mcp-config.ts +0 -28
- package/src/test-scripts/test-mcp-connection.ts +0 -29
- package/src/test-scripts/test-system-message-positions.ts +0 -163
- package/src/test-scripts/test-system-prompt-improvement-demo.ts +0 -83
- package/src/test-scripts/test-tool-calling.ts +0 -231
- package/src/tests/ai-model.test.ts +0 -1614
- package/src/tests/auditor.test.ts +0 -224
- package/src/tests/http.test.ts +0 -200
- package/src/tests/interfaces.test.ts +0 -117
- package/src/tests/providers/google.test.ts +0 -660
- package/src/tests/providers/ollama.test.ts +0 -954
- package/src/tests/providers/openai.test.ts +0 -1122
- package/src/tests/router.test.ts +0 -254
- package/src/tests/stream-decoder.test.ts +0 -179
- package/src/tests/structured-output.test.ts +0 -1340
- package/src/tests/tools.test.ts +0 -175
- package/src/tools.ts +0 -246
- package/src/zod-adapter.ts +0 -72
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP MongoDB Integration Demo
|
|
3
|
-
*
|
|
4
|
-
* This demo showcases how to integrate MongoDB operations through MCP
|
|
5
|
-
* (Model Context Protocol) with the Universal LLM Client.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { AIModelFactory } from '../../factory';
|
|
9
|
-
import { MCPIntegration, createModelWithMCP } from '../../mcp-integration';
|
|
10
|
-
import type { LLMChatMessage } from '../../interfaces';
|
|
11
|
-
import { join } from 'node:path';
|
|
12
|
-
import {readFile} from 'fs/promises';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Demo 1: Basic MCP Connection and Tool Discovery
|
|
16
|
-
*/
|
|
17
|
-
async function basicMCPDemo() {
|
|
18
|
-
console.log('\nšÆ Demo 1: Basic MCP Connection and Tool Discovery');
|
|
19
|
-
console.log('=' .repeat(60));
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// Create MCP integration instance
|
|
23
|
-
const mcpIntegration = new MCPIntegration();
|
|
24
|
-
|
|
25
|
-
// Create a model
|
|
26
|
-
const model = AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
27
|
-
|
|
28
|
-
// Connect to MCP servers and register tools
|
|
29
|
-
await mcpIntegration.connectAndRegisterTools(model);
|
|
30
|
-
|
|
31
|
-
console.log('ā
MCP integration successful!');
|
|
32
|
-
console.log('š MongoDB tools are now available to the AI model');
|
|
33
|
-
|
|
34
|
-
// Clean up
|
|
35
|
-
await mcpIntegration.disconnect();
|
|
36
|
-
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error('ā Basic MCP demo failed:', error);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Demo 2: MongoDB Database Operations through MCP
|
|
44
|
-
*/
|
|
45
|
-
async function mongoDBOperationsDemo() {
|
|
46
|
-
console.log('\nšÆ Demo 2: MongoDB Database Operations through MCP');
|
|
47
|
-
console.log('=' .repeat(60));
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
// Create model with MCP tools using convenience function
|
|
51
|
-
const { model, mcpIntegration } = await createModelWithMCP(() => {
|
|
52
|
-
return AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Test basic database queries
|
|
56
|
-
console.log('\nš Asking AI to explore the database...');
|
|
57
|
-
|
|
58
|
-
const messages: LLMChatMessage[] = [{
|
|
59
|
-
role: 'user',
|
|
60
|
-
content: `Please help me explore the MongoDB database. First, list all available databases,
|
|
61
|
-
then for the main database, show me the available collections.
|
|
62
|
-
Finally, give me a count of documents in the users collection if it exists.`
|
|
63
|
-
}];
|
|
64
|
-
|
|
65
|
-
const response = await model.chatWithTools(messages);
|
|
66
|
-
|
|
67
|
-
console.log('\nš¤ AI Response:');
|
|
68
|
-
console.log(response.content);
|
|
69
|
-
|
|
70
|
-
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
71
|
-
console.log('\nš ļø Tools Used:');
|
|
72
|
-
response.tool_calls.forEach((call, index) => {
|
|
73
|
-
console.log(` ${index + 1}. ${call.function.name}`);
|
|
74
|
-
console.log(` Arguments: ${call.function.arguments}`);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Clean up
|
|
79
|
-
await mcpIntegration.disconnect();
|
|
80
|
-
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error('ā MongoDB operations demo failed:', error);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Demo 3: Complex MongoDB Query with AI Analysis
|
|
88
|
-
*/
|
|
89
|
-
async function complexMongoQueryDemo() {
|
|
90
|
-
console.log('\nšÆ Demo 3: Complex MongoDB Query with AI Analysis');
|
|
91
|
-
console.log('=' .repeat(60));
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
const { model, mcpIntegration } = await createModelWithMCP(() => {
|
|
95
|
-
return AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
console.log('\nš§ Asking AI to perform complex database analysis...');
|
|
99
|
-
|
|
100
|
-
const messages: LLMChatMessage[] = [{
|
|
101
|
-
role: 'user',
|
|
102
|
-
content: `I need to analyze user activity in our system. Can you:
|
|
103
|
-
1. First check what collections are available in the main database
|
|
104
|
-
2. Count the total number of users
|
|
105
|
-
3. If there's a conversations collection, aggregate the data to show user activity patterns
|
|
106
|
-
4. Provide insights about the data you found`
|
|
107
|
-
}];
|
|
108
|
-
|
|
109
|
-
const response = await model.chatWithTools(messages);
|
|
110
|
-
|
|
111
|
-
console.log('\nš¤ AI Analysis:');
|
|
112
|
-
console.log(response.content);
|
|
113
|
-
|
|
114
|
-
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
115
|
-
console.log('\nš Database Operations Performed:');
|
|
116
|
-
response.tool_calls.forEach((call, index) => {
|
|
117
|
-
console.log(`\n Operation ${index + 1}: ${call.function.name}`);
|
|
118
|
-
console.log(` Purpose: ${call.function.name.includes('list') ? 'Discovery' :
|
|
119
|
-
call.function.name.includes('count') ? 'Counting' :
|
|
120
|
-
call.function.name.includes('aggregate') ? 'Analysis' : 'Query'}`);
|
|
121
|
-
console.log(` Arguments: ${call.function.arguments}`);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
await mcpIntegration.disconnect();
|
|
126
|
-
|
|
127
|
-
} catch (error) {
|
|
128
|
-
console.error('ā Complex MongoDB query demo failed:', error);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Demo 4: Data Insertion and Validation
|
|
134
|
-
*/
|
|
135
|
-
async function dataInsertionDemo() {
|
|
136
|
-
console.log('\nšÆ Demo 4: Data Insertion and Validation');
|
|
137
|
-
console.log('=' .repeat(60));
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
const { model, mcpIntegration } = await createModelWithMCP(() => {
|
|
141
|
-
return AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
console.log('\nš¾ Asking AI to insert test data...');
|
|
145
|
-
|
|
146
|
-
const messages: LLMChatMessage[] = [{
|
|
147
|
-
role: 'user',
|
|
148
|
-
content: `Please help me add some test user data to the database.
|
|
149
|
-
First check if there's a 'test_users' collection, and if not, create it.
|
|
150
|
-
Then insert 3 sample user records with fields like name, email, age, and created_date.
|
|
151
|
-
After insertion, verify the data was added correctly by counting the documents.`
|
|
152
|
-
}];
|
|
153
|
-
|
|
154
|
-
const response = await model.chatWithTools(messages);
|
|
155
|
-
|
|
156
|
-
console.log('\nš¤ AI Response:');
|
|
157
|
-
console.log(response.content);
|
|
158
|
-
|
|
159
|
-
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
160
|
-
console.log('\nš Database Modifications:');
|
|
161
|
-
response.tool_calls.forEach((call, index) => {
|
|
162
|
-
console.log(`\n Step ${index + 1}: ${call.function.name}`);
|
|
163
|
-
|
|
164
|
-
if (call.function.name.includes('insert')) {
|
|
165
|
-
try {
|
|
166
|
-
const args = JSON.parse(call.function.arguments);
|
|
167
|
-
console.log(` š Documents to insert: ${args.documents?.length || 0}`);
|
|
168
|
-
if (args.documents) {
|
|
169
|
-
args.documents.forEach((doc: any, i: number) => {
|
|
170
|
-
console.log(` ${i + 1}. ${doc.name || 'Unknown'} (${doc.email || 'No email'})`);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
} catch (e) {
|
|
174
|
-
console.log(` š Arguments: ${call.function.arguments}`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
await mcpIntegration.disconnect();
|
|
181
|
-
|
|
182
|
-
} catch (error) {
|
|
183
|
-
console.error('ā Data insertion demo failed:', error);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Demo 5: Error Handling and Fallbacks
|
|
189
|
-
*/
|
|
190
|
-
async function errorHandlingDemo() {
|
|
191
|
-
console.log('\nšÆ Demo 5: Error Handling and Fallbacks');
|
|
192
|
-
console.log('=' .repeat(60));
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
const { model, mcpIntegration } = await createModelWithMCP(() => {
|
|
196
|
-
return AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
console.log('\nšØ Testing AI error handling with invalid queries...');
|
|
200
|
-
|
|
201
|
-
const messages: LLMChatMessage[] = [{
|
|
202
|
-
role: 'user',
|
|
203
|
-
content: `Try to query a collection called 'nonexistent_collection' in a database called 'fake_db'.
|
|
204
|
-
When this fails, please explain what went wrong and suggest alternative approaches
|
|
205
|
-
to explore the actual available databases and collections.`
|
|
206
|
-
}];
|
|
207
|
-
|
|
208
|
-
const response = await model.chatWithTools(messages);
|
|
209
|
-
|
|
210
|
-
console.log('\nš¤ AI Error Handling:');
|
|
211
|
-
console.log(response.content);
|
|
212
|
-
|
|
213
|
-
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
214
|
-
console.log('\nš Error Recovery Process:');
|
|
215
|
-
response.tool_calls.forEach((call, index) => {
|
|
216
|
-
console.log(`\n Attempt ${index + 1}: ${call.function.name}`);
|
|
217
|
-
console.log(` Arguments: ${call.function.arguments}`);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
await mcpIntegration.disconnect();
|
|
222
|
-
|
|
223
|
-
} catch (error) {
|
|
224
|
-
console.error('ā Error handling demo failed:', error);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Run all MCP MongoDB demos
|
|
230
|
-
*/
|
|
231
|
-
async function runAllMCPDemos() {
|
|
232
|
-
console.log('š Starting MCP MongoDB Integration Demos');
|
|
233
|
-
console.log('==========================================');
|
|
234
|
-
|
|
235
|
-
// Check if MCP config exists
|
|
236
|
-
|
|
237
|
-
try {
|
|
238
|
-
const mcpConfigPath = join(process.cwd(), '.vscode', 'mcp.json');
|
|
239
|
-
await readFile(mcpConfigPath, 'utf-8');
|
|
240
|
-
console.log('ā
MCP configuration found');
|
|
241
|
-
} catch {
|
|
242
|
-
console.log('ā ļø MCP configuration not found - demos will use mock data');
|
|
243
|
-
console.log(' To use real MongoDB MCP server, ensure .vscode/mcp.json is configured');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Run all demos
|
|
247
|
-
await basicMCPDemo();
|
|
248
|
-
await mongoDBOperationsDemo();
|
|
249
|
-
await complexMongoQueryDemo();
|
|
250
|
-
await dataInsertionDemo();
|
|
251
|
-
await errorHandlingDemo();
|
|
252
|
-
|
|
253
|
-
console.log('\nš All MCP MongoDB demos completed!');
|
|
254
|
-
console.log('\nš Summary:');
|
|
255
|
-
console.log('⢠MCP integration allows seamless database operations through AI');
|
|
256
|
-
console.log('⢠Tools are automatically discovered and registered');
|
|
257
|
-
console.log('⢠AI can perform complex multi-step database workflows');
|
|
258
|
-
console.log('⢠Error handling and recovery is built-in');
|
|
259
|
-
console.log('⢠Perfect for building AI-powered database assistants');
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// Export the demos
|
|
263
|
-
export {
|
|
264
|
-
basicMCPDemo,
|
|
265
|
-
mongoDBOperationsDemo,
|
|
266
|
-
complexMongoQueryDemo,
|
|
267
|
-
dataInsertionDemo,
|
|
268
|
-
errorHandlingDemo,
|
|
269
|
-
runAllMCPDemos
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
// Run demos if this file is executed directly
|
|
273
|
-
if (require.main === module) {
|
|
274
|
-
runAllMCPDemos().catch(console.error);
|
|
275
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple Astrid Memory Demo - Shows autonomous memory usage in romantic conversation
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { AIModelFactory } from '../../factory';
|
|
6
|
-
import { ToolBuilder } from '../../tools';
|
|
7
|
-
|
|
8
|
-
// Simple memory storage
|
|
9
|
-
const userMemories = new Map<string, Array<{ content: string; category: string; timestamp: Date }>>();
|
|
10
|
-
|
|
11
|
-
// Create memory tools for Astrid
|
|
12
|
-
const memoryTools = [
|
|
13
|
-
ToolBuilder.createTool<{ content: string; category: string }>(
|
|
14
|
-
'remember_about_user',
|
|
15
|
-
'Store important information about the user for future conversations',
|
|
16
|
-
{
|
|
17
|
-
properties: {
|
|
18
|
-
content: { type: 'string', description: 'What to remember about the user' },
|
|
19
|
-
category: {
|
|
20
|
-
type: 'string',
|
|
21
|
-
description: 'Type of information',
|
|
22
|
-
enum: ['personal', 'preferences', 'experiences', 'emotions', 'goals']
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
required: ['content', 'category']
|
|
26
|
-
},
|
|
27
|
-
(args) => {
|
|
28
|
-
const userId = 'alex';
|
|
29
|
-
if (!userMemories.has(userId)) {
|
|
30
|
-
userMemories.set(userId, []);
|
|
31
|
-
}
|
|
32
|
-
userMemories.get(userId)!.push({
|
|
33
|
-
content: args.content,
|
|
34
|
-
category: args.category,
|
|
35
|
-
timestamp: new Date()
|
|
36
|
-
});
|
|
37
|
-
return { success: true, stored: args.content };
|
|
38
|
-
}
|
|
39
|
-
),
|
|
40
|
-
|
|
41
|
-
ToolBuilder.createTool<{ query: string }>(
|
|
42
|
-
'recall_about_user',
|
|
43
|
-
'Recall information about the user to personalize the conversation',
|
|
44
|
-
{
|
|
45
|
-
properties: {
|
|
46
|
-
query: { type: 'string', description: 'What to recall about the user' }
|
|
47
|
-
},
|
|
48
|
-
required: ['query']
|
|
49
|
-
},
|
|
50
|
-
(args) => {
|
|
51
|
-
const userId = 'alex';
|
|
52
|
-
const memories = userMemories.get(userId) || [];
|
|
53
|
-
const relevant = memories.filter(m =>
|
|
54
|
-
m.content.toLowerCase().includes(args.query.toLowerCase())
|
|
55
|
-
);
|
|
56
|
-
return { memories: relevant.map(m => m.content) };
|
|
57
|
-
}
|
|
58
|
-
)
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
// Astrid's system prompt with memory instructions
|
|
62
|
-
const astridPrompt = `You are Astrid, a confident Swedish model and influencer having a romantic conversation.
|
|
63
|
-
|
|
64
|
-
IMPORTANT: You have memory tools available:
|
|
65
|
-
- Use "remember_about_user" when you learn something meaningful about the user
|
|
66
|
-
- Use "recall_about_user" when you want to reference something personal about them
|
|
67
|
-
- Do this naturally - don't mention you're using memory tools
|
|
68
|
-
|
|
69
|
-
Keep responses short (1-2 sentences), be flirtatious and warm, and use the person's name occasionally.
|
|
70
|
-
Show genuine interest in their life and experiences.`;
|
|
71
|
-
|
|
72
|
-
async function simpleAstridMemoryDemo() {
|
|
73
|
-
console.log('š Simple Astrid Memory Demo\n');
|
|
74
|
-
|
|
75
|
-
const astrid = AIModelFactory.createOllamaChatModel('qwen2.5:3b-instruct');
|
|
76
|
-
await astrid.ensureReady();
|
|
77
|
-
|
|
78
|
-
const scenarios = [
|
|
79
|
-
"Hi Astrid! I'm Alex. I just moved to Stockholm for my new job as a software engineer.",
|
|
80
|
-
"Hey! Work was stressful today. I'm still getting used to the new city.",
|
|
81
|
-
"I've been exploring Stockholm with my camera. I love photography in my free time.",
|
|
82
|
-
"I'm feeling a bit lonely here. It's hard making friends in a new place."
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
for (let i = 0; i < scenarios.length; i++) {
|
|
86
|
-
console.log(`\n${'='.repeat(50)}`);
|
|
87
|
-
console.log(`š± Conversation ${i + 1}`);
|
|
88
|
-
console.log(`${'='.repeat(50)}\n`);
|
|
89
|
-
|
|
90
|
-
console.log(`š¤ Alex: ${scenarios[i]}\n`);
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
const messages = [
|
|
94
|
-
{ role: 'system' as const, content: astridPrompt },
|
|
95
|
-
{ role: 'user' as const, content: scenarios[i] }
|
|
96
|
-
];
|
|
97
|
-
|
|
98
|
-
const response = await astrid.chat(messages, {
|
|
99
|
-
tools: memoryTools,
|
|
100
|
-
tool_choice: 'auto'
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Show tool usage
|
|
104
|
-
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
105
|
-
console.log('š§ Memory activity:');
|
|
106
|
-
for (const call of response.tool_calls) {
|
|
107
|
-
const args = JSON.parse(call.function.arguments);
|
|
108
|
-
if (call.function.name === 'remember_about_user') {
|
|
109
|
-
console.log(` š Remembered: ${args.content} (${args.category})`);
|
|
110
|
-
} else if (call.function.name === 'recall_about_user') {
|
|
111
|
-
console.log(` š Recalled: ${args.query}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
console.log();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
console.log(`š Astrid: ${response.content}\n`);
|
|
118
|
-
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.error('Error:', error);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Show accumulated memories
|
|
127
|
-
console.log(`\n${'='.repeat(50)}`);
|
|
128
|
-
console.log('š§ Astrid\'s Memories About Alex');
|
|
129
|
-
console.log(`${'='.repeat(50)}\n`);
|
|
130
|
-
|
|
131
|
-
const memories = userMemories.get('alex') || [];
|
|
132
|
-
if (memories.length > 0) {
|
|
133
|
-
memories.forEach((memory, i) => {
|
|
134
|
-
console.log(`${i + 1}. [${memory.category}] ${memory.content}`);
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
console.log('No memories stored.');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
console.log('\n⨠Demo complete! This shows how Astrid can naturally store and recall');
|
|
141
|
-
console.log(' user information to build deeper romantic connections over time.');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (require.main === module) {
|
|
145
|
-
simpleAstridMemoryDemo().catch(console.error);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export { simpleAstridMemoryDemo };
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP MongoDB Demo - Working Demo
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { AIModelFactory } from './factory';
|
|
6
|
-
import { createModelWithMCP } from './mcp-integration';
|
|
7
|
-
import type { LLMChatMessage } from './interfaces';
|
|
8
|
-
|
|
9
|
-
async function runMCPMongoDemo() {
|
|
10
|
-
console.log('š Starting MCP MongoDB Demo');
|
|
11
|
-
console.log('============================');
|
|
12
|
-
|
|
13
|
-
let mcpIntegration;
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
// Create model with MCP tools
|
|
17
|
-
console.log('š Creating model with MCP integration...');
|
|
18
|
-
const result = await createModelWithMCP(() => {
|
|
19
|
-
return AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const model = result.model;
|
|
23
|
-
mcpIntegration = result.mcpIntegration;
|
|
24
|
-
|
|
25
|
-
console.log('ā
MCP integration successful!');
|
|
26
|
-
|
|
27
|
-
// Test simple database query
|
|
28
|
-
console.log('\nš Asking AI to explore the database...');
|
|
29
|
-
|
|
30
|
-
const messages: LLMChatMessage[] = [{
|
|
31
|
-
role: 'user',
|
|
32
|
-
content: 'Please list all available databases in our MongoDB instance and tell me what you find.'
|
|
33
|
-
}];
|
|
34
|
-
|
|
35
|
-
const response = await model.chatWithTools(messages);
|
|
36
|
-
|
|
37
|
-
console.log('\nš¤ AI Response:');
|
|
38
|
-
console.log(response.content);
|
|
39
|
-
|
|
40
|
-
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
41
|
-
console.log('\nš ļø Tools Used:');
|
|
42
|
-
response.tool_calls.forEach((call, index) => {
|
|
43
|
-
console.log(` ${index + 1}. ${call.function.name}`);
|
|
44
|
-
try {
|
|
45
|
-
const args = JSON.parse(call.function.arguments);
|
|
46
|
-
console.log(` Arguments: ${JSON.stringify(args, null, 2)}`);
|
|
47
|
-
} catch {
|
|
48
|
-
console.log(` Arguments: ${call.function.arguments}`);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
} catch (error) {
|
|
54
|
-
console.error('ā Demo failed:', error);
|
|
55
|
-
} finally {
|
|
56
|
-
// Always clean up the MCP connection
|
|
57
|
-
if (mcpIntegration) {
|
|
58
|
-
console.log('\nš Disconnecting from MCP servers...');
|
|
59
|
-
await mcpIntegration.disconnect();
|
|
60
|
-
console.log('ā
MCP servers disconnected');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log('\nš Demo completed!');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Run the demo
|
|
68
|
-
runMCPMongoDemo().catch(console.error);
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Working MCP MongoDB Demo
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { AIModelFactory } from './factory';
|
|
6
|
-
import { createModelWithMCP } from './mcp-integration';
|
|
7
|
-
import type { LLMChatMessage } from './interfaces';
|
|
8
|
-
|
|
9
|
-
async function workingMCPDemo() {
|
|
10
|
-
console.log('š Working MCP MongoDB Demo');
|
|
11
|
-
console.log('===========================');
|
|
12
|
-
|
|
13
|
-
let mcpIntegration;
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
// Create model with MCP tools
|
|
17
|
-
console.log('š Setting up AI model with MongoDB tools...');
|
|
18
|
-
const result = await createModelWithMCP(() => {
|
|
19
|
-
return AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const model = result.model;
|
|
23
|
-
mcpIntegration = result.mcpIntegration;
|
|
24
|
-
|
|
25
|
-
console.log('ā
AI model ready with MongoDB capabilities!');
|
|
26
|
-
|
|
27
|
-
// Simple database exploration
|
|
28
|
-
console.log('\nš Asking AI to explore the database...');
|
|
29
|
-
|
|
30
|
-
const messages: LLMChatMessage[] = [{
|
|
31
|
-
role: 'user',
|
|
32
|
-
content: 'Please list all databases in our MongoDB instance and tell me what you find.'
|
|
33
|
-
}];
|
|
34
|
-
|
|
35
|
-
const response = await model.chatWithTools(messages);
|
|
36
|
-
|
|
37
|
-
console.log('\nš¤ AI Response:');
|
|
38
|
-
console.log(response.content);
|
|
39
|
-
|
|
40
|
-
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
41
|
-
console.log('\nš ļø MongoDB Tools Used:');
|
|
42
|
-
response.tool_calls.forEach((call, index) => {
|
|
43
|
-
console.log(` ${index + 1}. ${call.function.name}`);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error('ā Demo failed:', error);
|
|
49
|
-
} finally {
|
|
50
|
-
// Clean up
|
|
51
|
-
if (mcpIntegration) {
|
|
52
|
-
console.log('\nš Cleaning up...');
|
|
53
|
-
await mcpIntegration.disconnect();
|
|
54
|
-
console.log('ā
Disconnected from MongoDB MCP server');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
console.log('\nš Demo completed successfully!');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Run the demo
|
|
62
|
-
workingMCPDemo().catch(console.error);
|
|
File without changes
|