Skip to content

Commit

Permalink
Feat: more settings for ai engine & models (#611)
Browse files Browse the repository at this point in the history
* may setup gpt ai engine & model

* ai models setting works

* update openai setting

* validate engine setting before save

* fail fast

* clean code

* refactor gpt preset
  • Loading branch information
an-lee committed May 15, 2024
1 parent b4d7fb8 commit 61c7600
Show file tree
Hide file tree
Showing 16 changed files with 449 additions and 148 deletions.
4 changes: 2 additions & 2 deletions enjoy/src/commands/json.command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChatOpenAI } from "@langchain/openai";
import { RESPONSE_JSON_FORMAT_MODELS } from "@/constants";
import { NOT_SUPPORTE_JSON_FORMAT_MODELS } from "@/constants";
import { zodToJsonSchema } from "zod-to-json-schema";

export const jsonCommand = async (
Expand All @@ -15,7 +15,7 @@ export const jsonCommand = async (
const { key, temperature = 0, baseUrl, schema } = options;
let { modelName = "gpt-4o" } = options;

if (RESPONSE_JSON_FORMAT_MODELS.indexOf(modelName) === -1) {
if (NOT_SUPPORTE_JSON_FORMAT_MODELS.indexOf(modelName) > -1) {
modelName = "gpt-4o";
}

Expand Down
14 changes: 4 additions & 10 deletions enjoy/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,10 @@ export const PROCESS_TIMEOUT = 1000 * 60 * 15;
export const AI_GATEWAY_ENDPOINT =
"https://gateway.ai.cloudflare.com/v1/11d43ab275eb7e1b271ba4089ecc3864/enjoy";

export const RESPONSE_JSON_FORMAT_MODELS = [
"gpt-3.5-turbo-0125",
"gpt-3.5-turbo",
"gpt-3.5-turbo-1106",
"gpt-4o",
"gpt-4-turbo",
"gpt-4-turbo-2024-04-09",
"gpt-4-0125-preview",
"gpt-4-turbo-preview",
"gpt-4-1106-preview",
export const NOT_SUPPORTE_JSON_FORMAT_MODELS = [
"gpt-4-vision-preview",
"gpt-4",
"gpt-4-32k",
];

export const CONVERSATION_PRESETS = [
Expand Down
6 changes: 6 additions & 0 deletions enjoy/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@
"whisperModelIsNotWorking": "Whisper model is not working",
"relaunchIsNeededAfterChanged": "Relaunch is needed after changed",
"defaultAiEngine": "Default AI engine",
"aiEngine": "AI engine",
"defaultAiModel": "Default AI model",
"lookupAiModel": "AI Lookup",
"translateAiModel": "AI Translate",
"analyzeAiModel": "AI Analyze",
"extractStoryAiModel": "AI extract vocabulary",
"openAiEngineTips": "Use OpenAI with your own key as default AI engine.",
"enjoyAiEngineTips": "Use EnjoyAI as default AI engine. It is a paid service.",
"openaiKeySaved": "OpenAI key saved",
Expand Down
6 changes: 6 additions & 0 deletions enjoy/src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@
"whisperModelIsNotWorking": "Whisper 模型无法正常工作,请尝试更换模型后重试,或联系开发者",
"relaunchIsNeededAfterChanged": "更改后需要重新启动",
"defaultAiEngine": "默认 AI 引擎",
"aiEngine": "AI 引擎",
"defaultAiModel": "默认 AI 模型",
"lookupAiModel": "智能词典模型",
"translateAiModel": "智能翻译模型",
"analyzeAiModel": "句子分析模型",
"extractStoryAiModel": "提取生词模型",
"openAiEngineTips": "使用 OpenAI 作为默认 AI 引擎,需要配置 API 密钥。",
"enjoyAiEngineTips": "使用 EnjoyAI 作为默认 AI 引擎,收费服务。",
"openaiKeySaved": "OpenAI 密钥已保存",
Expand Down
8 changes: 8 additions & 0 deletions enjoy/src/main/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ export default {
return settings.setSync("defaultEngine", engine);
});

ipcMain.handle("settings-get-gpt-engine", (_event) => {
return settings.getSync("engine.gpt");
});

ipcMain.handle("settings-set-gpt-engine", (_event, engine) => {
return settings.setSync("engine.gpt", engine);
});

ipcMain.handle("settings-get-default-hotkeys", (_event) => {
return settings.getSync("defaultHotkeys");
});
Expand Down
6 changes: 6 additions & 0 deletions enjoy/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
setDefaultEngine: (engine: "enjoyai" | "openai") => {
return ipcRenderer.invoke("settings-set-default-engine", engine);
},
getGptEngine: () => {
return ipcRenderer.invoke("settings-get-gpt-engine");
},
setGptEngine: (engine: GptEngineSettingType) => {
return ipcRenderer.invoke("settings-set-gpt-engine", engine);
},
getLlm: (provider: string) => {
return ipcRenderer.invoke("settings-get-llm", provider);
},
Expand Down
Loading

0 comments on commit 61c7600

Please sign in to comment.