Skip to content

Commit 505427c

Browse files
committed
Add back gemini support, add provider selector in ai assistant setting
1 parent 5e3282e commit 505427c

3 files changed

Lines changed: 46 additions & 12 deletions

File tree

src/lib/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class Settings {
151151
checkFiles: true,
152152
desktopMode: false,
153153
console: this.CONSOLE_LEGACY,
154+
aiProvider: "openai",
154155
aiApiKey: "",
155156
aiModel: "gemini-2.0-flash",
156157
aiBaseUrl: "https://openrouter.ai/api/v1",

src/pages/aiAssistant/assistant.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
12
import { createReactAgent } from "@langchain/langgraph/prebuilt";
23
import { ChatOpenAI } from "@langchain/openai";
34
import alert from "dialogs/alert";
@@ -50,14 +51,29 @@ export default function openAIAssistantPage() {
5051
});
5152

5253
const agentCheckpointer = new CordovaSqliteSaver();
53-
const model = new ChatOpenAI({
54-
model: settings.value.aiModel,
55-
apiKey: settings.value.aiApiKey,
56-
streaming: true,
57-
configuration: {
58-
baseURL: settings.value.aiBaseUrl,
59-
},
60-
});
54+
if ((settings.value.aiProvider = "openai")) {
55+
if (!settings.value.aiBaseUrl) {
56+
alert(
57+
"Error",
58+
"Please set your API base url in Settings before using the assistant.",
59+
);
60+
return;
61+
}
62+
const model = new ChatOpenAI({
63+
model: settings.value.aiModel,
64+
apiKey: settings.value.aiApiKey,
65+
streaming: true,
66+
configuration: {
67+
baseURL: settings.value.aiBaseUrl,
68+
},
69+
});
70+
} else if ((settings.value.aiProvider = "gemini")) {
71+
const model = new ChatGoogleGenerativeAI({
72+
model: settings.value.aiModel,
73+
apiKey: settings.value.aiApiKey,
74+
streaming: true,
75+
});
76+
}
6177

6278
const toolsArray = Object.values(allTools);
6379

src/settings/aiassistantSettings.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ export default function aiassistantSettings() {
55
const title = "Ai Assistant Settings";
66
const values = appSettings.value;
77
const items = [
8+
{
9+
key: "aiProvider",
10+
text: "AI Provider",
11+
value: values.aiProvider,
12+
valueText(value) {
13+
return this.select.find(([v]) => v === value)[1];
14+
},
15+
select: [
16+
["openai", "OpenAI/OpenAI-Like"],
17+
["gemini", "Gemini"],
18+
],
19+
info: "Select your AI provider.",
20+
},
821
{
922
key: "aiApiKey",
1023
text: "API Key",
@@ -19,14 +32,18 @@ export default function aiassistantSettings() {
1932
prompt: "Model",
2033
info: "Enter your AI model here.",
2134
},
22-
{
35+
];
36+
37+
// Show API Base URL only when provider is OpenAI (value 'openai')
38+
if (values.aiProvider === "openai") {
39+
items.push({
2340
key: "aiBaseUrl",
2441
text: "API Base URL",
2542
value: values.aiBaseUrl,
2643
prompt: "API Base URL",
27-
info: "Enter base url of your api here.",
28-
},
29-
];
44+
info: "Enter base URL of your API here. (OpenAI compatible only)",
45+
});
46+
}
3047

3148
return settingsPage(title, items, callback);
3249

0 commit comments

Comments
 (0)