freellm 1.0.12 → 1.0.13
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/client-dist/assets/index-CZTExjJU.js +174 -0
- package/client-dist/index.html +1 -1
- package/dist/db/index.d.ts +3 -0
- package/dist/db/index.js +12 -0
- package/dist/providers/google.js +6 -2
- package/dist/providers/openai-compat.js +7 -3
- package/dist/providers/types.d.ts +1 -1
- package/dist/providers/types.js +3 -12
- package/dist/routes/api/keys.js +86 -6
- package/dist/services/router.d.ts +2 -0
- package/dist/services/router.js +3 -6
- package/package.json +12 -2
- package/client-dist/assets/index-nnyuHthF.js +0 -96
package/client-dist/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
9
9
|
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #0f0f0f; color: #e1e1e1; }
|
|
10
10
|
</style>
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-CZTExjJU.js"></script>
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<div id="root"></div>
|
package/dist/db/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type Model = {
|
|
|
23
23
|
context_length: number | null;
|
|
24
24
|
fallback_order: number;
|
|
25
25
|
enabled: number;
|
|
26
|
+
available: number;
|
|
26
27
|
};
|
|
27
28
|
export declare function getSetting(key: string): string | undefined;
|
|
28
29
|
export declare function setSetting(key: string, value: string): void;
|
|
@@ -38,6 +39,8 @@ export declare function listModels(type?: string): Model[];
|
|
|
38
39
|
export declare function listEnabledModels(type?: string): Model[];
|
|
39
40
|
export declare function updateModelOrder(id: number, order: number): void;
|
|
40
41
|
export declare function toggleModel(id: number, enabled: boolean): void;
|
|
42
|
+
export declare function setModelAvailability(id: number, available: number): void;
|
|
43
|
+
export declare function resetPlatformAvailability(platform: string): void;
|
|
41
44
|
export declare function listModelsByPlatform(platform: string): Model[];
|
|
42
45
|
export declare function upsertModelsFromList(platform: string, models: Array<{
|
|
43
46
|
id: string;
|
package/dist/db/index.js
CHANGED
|
@@ -19,6 +19,8 @@ exports.listModels = listModels;
|
|
|
19
19
|
exports.listEnabledModels = listEnabledModels;
|
|
20
20
|
exports.updateModelOrder = updateModelOrder;
|
|
21
21
|
exports.toggleModel = toggleModel;
|
|
22
|
+
exports.setModelAvailability = setModelAvailability;
|
|
23
|
+
exports.resetPlatformAvailability = resetPlatformAvailability;
|
|
22
24
|
exports.listModelsByPlatform = listModelsByPlatform;
|
|
23
25
|
exports.upsertModelsFromList = upsertModelsFromList;
|
|
24
26
|
exports.listCustomProviders = listCustomProviders;
|
|
@@ -110,6 +112,10 @@ function migrate() {
|
|
|
110
112
|
CREATE INDEX IF NOT EXISTS idx_analytics_platform ON analytics(platform);
|
|
111
113
|
`);
|
|
112
114
|
seedModels();
|
|
115
|
+
const cols = db.prepare('PRAGMA table_info(models)').all();
|
|
116
|
+
if (!cols.some(c => c.name === 'available')) {
|
|
117
|
+
db.exec('ALTER TABLE models ADD COLUMN available INTEGER NOT NULL DEFAULT -1');
|
|
118
|
+
}
|
|
113
119
|
}
|
|
114
120
|
// ─── Settings ────────────────────────────────────────────────────────────────
|
|
115
121
|
function getSetting(key) {
|
|
@@ -165,6 +171,12 @@ function updateModelOrder(id, order) {
|
|
|
165
171
|
function toggleModel(id, enabled) {
|
|
166
172
|
db.prepare('UPDATE models SET enabled = ? WHERE id = ?').run(enabled ? 1 : 0, id);
|
|
167
173
|
}
|
|
174
|
+
function setModelAvailability(id, available) {
|
|
175
|
+
db.prepare('UPDATE models SET available = ? WHERE id = ?').run(available, id);
|
|
176
|
+
}
|
|
177
|
+
function resetPlatformAvailability(platform) {
|
|
178
|
+
db.prepare('UPDATE models SET available = -1 WHERE platform = ?').run(platform);
|
|
179
|
+
}
|
|
168
180
|
function listModelsByPlatform(platform) {
|
|
169
181
|
return db
|
|
170
182
|
.prepare('SELECT * FROM models WHERE platform = ? ORDER BY fallback_order, id')
|
package/dist/providers/google.js
CHANGED
|
@@ -47,8 +47,12 @@ class GoogleProvider extends types_1.BaseProvider {
|
|
|
47
47
|
}
|
|
48
48
|
async listModels(apiKey) {
|
|
49
49
|
const res = await fetch(`${this.baseUrl}/models?key=${encodeURIComponent(apiKey)}`);
|
|
50
|
-
if (!res.ok)
|
|
51
|
-
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
const text = await res.text().catch(() => '');
|
|
52
|
+
const err = new Error(`${res.status}: ${text}`);
|
|
53
|
+
err.status = res.status;
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
52
56
|
const data = await res.json();
|
|
53
57
|
return (data.models ?? [])
|
|
54
58
|
.filter((m) => !!m.name && (m.supportedGenerationMethods ?? []).includes('generateContent'))
|
|
@@ -18,8 +18,12 @@ class OpenAICompatProvider extends types_1.BaseProvider {
|
|
|
18
18
|
if (apiKey)
|
|
19
19
|
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
20
20
|
const res = await fetch(`${this.baseUrl}/models`, { headers });
|
|
21
|
-
if (!res.ok)
|
|
22
|
-
|
|
21
|
+
if (!res.ok) {
|
|
22
|
+
const text = await res.text().catch(() => '');
|
|
23
|
+
const err = new Error(`${res.status}: ${text}`);
|
|
24
|
+
err.status = res.status;
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
23
27
|
const data = await res.json();
|
|
24
28
|
return (data.data ?? [])
|
|
25
29
|
.filter((m) => !!m.id)
|
|
@@ -120,7 +124,7 @@ exports.PROVIDERS = {
|
|
|
120
124
|
cohere: new OpenAICompatProvider('cohere', 'https://api.cohere.com/compatibility/v1', 'command-r'),
|
|
121
125
|
llm7: new OpenAICompatProvider('llm7', 'https://llm7.io/v1', 'gpt-4o-mini'),
|
|
122
126
|
ovh: new OpenAICompatProvider('ovh', 'https://oai.endpoints.kepler.ai.cloud.ovh.net/v1', 'Llama-3.3-70B-Instruct'),
|
|
123
|
-
nvidia: new OpenAICompatProvider('nvidia', 'https://integrate.api.nvidia.com/v1', 'deepseek-ai/deepseek-
|
|
127
|
+
nvidia: new OpenAICompatProvider('nvidia', 'https://integrate.api.nvidia.com/v1', 'deepseek-ai/deepseek-coder-6.7b-instruct'),
|
|
124
128
|
kilo: new OpenAICompatProvider('kilo', 'https://gateway.kilo.chat/v1', 'poolside/laguna-m.1:free'),
|
|
125
129
|
opencode: new OpenAICompatProvider('opencode', 'https://api.opencode.ai/v1', 'deepseek-v4-flash-free'),
|
|
126
130
|
zhipu: new OpenAICompatProvider('zhipu', 'https://open.bigmodel.cn/api/paas/v4', 'glm-4.7-flash'),
|
|
@@ -88,7 +88,7 @@ export declare abstract class BaseProvider {
|
|
|
88
88
|
protected fetchJSON<T>(url: string, options: RequestInit): Promise<T>;
|
|
89
89
|
abstract chat(apiKey: string, req: ChatRequest): Promise<ChatResponse>;
|
|
90
90
|
abstract streamChat(apiKey: string, req: ChatRequest, onChunk: (chunk: StreamChunk) => void, onDone: () => void, onError: (err: Error) => void): Promise<void>;
|
|
91
|
-
/** Default implementation:
|
|
91
|
+
/** Default implementation: verify the key via the provider's /models endpoint; throws on failure */
|
|
92
92
|
healthCheck(apiKey: string): Promise<boolean>;
|
|
93
93
|
/** Fetch available models from the provider. Default: none (provider does not expose a list). */
|
|
94
94
|
listModels(_apiKey: string): Promise<Array<{
|
package/dist/providers/types.js
CHANGED
|
@@ -13,19 +13,10 @@ class BaseProvider {
|
|
|
13
13
|
}
|
|
14
14
|
return res.json();
|
|
15
15
|
}
|
|
16
|
-
/** Default implementation:
|
|
16
|
+
/** Default implementation: verify the key via the provider's /models endpoint; throws on failure */
|
|
17
17
|
async healthCheck(apiKey) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
model: this.defaultModel(),
|
|
21
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
22
|
-
max_tokens: 1,
|
|
23
|
-
});
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
18
|
+
await this.listModels(apiKey);
|
|
19
|
+
return true;
|
|
29
20
|
}
|
|
30
21
|
/** Fetch available models from the provider. Default: none (provider does not expose a list). */
|
|
31
22
|
async listModels(_apiKey) {
|
package/dist/routes/api/keys.js
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.keysRouter = void 0;
|
|
4
7
|
const express_1 = require("express");
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
5
9
|
const db_1 = require("../../db");
|
|
6
10
|
const db_2 = require("../../db");
|
|
7
|
-
const
|
|
11
|
+
const crypto_2 = require("../../crypto");
|
|
8
12
|
const providers_1 = require("../../providers");
|
|
9
13
|
exports.keysRouter = (0, express_1.Router)();
|
|
10
14
|
// Get unified API key (or generate one)
|
|
11
15
|
exports.keysRouter.get('/keys/unified', (_req, res) => {
|
|
12
16
|
let key = (0, db_2.getSetting)('unified_key');
|
|
13
17
|
if (!key) {
|
|
14
|
-
key = (0,
|
|
18
|
+
key = (0, crypto_2.generateUnifiedKey)();
|
|
15
19
|
(0, db_2.setSetting)('unified_key', key);
|
|
16
20
|
}
|
|
17
21
|
return res.json({ key });
|
|
18
22
|
});
|
|
19
23
|
// Regenerate unified key
|
|
20
24
|
exports.keysRouter.post('/keys/unified/regenerate', (_req, res) => {
|
|
21
|
-
const key = (0,
|
|
25
|
+
const key = (0, crypto_2.generateUnifiedKey)();
|
|
22
26
|
(0, db_2.setSetting)('unified_key', key);
|
|
23
27
|
return res.json({ key });
|
|
24
28
|
});
|
|
@@ -47,10 +51,13 @@ exports.keysRouter.get('/keys', (_req, res) => {
|
|
|
47
51
|
// Add provider key
|
|
48
52
|
exports.keysRouter.post('/keys', (req, res) => {
|
|
49
53
|
const { platform, key, label } = req.body;
|
|
50
|
-
if (!platform
|
|
51
|
-
return res.status(400).json({ error: 'platform
|
|
54
|
+
if (!platform) {
|
|
55
|
+
return res.status(400).json({ error: 'platform is required' });
|
|
52
56
|
}
|
|
53
|
-
|
|
57
|
+
if (!key && !KEYLESS_PLATFORMS.has(platform)) {
|
|
58
|
+
return res.status(400).json({ error: 'key is required for this platform' });
|
|
59
|
+
}
|
|
60
|
+
const id = (0, db_1.addKey)(platform, key ?? '', label);
|
|
54
61
|
return res.json({ id });
|
|
55
62
|
});
|
|
56
63
|
// Delete provider key
|
|
@@ -116,3 +123,76 @@ exports.keysRouter.post('/keys/:id/models/sync', async (req, res) => {
|
|
|
116
123
|
return res.status(500).json({ error: e.message });
|
|
117
124
|
}
|
|
118
125
|
});
|
|
126
|
+
const checkJobs = new Map();
|
|
127
|
+
const CHECK_PACE_MS = 1500;
|
|
128
|
+
const KEYLESS_PLATFORMS = new Set(['pollinations', 'llm7', 'ovh', 'ollama', 'kilo']);
|
|
129
|
+
// Start checking every chat model of this key against the provider, one by one
|
|
130
|
+
exports.keysRouter.post('/keys/:id/models/check', async (req, res) => {
|
|
131
|
+
const k = (0, db_1.getKey)(Number(req.params.id));
|
|
132
|
+
if (!k)
|
|
133
|
+
return res.status(404).json({ error: 'key not found' });
|
|
134
|
+
const provider = (0, providers_1.getChatProvider)(k.platform);
|
|
135
|
+
if (!provider)
|
|
136
|
+
return res.status(400).json({ error: `no provider for platform '${k.platform}'` });
|
|
137
|
+
for (const [id, job] of checkJobs) {
|
|
138
|
+
if (job.keyId === k.id && !job.done)
|
|
139
|
+
return res.json({ jobId: id, total: job.total });
|
|
140
|
+
}
|
|
141
|
+
const models = (0, db_1.listModelsByPlatform)(k.platform).filter((m) => m.type === 'chat');
|
|
142
|
+
const job = {
|
|
143
|
+
keyId: k.id,
|
|
144
|
+
total: models.length,
|
|
145
|
+
checked: 0,
|
|
146
|
+
current: '',
|
|
147
|
+
available: {},
|
|
148
|
+
done: false,
|
|
149
|
+
};
|
|
150
|
+
const jobId = crypto_1.default.randomBytes(8).toString('hex');
|
|
151
|
+
checkJobs.set(jobId, job);
|
|
152
|
+
const rawKey = (0, db_1.decryptKey)(k.key_enc);
|
|
153
|
+
(0, db_1.resetPlatformAvailability)(k.platform);
|
|
154
|
+
(async () => {
|
|
155
|
+
try {
|
|
156
|
+
for (const m of models) {
|
|
157
|
+
job.current = m.model_id;
|
|
158
|
+
try {
|
|
159
|
+
await Promise.race([
|
|
160
|
+
provider.chat(rawKey, {
|
|
161
|
+
model: m.model_id,
|
|
162
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
163
|
+
max_tokens: 1,
|
|
164
|
+
}),
|
|
165
|
+
new Promise((_resolve, reject) => setTimeout(() => reject(new Error('timeout')), 30000)),
|
|
166
|
+
]);
|
|
167
|
+
job.available[m.id] = 1;
|
|
168
|
+
(0, db_1.setModelAvailability)(m.id, 1);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
job.available[m.id] = 0;
|
|
172
|
+
(0, db_1.setModelAvailability)(m.id, 0);
|
|
173
|
+
}
|
|
174
|
+
job.checked++;
|
|
175
|
+
await new Promise((r) => setTimeout(r, CHECK_PACE_MS));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
job.done = true;
|
|
180
|
+
job.current = '';
|
|
181
|
+
setTimeout(() => checkJobs.delete(jobId), 10 * 60 * 1000);
|
|
182
|
+
}
|
|
183
|
+
})();
|
|
184
|
+
return res.json({ jobId, total: models.length });
|
|
185
|
+
});
|
|
186
|
+
// Poll check progress
|
|
187
|
+
exports.keysRouter.get('/keys/:id/models/check/:jobId', (_req, res) => {
|
|
188
|
+
const job = checkJobs.get(_req.params.jobId);
|
|
189
|
+
if (!job)
|
|
190
|
+
return res.status(404).json({ error: 'job not found' });
|
|
191
|
+
return res.json({
|
|
192
|
+
done: job.done,
|
|
193
|
+
total: job.total,
|
|
194
|
+
checked: job.checked,
|
|
195
|
+
current: job.current,
|
|
196
|
+
available: job.available,
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -6,6 +6,8 @@ export type RouterEntry = {
|
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Returns an ordered list of (model, key) candidates for a request.
|
|
9
|
+
* Follows the model priority list (fallback order) and only includes
|
|
10
|
+
* platforms that have an added, enabled, healthy key.
|
|
9
11
|
* Filters out disabled models, rate-limited/cooldown keys, and unhealthy keys.
|
|
10
12
|
*/
|
|
11
13
|
export declare function buildCandidates(requestedModel: string, type?: string, requireVision?: boolean, requireTools?: boolean): RouterEntry[];
|
package/dist/services/router.js
CHANGED
|
@@ -5,9 +5,10 @@ exports.hasVisionContent = hasVisionContent;
|
|
|
5
5
|
const db_1 = require("../db");
|
|
6
6
|
const providers_1 = require("../providers");
|
|
7
7
|
const ratelimit_1 = require("./ratelimit");
|
|
8
|
-
const KEYLESS_PLATFORMS = new Set(['pollinations', 'llm7', 'ovh', 'ollama', 'kilo']);
|
|
9
8
|
/**
|
|
10
9
|
* Returns an ordered list of (model, key) candidates for a request.
|
|
10
|
+
* Follows the model priority list (fallback order) and only includes
|
|
11
|
+
* platforms that have an added, enabled, healthy key.
|
|
11
12
|
* Filters out disabled models, rate-limited/cooldown keys, and unhealthy keys.
|
|
12
13
|
*/
|
|
13
14
|
function buildCandidates(requestedModel, type = 'chat', requireVision = false, requireTools = false) {
|
|
@@ -42,11 +43,7 @@ function buildCandidates(requestedModel, type = 'chat', requireVision = false, r
|
|
|
42
43
|
provider = (0, providers_1.getTTSProvider)(model.platform);
|
|
43
44
|
if (!provider)
|
|
44
45
|
continue;
|
|
45
|
-
//
|
|
46
|
-
if (KEYLESS_PLATFORMS.has(model.platform)) {
|
|
47
|
-
candidates.push({ model, providerKey: null, decryptedKey: '' });
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
46
|
+
// Providers are only used when a key has been added for them
|
|
50
47
|
const platformKeys = keysByPlatform[model.platform] ?? [];
|
|
51
48
|
for (const pk of platformKeys) {
|
|
52
49
|
if ((0, ratelimit_1.isOnCooldown)(model.platform, pk.id))
|
package/package.json
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "freellm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "One OpenAI-compatible endpoint for 15+ free LLM providers. Smart routing, failover, encrypted keys. Run with npx freellm.",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"llm",
|
|
7
|
+
"openai",
|
|
8
|
+
"proxy",
|
|
9
|
+
"groq",
|
|
10
|
+
"gemini",
|
|
11
|
+
"mistral",
|
|
12
|
+
"free",
|
|
13
|
+
"api-gateway"
|
|
14
|
+
],
|
|
6
15
|
"author": "",
|
|
7
16
|
"license": "MIT",
|
|
8
17
|
"bin": {
|
|
@@ -31,6 +40,7 @@
|
|
|
31
40
|
"cookie-parser": "^1.4.6",
|
|
32
41
|
"cors": "^2.8.5",
|
|
33
42
|
"express": "^4.18.3",
|
|
43
|
+
"marked": "^18.0.9",
|
|
34
44
|
"open": "^10.1.0",
|
|
35
45
|
"react": "^18.2.0",
|
|
36
46
|
"react-dom": "^18.2.0"
|