From 757c2af85c26888817e3e9bde1dd442b6a62ca4a Mon Sep 17 00:00:00 2001 From: an-lee Date: Fri, 19 Jan 2024 17:24:12 +0800 Subject: [PATCH] Feat: use default ai config (#167) * fix locale * use openai config if any --- enjoy/src/commands/ipa.command.ts | 1 + enjoy/src/commands/lookup.command.ts | 1 + .../conversations/conversation-form.tsx | 22 +++++++++++++++---- .../src/renderer/components/ffmpeg-check.tsx | 6 ++++- .../src/renderer/components/lookup-result.tsx | 1 + .../components/medias/media-caption.tsx | 2 ++ enjoy/src/renderer/pages/story.tsx | 1 + 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/enjoy/src/commands/ipa.command.ts b/enjoy/src/commands/ipa.command.ts index 215d803a..199fbd62 100644 --- a/enjoy/src/commands/ipa.command.ts +++ b/enjoy/src/commands/ipa.command.ts @@ -35,6 +35,7 @@ export const ipaCommand = async ( const fixParser = OutputFixingParser.fromLLM( new ChatOpenAI({ openAIApiKey: key, + modelName, temperature: 0, configuration: { baseURL: baseUrl, diff --git a/enjoy/src/commands/lookup.command.ts b/enjoy/src/commands/lookup.command.ts index d15f7ec0..272ad629 100644 --- a/enjoy/src/commands/lookup.command.ts +++ b/enjoy/src/commands/lookup.command.ts @@ -51,6 +51,7 @@ export const lookupCommand = async ( const fixParser = OutputFixingParser.fromLLM( new ChatOpenAI({ openAIApiKey: key, + modelName, temperature: 0, configuration: { baseURL: baseUrl, diff --git a/enjoy/src/renderer/components/conversations/conversation-form.tsx b/enjoy/src/renderer/components/conversations/conversation-form.tsx index 7e991f8f..5b8f78e3 100644 --- a/enjoy/src/renderer/components/conversations/conversation-form.tsx +++ b/enjoy/src/renderer/components/conversations/conversation-form.tsx @@ -30,7 +30,10 @@ import { Textarea, } from "@renderer/components/ui"; import { useState, useEffect, useContext } from "react"; -import { AppSettingsProviderContext } from "@renderer/context"; +import { + AppSettingsProviderContext, + AISettingsProviderContext, +} from "@renderer/context"; import { LoaderIcon } from "lucide-react"; import { useNavigate } from "react-router-dom"; @@ -68,6 +71,7 @@ export const ConversationForm = (props: { const [submitting, setSubmitting] = useState(false); const [providers, setProviders] = useState(LLM_PROVIDERS); const { EnjoyApp } = useContext(AppSettingsProviderContext); + const { openai } = useContext(AISettingsProviderContext); const navigate = useNavigate(); const refreshProviders = async () => { @@ -94,6 +98,15 @@ export const ConversationForm = (props: { refreshProviders(); }, []); + const defaultConfig = conversationDefaultConfiguration; + if (defaultConfig.engine === "openai" && openai) { + defaultConfig.configuration.model = openai.model; + defaultConfig.configuration.baseUrl = openai.baseUrl; + } + if (defaultConfig.configuration.tts.engine === "openai" && openai) { + defaultConfig.configuration.tts.baseUrl = openai.baseUrl; + } + const form = useForm>({ resolver: zodResolver(conversationFormSchema), // @ts-ignore @@ -109,10 +122,10 @@ export const ConversationForm = (props: { }, } : { - name: conversationDefaultConfiguration.name, - engine: conversationDefaultConfiguration.engine, + name: defaultConfig.name, + engine: defaultConfig.engine, configuration: { - ...conversationDefaultConfiguration.configuration, + ...defaultConfig.configuration, }, }, }); @@ -697,6 +710,7 @@ const conversationDefaultConfiguration = { engine: "openai", configuration: { model: "gpt-4-1106-preview", + baseUrl: "", roleDefinition: `你是我的英语教练。 请将我的话改写成英文。 不需要逐字翻译。 diff --git a/enjoy/src/renderer/components/ffmpeg-check.tsx b/enjoy/src/renderer/components/ffmpeg-check.tsx index c380e3ff..eaf6626d 100644 --- a/enjoy/src/renderer/components/ffmpeg-check.tsx +++ b/enjoy/src/renderer/components/ffmpeg-check.tsx @@ -27,7 +27,11 @@ export const FfmpegCheck = () => { EnjoyApp.ffmpeg.discover().then((config) => { setScanResult(config); if (config.ffmpegPath && config.ffprobePath) { - toast.success(t("ffmpegFound")); + toast.success( + t("ffmpegFoundAt", { + path: [config.ffmpegPath, config.ffprobePath].join(", "), + }) + ); refreshFfmpegConfig(); } else { toast.error(t("ffmpegNotFound")); diff --git a/enjoy/src/renderer/components/lookup-result.tsx b/enjoy/src/renderer/components/lookup-result.tsx index 4a97e90b..650f4ada 100644 --- a/enjoy/src/renderer/components/lookup-result.tsx +++ b/enjoy/src/renderer/components/lookup-result.tsx @@ -55,6 +55,7 @@ export const LookupResult = (props: { }, { key: openai.key, + modelName: openai.model, } ) .then((res) => { diff --git a/enjoy/src/renderer/components/medias/media-caption.tsx b/enjoy/src/renderer/components/medias/media-caption.tsx index 6b9b7735..a432b1c8 100644 --- a/enjoy/src/renderer/components/medias/media-caption.tsx +++ b/enjoy/src/renderer/components/medias/media-caption.tsx @@ -90,6 +90,7 @@ export const MediaCaption = (props: { ipaCommand(transcription.text, { key: openai.key, + modelName: openai.model, }) .then((result) => { if (result?.words?.length > 0) { @@ -128,6 +129,7 @@ export const MediaCaption = (props: { translateCommand(transcription.text, { key: openai.key, + modelName: openai.model, }) .then((result) => { if (result) { diff --git a/enjoy/src/renderer/pages/story.tsx b/enjoy/src/renderer/pages/story.tsx index 742a069a..21ffea3d 100644 --- a/enjoy/src/renderer/pages/story.tsx +++ b/enjoy/src/renderer/pages/story.tsx @@ -82,6 +82,7 @@ export default () => { try { const res = await extractStoryCommand(story.content, { key: openai.key, + modelName: openai.model, }); words = res.words || [];