llmjs2 1.3.9 → 1.7.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.
- package/README.md +31 -476
- package/chain/AGENT_STEP_README.md +102 -0
- package/chain/README.md +257 -0
- package/chain/WORKFLOW_README.md +85 -0
- package/chain/agent-step-example.js +232 -0
- package/chain/docs/AGENT.md +126 -0
- package/chain/docs/GRAPH.md +490 -0
- package/chain/examples.js +314 -0
- package/chain/index.js +31 -0
- package/chain/lib/agent.js +338 -0
- package/chain/lib/flow/agent-step.js +119 -0
- package/chain/lib/flow/edge.js +24 -0
- package/chain/lib/flow/flow.js +76 -0
- package/chain/lib/flow/graph.js +331 -0
- package/chain/lib/flow/index.js +7 -0
- package/chain/lib/flow/step.js +63 -0
- package/chain/lib/memory/in-memory.js +117 -0
- package/chain/lib/memory/index.js +36 -0
- package/chain/lib/memory/lance-memory.js +225 -0
- package/chain/lib/memory/sqlite-memory.js +309 -0
- package/chain/simple-agent-step-example.js +168 -0
- package/chain/workflow-example-usage.js +70 -0
- package/chain/workflow-example.json +59 -0
- package/core/README.md +485 -0
- package/core/cli.js +275 -0
- package/core/docs/BASIC_USAGE.md +62 -0
- package/core/docs/CLI.md +104 -0
- package/{docs → core/docs}/GET_STARTED.md +129 -129
- package/{docs → core/docs}/GUARDRAILS_GUIDE.md +734 -734
- package/{docs → core/docs}/README.md +47 -47
- package/core/docs/ROUTER_GUIDE.md +199 -0
- package/{docs → core/docs}/SERVER_MODE.md +358 -350
- package/core/index.js +115 -0
- package/{providers → core/providers}/ollama.js +14 -6
- package/{providers → core/providers}/openai.js +14 -6
- package/core/providers/openrouter.js +206 -0
- package/core/router.js +252 -0
- package/{server.js → core/server.js} +15 -5
- package/package.json +46 -27
- package/cli.js +0 -195
- package/docs/BASIC_USAGE.md +0 -296
- package/docs/CLI.md +0 -455
- package/docs/ROUTER_GUIDE.md +0 -402
- package/index.js +0 -267
- package/providers/openrouter.js +0 -113
- package/router.js +0 -273
- package/test-completion.js +0 -99
- package/test.js +0 -246
- /package/{config.yaml → core/config.yaml} +0 -0
- /package/{logger.js → core/logger.js} +0 -0
package/test.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
// Import all modules
|
|
2
|
-
const { completion: llmCompletion, LLMJS2: LLMJS2Class, router, app } = require('./index');
|
|
3
|
-
|
|
4
|
-
// Basic validation tests
|
|
5
|
-
async function runTests() {
|
|
6
|
-
console.log('Running LLMJS2 comprehensive tests...\n');
|
|
7
|
-
|
|
8
|
-
let testCount = 0;
|
|
9
|
-
let passedCount = 0;
|
|
10
|
-
|
|
11
|
-
// Test 1: Input validation
|
|
12
|
-
testCount++;
|
|
13
|
-
try {
|
|
14
|
-
await llmCompletion('');
|
|
15
|
-
console.log('❌ Test 1 failed: Should reject empty prompt');
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.log('✅ Test 1 passed: Empty prompt rejected');
|
|
18
|
-
passedCount++;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Test 2: Invalid input type
|
|
22
|
-
testCount++;
|
|
23
|
-
try {
|
|
24
|
-
await llmCompletion(123);
|
|
25
|
-
console.log('❌ Test 2 failed: Should reject non-string/non-object input');
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.log('✅ Test 2 passed: Invalid input type rejected');
|
|
28
|
-
passedCount++;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Test 3: Invalid messages array
|
|
32
|
-
testCount++;
|
|
33
|
-
try {
|
|
34
|
-
await llmCompletion({ messages: [] });
|
|
35
|
-
console.log('❌ Test 3 failed: Should reject empty messages array');
|
|
36
|
-
} catch (error) {
|
|
37
|
-
console.log('✅ Test 3 passed: Empty messages array rejected');
|
|
38
|
-
passedCount++;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Test 4: Invalid message format
|
|
42
|
-
testCount++;
|
|
43
|
-
try {
|
|
44
|
-
await llmCompletion({ messages: [{ content: 'test' }] });
|
|
45
|
-
console.log('❌ Test 4 failed: Should reject message without role');
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.log('✅ Test 4 passed: Message without role rejected');
|
|
48
|
-
passedCount++;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Test 5: Invalid provider
|
|
52
|
-
testCount++;
|
|
53
|
-
try {
|
|
54
|
-
const llm = new LLMJS2();
|
|
55
|
-
llm.getProvider('unknown/test');
|
|
56
|
-
console.log('❌ Test 5 failed: Should reject unknown provider');
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.log('✅ Test 5 passed: Unknown provider rejected -', error.message);
|
|
59
|
-
passedCount++;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Test 6: LLMJS2 class instantiation
|
|
63
|
-
testCount++;
|
|
64
|
-
try {
|
|
65
|
-
const llm = new LLMJS2Class();
|
|
66
|
-
console.log('✅ Test 6 passed: LLMJS2 class instantiated successfully');
|
|
67
|
-
passedCount++;
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.log('❌ Test 6 failed:', error.message);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Test 7: Provider availability check (without API keys)
|
|
73
|
-
testCount++;
|
|
74
|
-
try {
|
|
75
|
-
// Temporarily clear API keys for this test
|
|
76
|
-
const originalKeys = {
|
|
77
|
-
openai: process.env.OPENAI_API_KEY,
|
|
78
|
-
ollama: process.env.OLLAMA_API_KEY,
|
|
79
|
-
openrouter: process.env.OPEN_ROUTER_API_KEY
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
delete process.env.OPENAI_API_KEY;
|
|
83
|
-
delete process.env.OLLAMA_API_KEY;
|
|
84
|
-
delete process.env.OPEN_ROUTER_API_KEY;
|
|
85
|
-
|
|
86
|
-
const llm = new LLMJS2Class();
|
|
87
|
-
const available = llm.getAvailableProviders();
|
|
88
|
-
|
|
89
|
-
// Restore original keys
|
|
90
|
-
process.env.OPENAI_API_KEY = originalKeys.openai;
|
|
91
|
-
process.env.OLLAMA_API_KEY = originalKeys.ollama;
|
|
92
|
-
process.env.OPEN_ROUTER_API_KEY = originalKeys.openrouter;
|
|
93
|
-
|
|
94
|
-
if (available.length === 0) {
|
|
95
|
-
console.log('✅ Test 7 passed: No providers available without API keys');
|
|
96
|
-
passedCount++;
|
|
97
|
-
} else {
|
|
98
|
-
console.log('❌ Test 7 failed: Should have no providers without API keys');
|
|
99
|
-
}
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.log('❌ Test 7 failed:', error.message);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Test 8: Model parsing
|
|
105
|
-
testCount++;
|
|
106
|
-
try {
|
|
107
|
-
const llm = new LLMJS2Class();
|
|
108
|
-
const { provider, model } = llm.parseModel('openai/gpt-3.5-turbo');
|
|
109
|
-
if (provider === 'openai' && model === 'gpt-3.5-turbo') {
|
|
110
|
-
console.log('✅ Test 8 passed: Model parsing works correctly');
|
|
111
|
-
passedCount++;
|
|
112
|
-
} else {
|
|
113
|
-
console.log('❌ Test 8 failed: Model parsing incorrect');
|
|
114
|
-
}
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.log('❌ Test 8 failed:', error.message);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Test 9: Router creation
|
|
120
|
-
testCount++;
|
|
121
|
-
try {
|
|
122
|
-
const modelList = [
|
|
123
|
-
{
|
|
124
|
-
model_name: 'test',
|
|
125
|
-
llm_params: {
|
|
126
|
-
model: 'ollama/test',
|
|
127
|
-
api_key: 'test-key'
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
];
|
|
131
|
-
const route = router(modelList, 'random');
|
|
132
|
-
console.log('✅ Test 9 passed: Router created successfully');
|
|
133
|
-
passedCount++;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
console.log('❌ Test 9 failed:', error.message);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Test 10: Router model selection
|
|
139
|
-
testCount++;
|
|
140
|
-
try {
|
|
141
|
-
const modelList = [
|
|
142
|
-
{
|
|
143
|
-
model_name: 'test',
|
|
144
|
-
llm_params: {
|
|
145
|
-
model: 'ollama/test',
|
|
146
|
-
api_key: 'test-key'
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
];
|
|
150
|
-
const route = router(modelList);
|
|
151
|
-
const selectedModel = route.selectModel('test');
|
|
152
|
-
if (selectedModel.llm_params.model === 'ollama/test') {
|
|
153
|
-
console.log('✅ Test 10 passed: Router model selection works');
|
|
154
|
-
passedCount++;
|
|
155
|
-
} else {
|
|
156
|
-
console.log('❌ Test 10 failed: Incorrect model selected');
|
|
157
|
-
}
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.log('❌ Test 10 failed:', error.message);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Test 11: Router auto-selection
|
|
163
|
-
testCount++;
|
|
164
|
-
try {
|
|
165
|
-
const modelList = [
|
|
166
|
-
{
|
|
167
|
-
model_name: 'test1',
|
|
168
|
-
llm_params: {
|
|
169
|
-
model: 'ollama/test1',
|
|
170
|
-
api_key: 'test-key'
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
model_name: 'test2',
|
|
175
|
-
llm_params: {
|
|
176
|
-
model: 'ollama/test2',
|
|
177
|
-
api_key: 'test-key'
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
];
|
|
181
|
-
const route = router(modelList, 'random');
|
|
182
|
-
const selectedModel = route.autoSelectModel();
|
|
183
|
-
if (selectedModel && selectedModel.llm_params.model.startsWith('ollama/')) {
|
|
184
|
-
console.log('✅ Test 11 passed: Router auto-selection works');
|
|
185
|
-
passedCount++;
|
|
186
|
-
} else {
|
|
187
|
-
console.log('❌ Test 11 failed: Auto-selection failed');
|
|
188
|
-
}
|
|
189
|
-
} catch (error) {
|
|
190
|
-
console.log('❌ Test 11 failed:', error.message);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Test 12: Guardrails execution
|
|
194
|
-
testCount++;
|
|
195
|
-
try {
|
|
196
|
-
const modelList = [
|
|
197
|
-
{
|
|
198
|
-
model_name: 'test',
|
|
199
|
-
llm_params: {
|
|
200
|
-
model: 'ollama/test',
|
|
201
|
-
api_key: 'test-key'
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
];
|
|
205
|
-
const route = router(modelList);
|
|
206
|
-
|
|
207
|
-
route.setGuardrails([
|
|
208
|
-
{
|
|
209
|
-
name: 'test_guardrail',
|
|
210
|
-
mode: 'pre_call',
|
|
211
|
-
code: (processId, input) => {
|
|
212
|
-
return { ...input, messages: [...input.messages, { role: 'system', content: 'Test' }] };
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
]);
|
|
216
|
-
|
|
217
|
-
console.log('✅ Test 12 passed: Guardrails set successfully');
|
|
218
|
-
passedCount++;
|
|
219
|
-
} catch (error) {
|
|
220
|
-
console.log('❌ Test 12 failed:', error.message);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Test 13: Server app creation
|
|
224
|
-
testCount++;
|
|
225
|
-
try {
|
|
226
|
-
const testApp = app; // Already created
|
|
227
|
-
if (testApp && typeof testApp.use === 'function') {
|
|
228
|
-
console.log('✅ Test 13 passed: Server app created successfully');
|
|
229
|
-
passedCount++;
|
|
230
|
-
} else {
|
|
231
|
-
console.log('❌ Test 13 failed: Server app creation failed');
|
|
232
|
-
}
|
|
233
|
-
} catch (error) {
|
|
234
|
-
console.log('❌ Test 13 failed:', error.message);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
console.log(`\nTest Results: ${passedCount}/${testCount} tests passed`);
|
|
238
|
-
if (passedCount === testCount) {
|
|
239
|
-
console.log('🎉 All tests passed!');
|
|
240
|
-
} else {
|
|
241
|
-
console.log('⚠️ Some tests failed. Please review the implementation.');
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Run tests
|
|
246
|
-
runTests().catch(console.error);
|
|
File without changes
|
|
File without changes
|