llmjs2 1.1.1 → 1.3.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/CONFIG_README.md +98 -0
- package/README.md +382 -357
- package/cli.js +195 -0
- package/config.yaml +149 -0
- package/docs/BASIC_USAGE.md +296 -0
- package/docs/CLI.md +455 -0
- package/docs/GET_STARTED.md +129 -0
- package/docs/GUARDRAILS_GUIDE.md +734 -0
- package/docs/README.md +47 -0
- package/docs/ROUTER_GUIDE.md +397 -0
- package/docs/SERVER_MODE.md +350 -0
- package/index.js +199 -246
- package/package.json +45 -34
- package/providers/ollama.js +120 -88
- package/providers/openai.js +104 -0
- package/providers/openrouter.js +113 -79
- package/router.js +248 -0
- package/server.js +186 -0
- package/test.js +246 -0
- package/validate-config.js +87 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Test script to validate config.yaml loading
|
|
4
|
+
const yaml = require('yaml');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
function loadAndValidateConfig() {
|
|
9
|
+
const configPath = path.join(__dirname, 'config.yaml');
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync(configPath)) {
|
|
12
|
+
console.error('❌ config.yaml not found');
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const configContent = fs.readFileSync(configPath, 'utf8');
|
|
18
|
+
const config = yaml.parse(configContent);
|
|
19
|
+
|
|
20
|
+
console.log('✅ Config file loaded successfully');
|
|
21
|
+
console.log(`📋 Found ${config.model_list?.length || 0} models`);
|
|
22
|
+
console.log(`🛡️ Found ${config.guardrails?.length || 0} guardrails`);
|
|
23
|
+
console.log(`🔀 Routing strategy: ${config.router_settings?.routing_strategy || 'default'}`);
|
|
24
|
+
|
|
25
|
+
// Validate model list
|
|
26
|
+
if (!config.model_list || !Array.isArray(config.model_list)) {
|
|
27
|
+
console.error('❌ model_list must be an array');
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Check each model
|
|
32
|
+
const modelNames = [];
|
|
33
|
+
for (const model of config.model_list) {
|
|
34
|
+
if (!model.model_name || !model.llm_params?.model) {
|
|
35
|
+
console.error('❌ Each model must have model_name and llm_params.model');
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
modelNames.push(model.model_name);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log(`📊 Model names: ${[...new Set(modelNames)].join(', ')}`);
|
|
42
|
+
|
|
43
|
+
// Validate guardrails
|
|
44
|
+
if (config.guardrails) {
|
|
45
|
+
for (const guardrail of config.guardrails) {
|
|
46
|
+
if (!guardrail.name || !guardrail.mode || !guardrail.code) {
|
|
47
|
+
console.error(`❌ Guardrail "${guardrail.name || 'unnamed'}" missing required fields`);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (!['pre_call', 'post_call'].includes(guardrail.mode)) {
|
|
51
|
+
console.error(`❌ Guardrail "${guardrail.name}" has invalid mode: ${guardrail.mode}`);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Test environment variable resolution
|
|
58
|
+
const testModel = config.model_list[0];
|
|
59
|
+
if (testModel.llm_params.api_key?.startsWith('os.environ/')) {
|
|
60
|
+
const envVar = testModel.llm_params.api_key.replace('os.environ/', '');
|
|
61
|
+
const envValue = process.env[envVar];
|
|
62
|
+
console.log(`🔑 API key for ${testModel.llm_params.model}: ${envValue ? '✅ Set' : '❌ Not set'}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log('🎉 Config validation passed!');
|
|
66
|
+
return true;
|
|
67
|
+
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('❌ Config validation failed:', error.message);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Run validation
|
|
75
|
+
console.log('🔍 Validating config.yaml...\n');
|
|
76
|
+
const success = loadAndValidateConfig();
|
|
77
|
+
|
|
78
|
+
if (!success) {
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
console.log('\n💡 To test the server, run:');
|
|
83
|
+
console.log(' node cli.js --config config.yaml --port 3001');
|
|
84
|
+
console.log('\n📖 To test with curl:');
|
|
85
|
+
console.log(' curl -X POST http://localhost:3001/v1/chat/completions \\');
|
|
86
|
+
console.log(' -H "Content-Type: application/json" \\');
|
|
87
|
+
console.log(' -d \'{"messages":[{"role":"user","content":"Hello!"}]}\'');
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 littlellmjs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|