Skip to content

Commit d1928ae

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

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

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: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,44 @@ 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+
const found = this.select.find(([v]) => v === value);
14+
return found ? found[1] : value;
15+
},
16+
select: [
17+
["openai", "OpenAI/OpenAI-Like"],
18+
["gemini", "Gemini"],
19+
],
20+
info: "Select your AI provider.",
21+
},
822
{
923
key: "aiApiKey",
1024
text: "API Key",
1125
value: values.aiApiKey,
1226
prompt: "API Key",
27+
promptType: "text",
1328
info: "Enter your API key here.",
1429
},
30+
{
31+
key: "aiBaseUrl",
32+
text: "API Base URL (OpenAI/OpenAI-Like only)",
33+
value: values.aiBaseUrl,
34+
prompt: "API Base URL",
35+
promptType: "text",
36+
info: "Enter base URL of your API here. (OpenAI compatible only)",
37+
},
1538
{
1639
key: "aiModel",
1740
text: "Model",
1841
value: values.aiModel,
1942
prompt: "Model",
43+
promptType: "text",
2044
info: "Enter your AI model here.",
2145
},
22-
{
23-
key: "aiBaseUrl",
24-
text: "API Base URL",
25-
value: values.aiBaseUrl,
26-
prompt: "API Base URL",
27-
info: "Enter base url of your api here.",
28-
},
2946
];
3047

3148
return settingsPage(title, items, callback);

0 commit comments

Comments
 (0)