Skip to content

Commit 66b3ddb

Browse files
committed
✨config ModelEngine Service
2 parents 6a30c20 + 282fe62 commit 66b3ddb

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

doc/docs/zh/opensource-memorial-wall.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,19 @@ Nexent开发者加油
632632
开放原子大赛接触到了Nexent平台,祝越来越好!
633633
:::
634634

635-
::: hongmuxiangxun - 2025-12-19
635+
::: info hongmuxiangxun - 2025-12-19
636636
开放原子大赛接触到了Nexent平台,祝越来越好,越来越容易上手。
637637
:::
638+
639+
::: info jinmo - 2025-12-25
640+
无意中接触了Nexent平台,喜欢它的风格,祝它能被更多人知晓。
641+
:::
642+
643+
::: tip 开源新手 - 2025-12-25
644+
感谢 Nexent 让我踏上了开源之旅!这个项目的文档真的很棒,帮助我快速上手,希望 Nexent 越来越好!
645+
:::
646+
647+
::: info 1-xiaozheng-1 - 2025-12-25
648+
从modelengine中看到Nexent,发现这个平台创建智能体简直一绝,希望越来越好。
649+
:::
650+

docker/.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ REDIS_URL=redis://redis:6379/0
7070
REDIS_BACKEND_URL=redis://redis:6379/1
7171

7272
# Model Engine Config
73-
MODEL_ENGINE_HOST=https://localhost:30555
74-
MODEL_ENGINE_APIKEY=
73+
MODEL_ENGINE_ENABLED=true
74+
MODEL_ENGINE_HOST=""
75+
MODEL_ENGINE_API_KEY=""
7576

7677
# Supabase Config
7778
DASHBOARD_USERNAME=supabase
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { modelService } from "./modelService";
2+
import { ModelType } from "@/types/modelConfig";
3+
4+
const TYPES_TO_SYNC: ModelType[] = [
5+
("llm" as unknown) as ModelType,
6+
("embedding" as unknown) as ModelType,
7+
("multi_embedding" as unknown) as ModelType,
8+
("vlm" as unknown) as ModelType,
9+
("tts" as unknown) as ModelType,
10+
("stt" as unknown) as ModelType,
11+
];
12+
13+
/**
14+
* Sync models from ModelEngine and verify connectivity.
15+
* Returns an object with overall success and per-model verification results.
16+
*/
17+
export async function syncModelEngine(apiKey: string) {
18+
let syncFailed = false;
19+
try {
20+
for (const type of TYPES_TO_SYNC) {
21+
try {
22+
const providerModels = await modelService.addProviderModel({
23+
provider: "modelengine",
24+
type: type as any,
25+
apiKey,
26+
});
27+
if (providerModels && providerModels.length > 0) {
28+
await modelService.addBatchCustomModel({
29+
api_key: apiKey,
30+
provider: "modelengine",
31+
type,
32+
models: providerModels,
33+
});
34+
}
35+
} catch (err) {
36+
// mark that at least one provider fetch failed
37+
syncFailed = true;
38+
}
39+
}
40+
41+
// reload all models from backend
42+
const allModelsAfter = await modelService.getAllModels();
43+
const modelEngineModels = allModelsAfter.filter((m) => m.source === "modelengine");
44+
45+
// update persisted api keys for modelengine models if needed
46+
if (modelEngineModels.length > 0 && apiKey) {
47+
const updates = modelEngineModels.map((m) => ({
48+
model_id: String(m.id || m.name || m.displayName),
49+
apiKey: apiKey,
50+
}));
51+
try {
52+
await modelService.updateBatchModel(updates);
53+
} catch (err) {
54+
// non-fatal; continue to verification but flag sync failure
55+
syncFailed = true;
56+
}
57+
}
58+
59+
// verify each persistent model and collect results
60+
const verificationResults: Array<{ displayName: string; type: string; connected: boolean }> = [];
61+
for (const m of modelEngineModels) {
62+
if (!m.displayName) continue;
63+
try {
64+
const connected = await modelService.verifyCustomModel(m.displayName);
65+
verificationResults.push({ displayName: m.displayName, type: m.type, connected });
66+
} catch (err) {
67+
verificationResults.push({ displayName: m.displayName, type: m.type, connected: false });
68+
}
69+
}
70+
71+
const anyUnavailable = verificationResults.some((r) => !r.connected);
72+
const success = !syncFailed && !anyUnavailable;
73+
return { success, verificationResults, error: syncFailed ? "provider_fetch_failed" : undefined };
74+
} catch (err: any) {
75+
return { success: false, verificationResults: [], error: err?.message || String(err) };
76+
}
77+
}

0 commit comments

Comments
 (0)