Skip to content

Commit 8e0f09e

Browse files
fengju0213bytecii
andauthored
feat: add ernie in custom model (#1487)
Co-authored-by: bytecii <994513625@qq.com>
1 parent 031cb65 commit 8e0f09e

6 files changed

Lines changed: 64 additions & 14 deletions

File tree

backend/app/controller/electron_browser.cjs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const startUrl = args[2] || 'https://www.google.com';
99

1010
// This must be called before app.ready
1111
app.commandLine.appendSwitch('remote-debugging-port', cdpPort);
12+
app.commandLine.appendSwitch('password-store', 'basic');
13+
app.commandLine.appendSwitch('use-mock-keychain');
1214

1315
console.log('[ELECTRON BROWSER] Starting with:');
1416
console.log(' Chrome version:', process.versions.chrome);
@@ -36,8 +38,14 @@ app.whenReady().then(async () => {
3638

3739
// Check command line switches
3840
console.log('[ELECTRON BROWSER] Command line switches:');
39-
console.log(' user-data-dir:', app.commandLine.getSwitchValue('user-data-dir'));
40-
console.log(' remote-debugging-port:', app.commandLine.getSwitchValue('remote-debugging-port'));
41+
console.log(
42+
' user-data-dir:',
43+
app.commandLine.getSwitchValue('user-data-dir')
44+
);
45+
console.log(
46+
' remote-debugging-port:',
47+
app.commandLine.getSwitchValue('remote-debugging-port')
48+
);
4149

4250
// Log partition session info
4351
const userLoginSession = session.fromPartition('persist:user_login');
@@ -46,7 +54,12 @@ app.whenReady().then(async () => {
4654
console.log(' Session storage path:', userLoginSession.getStoragePath());
4755

4856
// Check if Cookies file exists
49-
const cookiesPath = path.join(app.getPath('userData'), 'Partitions', 'user_login', 'Cookies');
57+
const cookiesPath = path.join(
58+
app.getPath('userData'),
59+
'Partitions',
60+
'user_login',
61+
'Cookies'
62+
);
5063
console.log('[ELECTRON BROWSER] Cookies path:', cookiesPath);
5164
console.log('[ELECTRON BROWSER] Cookies exists:', fs.existsSync(cookiesPath));
5265
if (fs.existsSync(cookiesPath)) {
@@ -60,8 +73,8 @@ app.whenReady().then(async () => {
6073
webPreferences: {
6174
nodeIntegration: true,
6275
contextIsolation: false,
63-
webviewTag: true
64-
}
76+
webviewTag: true,
77+
},
6578
});
6679

6780
// Create navigation bar and webview HTML
@@ -305,9 +318,14 @@ app.whenReady().then(async () => {
305318
setInterval(async () => {
306319
try {
307320
const cookies = await userLoginSession.cookies.get({});
308-
console.log('[ELECTRON BROWSER] Current cookies count:', cookies.length);
321+
console.log(
322+
'[ELECTRON BROWSER] Current cookies count:',
323+
cookies.length
324+
);
309325
if (cookies.length > 0) {
310-
console.log('[ELECTRON BROWSER] Cookie domains:', [...new Set(cookies.map(c => c.domain))]);
326+
console.log('[ELECTRON BROWSER] Cookie domains:', [
327+
...new Set(cookies.map((c) => c.domain)),
328+
]);
311329
}
312330
} catch (error) {
313331
console.error('[ELECTRON BROWSER] Failed to get cookies:', error);
@@ -327,20 +345,34 @@ app.whenReady().then(async () => {
327345

328346
// Log cookies before flush
329347
const cookiesBeforeFlush = await userLoginSession.cookies.get({});
330-
console.log('[ELECTRON BROWSER] Cookies count before flush:', cookiesBeforeFlush.length);
348+
console.log(
349+
'[ELECTRON BROWSER] Cookies count before flush:',
350+
cookiesBeforeFlush.length
351+
);
331352

332353
// Flush storage
333354
console.log('[ELECTRON BROWSER] Flushing storage data...');
334355
await userLoginSession.flushStorageData();
335356
console.log('[ELECTRON BROWSER] Storage data flushed successfully');
336357

337358
// Check cookies file after flush
338-
const cookiesPath = path.join(app.getPath('userData'), 'Partitions', 'user_login', 'Cookies');
359+
const cookiesPath = path.join(
360+
app.getPath('userData'),
361+
'Partitions',
362+
'user_login',
363+
'Cookies'
364+
);
339365
if (fs.existsSync(cookiesPath)) {
340366
const stats = fs.statSync(cookiesPath);
341-
console.log('[ELECTRON BROWSER] Cookies file size after flush:', stats.size, 'bytes');
367+
console.log(
368+
'[ELECTRON BROWSER] Cookies file size after flush:',
369+
stats.size,
370+
'bytes'
371+
);
342372
} else {
343-
console.log('[ELECTRON BROWSER] WARNING: Cookies file does not exist after flush!');
373+
console.log(
374+
'[ELECTRON BROWSER] WARNING: Cookies file does not exist after flush!'
375+
);
344376
}
345377
} catch (error) {
346378
console.error('[ELECTRON BROWSER] Failed to flush storage data:', error);
@@ -368,9 +400,14 @@ app.on('before-quit', async (event) => {
368400

369401
// Log cookies before flush
370402
const cookiesBeforeQuit = await userLoginSession.cookies.get({});
371-
console.log('[ELECTRON BROWSER] Cookies count before quit:', cookiesBeforeQuit.length);
403+
console.log(
404+
'[ELECTRON BROWSER] Cookies count before quit:',
405+
cookiesBeforeQuit.length
406+
);
372407
if (cookiesBeforeQuit.length > 0) {
373-
console.log('[ELECTRON BROWSER] Cookie domains before quit:', [...new Set(cookiesBeforeQuit.map(c => c.domain))]);
408+
console.log('[ELECTRON BROWSER] Cookie domains before quit:', [
409+
...new Set(cookiesBeforeQuit.map((c) => c.domain)),
410+
]);
374411
}
375412

376413
// Flush storage

backend/app/model/model_platform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"z.ai": "openai-compatible-model",
2121
"ModelArk": "openai-compatible-model",
2222
"grok": "openai-compatible-model",
23+
"ernie": "openai-compatible-model",
2324
"llama.cpp": "openai-compatible-model",
2425
}
2526

backend/tests/app/model/test_model_platform.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_normalize_model_platform_maps_known_aliases():
2626
assert normalize_model_platform("grok") == "openai-compatible-model"
2727
assert normalize_model_platform("z.ai") == "openai-compatible-model"
2828
assert normalize_model_platform("ModelArk") == "openai-compatible-model"
29+
assert normalize_model_platform("ernie") == "openai-compatible-model"
2930
assert normalize_model_platform("llama.cpp") == "openai-compatible-model"
3031

3132

@@ -44,7 +45,7 @@ class _Model(BaseModel):
4445
optional_model_platform: NormalizedOptionalModelPlatform = None
4546

4647
item = _Model(
47-
model_platform="llama.cpp",
48+
model_platform="ernie",
4849
optional_model_platform="ModelArk",
4950
)
5051

src/assets/model/ernie.png

133 KB
Loading

src/lib/llm.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ export const INIT_PROVODERS: Provider[] = [
164164
is_valid: false,
165165
model_type: '',
166166
},
167+
{
168+
id: 'ernie',
169+
name: 'Ernie',
170+
apiKey: '',
171+
apiHost: 'https://qianfan.baidubce.com/v2',
172+
description: 'Baidu Ernie model configuration.',
173+
is_valid: false,
174+
model_type: '',
175+
},
167176
{
168177
id: 'openai-compatible-model',
169178
name: 'OpenAI Compatible',

src/pages/Agents/Models.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import azureImage from '@/assets/model/azure.svg';
6464
import bedrockImage from '@/assets/model/bedrock.svg';
6565
import deepseekImage from '@/assets/model/deepseek.svg';
6666
import eigentImage from '@/assets/model/eigent.svg';
67+
import ernieImage from '@/assets/model/ernie.png';
6768
import geminiImage from '@/assets/model/gemini.svg';
6869
import llamaCppImage from '@/assets/model/llamacpp.svg';
6970
import lmstudioImage from '@/assets/model/lmstudio.svg';
@@ -1057,6 +1058,7 @@ export default function SettingModels() {
10571058
openrouter: openrouterImage,
10581059
'tongyi-qianwen': qwenImage,
10591060
deepseek: deepseekImage,
1061+
ernie: ernieImage,
10601062
minimax: minimaxImage,
10611063
'z.ai': zaiImage,
10621064
moonshot: moonshotImage,

0 commit comments

Comments
 (0)