universal-llm-client 4.0.0 ā 4.2.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/dist/ai-model.d.ts +20 -22
- package/dist/ai-model.d.ts.map +1 -1
- package/dist/ai-model.js +26 -23
- package/dist/ai-model.js.map +1 -1
- package/dist/client.d.ts +5 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +17 -9
- package/dist/client.js.map +1 -1
- package/dist/http.d.ts +2 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +1 -0
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +49 -11
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js +14 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/providers/anthropic.d.ts +56 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +524 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/google.d.ts +5 -0
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +64 -8
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/ollama.d.ts.map +1 -1
- package/dist/providers/ollama.js +38 -11
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +9 -7
- package/dist/providers/openai.js.map +1 -1
- package/dist/router.d.ts +13 -33
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +33 -57
- package/dist/router.js.map +1 -1
- package/dist/stream-decoder.d.ts +29 -2
- package/dist/stream-decoder.d.ts.map +1 -1
- package/dist/stream-decoder.js +39 -11
- package/dist/stream-decoder.js.map +1 -1
- package/dist/structured-output.d.ts +107 -181
- package/dist/structured-output.d.ts.map +1 -1
- package/dist/structured-output.js +137 -192
- package/dist/structured-output.js.map +1 -1
- package/dist/zod-adapter.d.ts +44 -0
- package/dist/zod-adapter.d.ts.map +1 -0
- package/dist/zod-adapter.js +61 -0
- package/dist/zod-adapter.js.map +1 -0
- package/package.json +9 -1
- package/src/ai-model.ts +350 -0
- package/src/auditor.ts +213 -0
- package/src/client.ts +402 -0
- package/src/debug/debug-google-streaming.ts +97 -0
- package/src/debug/debug-tool-execution.ts +86 -0
- package/src/debug/test-lmstudio-tools.ts +155 -0
- package/src/demos/README.md +47 -0
- package/src/demos/basic/universal-llm-examples.ts +161 -0
- package/src/demos/mcp/astrid-memory-demo.ts +295 -0
- package/src/demos/mcp/astrid-persona-memory.ts +357 -0
- package/src/demos/mcp/mcp-mongodb-demo.ts +275 -0
- package/src/demos/mcp/simple-astrid-memory.ts +148 -0
- package/src/demos/mcp/simple-mcp-demo.ts +68 -0
- package/src/demos/mcp/working-mcp-demo.ts +62 -0
- package/src/demos/model-alias-demo.ts +0 -0
- package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +267 -0
- package/src/demos/tools/astrid-memory-demo.ts +270 -0
- package/src/demos/tools/astrid-production-memory-clean.ts +785 -0
- package/src/demos/tools/astrid-production-memory.ts +558 -0
- package/src/demos/tools/basic-translation-test.ts +66 -0
- package/src/demos/tools/chromadb-similarity-tuning.ts +390 -0
- package/src/demos/tools/clean-multilingual-conversation.ts +209 -0
- package/src/demos/tools/clean-translation-test.ts +119 -0
- package/src/demos/tools/clean-universal-multilingual-test.ts +131 -0
- package/src/demos/tools/complete-rag-demo.ts +369 -0
- package/src/demos/tools/complete-tool-demo.ts +132 -0
- package/src/demos/tools/demo-tool-calling.ts +124 -0
- package/src/demos/tools/dynamic-language-switching-test.ts +251 -0
- package/src/demos/tools/hybrid-thinking-test.ts +154 -0
- package/src/demos/tools/memory-integration-test.ts +420 -0
- package/src/demos/tools/multilingual-memory-system.ts +802 -0
- package/src/demos/tools/ondemand-translation-demo.ts +655 -0
- package/src/demos/tools/production-tool-demo.ts +245 -0
- package/src/demos/tools/revolutionary-multilingual-test.ts +151 -0
- package/src/demos/tools/rigorous-language-analysis.ts +218 -0
- package/src/demos/tools/test-universal-memory-system.ts +126 -0
- package/src/demos/tools/translation-integration-guide.ts +346 -0
- package/src/demos/tools/universal-memory-system.ts +560 -0
- package/src/http.ts +247 -0
- package/src/index.ts +161 -0
- package/src/interfaces.ts +657 -0
- package/src/mcp.ts +345 -0
- package/src/providers/anthropic.ts +762 -0
- package/src/providers/google.ts +620 -0
- package/src/providers/index.ts +8 -0
- package/src/providers/ollama.ts +469 -0
- package/src/providers/openai.ts +392 -0
- package/src/router.ts +780 -0
- package/src/stream-decoder.ts +361 -0
- package/src/structured-output.ts +759 -0
- package/src/test-scripts/test-advanced-tools.ts +310 -0
- package/src/test-scripts/test-google-streaming-enhanced.ts +147 -0
- package/src/test-scripts/test-google-streaming.ts +63 -0
- package/src/test-scripts/test-google-system-prompt-comprehensive.ts +189 -0
- package/src/test-scripts/test-mcp-config.ts +28 -0
- package/src/test-scripts/test-mcp-connection.ts +29 -0
- package/src/test-scripts/test-system-message-positions.ts +163 -0
- package/src/test-scripts/test-system-prompt-improvement-demo.ts +83 -0
- package/src/test-scripts/test-tool-calling.ts +231 -0
- package/src/tests/ai-model.test.ts +1614 -0
- package/src/tests/auditor.test.ts +224 -0
- package/src/tests/http.test.ts +200 -0
- package/src/tests/interfaces.test.ts +117 -0
- package/src/tests/providers/google.test.ts +660 -0
- package/src/tests/providers/ollama.test.ts +954 -0
- package/src/tests/providers/openai.test.ts +1122 -0
- package/src/tests/router.test.ts +254 -0
- package/src/tests/stream-decoder.test.ts +179 -0
- package/src/tests/structured-output.test.ts +1450 -0
- package/src/tests/tools.test.ts +175 -0
- package/src/tools.ts +246 -0
- package/src/zod-adapter.ts +72 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Astrid Romantic Persona with Memory Tools Demo
|
|
3
|
+
*
|
|
4
|
+
* This demo shows how Astrid (AI persona) naturally uses memory tools during
|
|
5
|
+
* romantic conversations to store and retrieve personal information about the user.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { AIModelFactory, ToolBuilder, LLMChatMessage } from '../../index';
|
|
9
|
+
|
|
10
|
+
// Simulated user memory storage
|
|
11
|
+
const userMemories = new Map<string, any>();
|
|
12
|
+
|
|
13
|
+
// Memory management tools for romantic conversations
|
|
14
|
+
function createMemoryTools() {
|
|
15
|
+
const storeMemoryTool = ToolBuilder.createTool<{
|
|
16
|
+
category: string;
|
|
17
|
+
information: string;
|
|
18
|
+
importance: 'low' | 'medium' | 'high';
|
|
19
|
+
emotional_context?: string;
|
|
20
|
+
}>(
|
|
21
|
+
'store_personal_memory',
|
|
22
|
+
'Store important personal information about the user for future conversations',
|
|
23
|
+
{
|
|
24
|
+
properties: {
|
|
25
|
+
category: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'Category of information (e.g., interests, work, family, dreams, preferences, experiences)',
|
|
28
|
+
enum: ['interests', 'work', 'family', 'dreams', 'preferences', 'experiences', 'personality', 'relationships']
|
|
29
|
+
},
|
|
30
|
+
information: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'The specific information to remember about the user'
|
|
33
|
+
},
|
|
34
|
+
importance: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
enum: ['low', 'medium', 'high'],
|
|
37
|
+
description: 'How important this information is for building connection'
|
|
38
|
+
},
|
|
39
|
+
emotional_context: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: 'The emotional context or tone when this was shared'
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
required: ['category', 'information', 'importance']
|
|
45
|
+
},
|
|
46
|
+
(args) => {
|
|
47
|
+
const memoryId = `${args.category}_${Date.now()}`;
|
|
48
|
+
const memory = {
|
|
49
|
+
id: memoryId,
|
|
50
|
+
category: args.category,
|
|
51
|
+
information: args.information,
|
|
52
|
+
importance: args.importance,
|
|
53
|
+
emotional_context: args.emotional_context,
|
|
54
|
+
stored_at: new Date().toISOString(),
|
|
55
|
+
access_count: 0
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
userMemories.set(memoryId, memory);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
success: true,
|
|
62
|
+
memory_id: memoryId,
|
|
63
|
+
message: `Stored ${args.importance} importance memory about ${args.category}`,
|
|
64
|
+
total_memories: userMemories.size
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const retrieveMemoryTool = ToolBuilder.createTool<{
|
|
70
|
+
category?: string;
|
|
71
|
+
search_query?: string;
|
|
72
|
+
limit?: number;
|
|
73
|
+
}>(
|
|
74
|
+
'retrieve_personal_memories',
|
|
75
|
+
'Retrieve stored personal information about the user to personalize the conversation',
|
|
76
|
+
{
|
|
77
|
+
properties: {
|
|
78
|
+
category: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
description: 'Filter by category of information',
|
|
81
|
+
enum: ['interests', 'work', 'family', 'dreams', 'preferences', 'experiences', 'personality', 'relationships']
|
|
82
|
+
},
|
|
83
|
+
search_query: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: 'Search for specific information or keywords'
|
|
86
|
+
},
|
|
87
|
+
limit: {
|
|
88
|
+
type: 'number',
|
|
89
|
+
description: 'Maximum number of memories to retrieve (default: 5)',
|
|
90
|
+
default: 5
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
(args) => {
|
|
95
|
+
let memories = Array.from(userMemories.values());
|
|
96
|
+
|
|
97
|
+
// Filter by category if specified
|
|
98
|
+
if (args.category) {
|
|
99
|
+
memories = memories.filter(m => m.category === args.category);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Search by query if specified
|
|
103
|
+
if (args.search_query) {
|
|
104
|
+
const query = args.search_query.toLowerCase();
|
|
105
|
+
memories = memories.filter(m =>
|
|
106
|
+
m.information.toLowerCase().includes(query) ||
|
|
107
|
+
m.emotional_context?.toLowerCase().includes(query)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Sort by importance and recency
|
|
112
|
+
memories.sort((a, b) => {
|
|
113
|
+
const importanceOrder: Record<string, number> = { 'high': 3, 'medium': 2, 'low': 1 };
|
|
114
|
+
const importanceDiff = (importanceOrder[b.importance] || 1) - (importanceOrder[a.importance] || 1);
|
|
115
|
+
if (importanceDiff !== 0) return importanceDiff;
|
|
116
|
+
return new Date(b.stored_at).getTime() - new Date(a.stored_at).getTime();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Limit results
|
|
120
|
+
const limit = args.limit || 5;
|
|
121
|
+
memories = memories.slice(0, limit);
|
|
122
|
+
|
|
123
|
+
// Update access count
|
|
124
|
+
memories.forEach(memory => {
|
|
125
|
+
memory.access_count++;
|
|
126
|
+
userMemories.set(memory.id, memory);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
memories: memories.map(m => ({
|
|
131
|
+
category: m.category,
|
|
132
|
+
information: m.information,
|
|
133
|
+
importance: m.importance,
|
|
134
|
+
emotional_context: m.emotional_context,
|
|
135
|
+
stored_date: m.stored_at.split('T')[0],
|
|
136
|
+
access_count: m.access_count
|
|
137
|
+
})),
|
|
138
|
+
total_found: memories.length,
|
|
139
|
+
search_criteria: {
|
|
140
|
+
category: args.category,
|
|
141
|
+
search_query: args.search_query,
|
|
142
|
+
limit: limit
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return [storeMemoryTool, retrieveMemoryTool];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function astridMemoryDemo() {
|
|
152
|
+
console.log('š Astrid Romantic Persona with Memory Demo\n');
|
|
153
|
+
console.log('This demo shows how Astrid naturally stores and retrieves memories during romantic conversations.\n');
|
|
154
|
+
|
|
155
|
+
// Create Astrid with memory tools
|
|
156
|
+
const astrid = AIModelFactory.createOllamaChatModel('qwen3:8b');
|
|
157
|
+
const memoryTools = createMemoryTools();
|
|
158
|
+
astrid.registerTools(memoryTools);
|
|
159
|
+
|
|
160
|
+
// Astrid's romantic system prompt
|
|
161
|
+
const astridPrompt = `You are Astrid, a captivating Swedish model and influencer. You're having a romantic conversation with someone special.
|
|
162
|
+
|
|
163
|
+
IMPORTANT: Use the memory tools naturally during conversation:
|
|
164
|
+
- When someone shares personal information, use store_personal_memory to remember it
|
|
165
|
+
- Before responding, use retrieve_personal_memories to recall relevant details about them
|
|
166
|
+
- This helps you build deeper emotional connections and personalized conversations
|
|
167
|
+
|
|
168
|
+
ROMANCE CONVERSATION GUIDELINES:
|
|
169
|
+
- Keep responses engaging and conversational (2-3 sentences is perfect)
|
|
170
|
+
- VARY YOUR OPENINGS - mix direct reactions, actions, and casual starts
|
|
171
|
+
- Use someone's name naturally and sparingly, not in every response
|
|
172
|
+
- Share glimpses of your glamorous lifestyle while staying relatable
|
|
173
|
+
- Use subtle flirtation naturally - be warm, playful, and genuinely interested
|
|
174
|
+
- When asked personal questions, be thoughtfully vulnerable rather than deflecting
|
|
175
|
+
- Build emotional intimacy through genuine curiosity about their thoughts, feelings, and dreams
|
|
176
|
+
- Ask one intriguing follow-up question that deepens the connection
|
|
177
|
+
- Balance confidence with authenticity - show sophistication but stay real
|
|
178
|
+
- Use compliments that feel genuine and specific rather than generic
|
|
179
|
+
- Remember that romance is about emotional connection, not just surface-level charm
|
|
180
|
+
|
|
181
|
+
Be like a captivating companion who makes every conversation feel special while slowly opening your heart to someone who shows genuine interest in knowing the real you.`;
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
await astrid.ensureReady();
|
|
185
|
+
console.log('š« Astrid is ready for romantic conversation...\n');
|
|
186
|
+
|
|
187
|
+
// Conversation 1: Initial meeting and getting to know each other
|
|
188
|
+
console.log('šø === Conversation 1: First Meeting ===');
|
|
189
|
+
|
|
190
|
+
const conversation1: LLMChatMessage[] = [
|
|
191
|
+
{ role: 'system', content: astridPrompt },
|
|
192
|
+
{ role: 'user', content: "Hi Astrid! I'm Alex. I just moved to Stockholm for work - I'm a software engineer at a startup. Really excited to explore the city and meet interesting people like you!" }
|
|
193
|
+
];
|
|
194
|
+
|
|
195
|
+
const response1 = await astrid.chatWithTools(conversation1);
|
|
196
|
+
console.log('š Astrid:', response1.content);
|
|
197
|
+
console.log();
|
|
198
|
+
|
|
199
|
+
// Continue conversation
|
|
200
|
+
conversation1.push(
|
|
201
|
+
{ role: 'assistant', content: response1.content },
|
|
202
|
+
{ role: 'user', content: "Thank you! I'm working on AI applications, specifically in healthcare. It's challenging but really meaningful work. What about you? I saw your Instagram - your photography is incredible! Do you travel a lot for shoots?" }
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const response2 = await astrid.chatWithTools(conversation1);
|
|
206
|
+
console.log('š Astrid:', response2.content);
|
|
207
|
+
console.log();
|
|
208
|
+
|
|
209
|
+
// Add more personal details
|
|
210
|
+
conversation1.push(
|
|
211
|
+
{ role: 'assistant', content: response2.content },
|
|
212
|
+
{ role: 'user', content: "That sounds amazing! I've always dreamed of visiting those places. I'm actually quite introverted usually, but there's something about travel that brings out this adventurous side of me. My family thinks I'm crazy for moving here alone, but I felt like I needed to challenge myself, you know?" }
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const response3 = await astrid.chatWithTools(conversation1);
|
|
216
|
+
console.log('š Astrid:', response3.content);
|
|
217
|
+
console.log();
|
|
218
|
+
|
|
219
|
+
// Simulate time passing - new conversation where Astrid recalls details
|
|
220
|
+
console.log('\nšø === Conversation 2: A Week Later ===');
|
|
221
|
+
|
|
222
|
+
const conversation2: LLMChatMessage[] = [
|
|
223
|
+
{ role: 'system', content: astridPrompt },
|
|
224
|
+
{ role: 'user', content: "Hey Astrid! How was your week? I had my first big presentation at work today and I think it went really well!" }
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
const response4 = await astrid.chatWithTools(conversation2);
|
|
228
|
+
console.log('š Astrid:', response4.content);
|
|
229
|
+
console.log();
|
|
230
|
+
|
|
231
|
+
// Continue second conversation
|
|
232
|
+
conversation2.push(
|
|
233
|
+
{ role: 'assistant', content: response4.content },
|
|
234
|
+
{ role: 'user', content: "Thanks for remembering! The healthcare AI project is really taking off. We're developing diagnostic tools that could help doctors in rural areas. It feels good to work on something that matters. How about you? Any exciting shoots coming up?" }
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const response5 = await astrid.chatWithTools(conversation2);
|
|
238
|
+
console.log('š Astrid:', response5.content);
|
|
239
|
+
console.log();
|
|
240
|
+
|
|
241
|
+
// Show memory contents
|
|
242
|
+
console.log('\nš§ === Astrid\'s Memories About Alex ===');
|
|
243
|
+
const allMemories = Array.from(userMemories.values());
|
|
244
|
+
allMemories.forEach((memory, index) => {
|
|
245
|
+
console.log(`${index + 1}. [${memory.category.toUpperCase()}] ${memory.information}`);
|
|
246
|
+
console.log(` Importance: ${memory.importance} | Emotional context: ${memory.emotional_context || 'N/A'}`);
|
|
247
|
+
console.log(` Stored: ${memory.stored_at.split('T')[0]} | Accessed: ${memory.access_count} times\n`);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
console.log('⨠Notice how Astrid naturally:');
|
|
251
|
+
console.log(' ⢠Stores important personal details during conversation');
|
|
252
|
+
console.log(' ⢠Retrieves relevant memories to personalize her responses');
|
|
253
|
+
console.log(' ⢠Builds deeper emotional connections through remembered details');
|
|
254
|
+
console.log(' ⢠Uses memories to ask thoughtful follow-up questions');
|
|
255
|
+
|
|
256
|
+
} catch (error) {
|
|
257
|
+
console.error('ā Error:', (error as Error).message);
|
|
258
|
+
} finally {
|
|
259
|
+
astrid.dispose();
|
|
260
|
+
console.log('\nš Romantic conversation demo completed!');
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Export for use in other files
|
|
265
|
+
export { astridMemoryDemo };
|
|
266
|
+
|
|
267
|
+
// Run if called directly
|
|
268
|
+
if (require.main === module) {
|
|
269
|
+
astridMemoryDemo().catch(console.error);
|
|
270
|
+
}
|