From ccf07b7948199161bb2f41688fb2c5eea27a6e9e Mon Sep 17 00:00:00 2001 From: an-lee Date: Thu, 11 Jan 2024 11:07:30 +0800 Subject: [PATCH] may config tts baseURL --- enjoy/src/i18n/en.json | 1 + enjoy/src/i18n/zh-CN.json | 1 + enjoy/src/main/db/models/speech.ts | 3 ++ .../conversations/conversation-form.tsx | 28 ++++++++++++++++++- .../components/messages/assistant-message.tsx | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index bb9b9657..37d71e4c 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -84,6 +84,7 @@ "ttsEngine": "TTS engine", "ttsModel": "TTS model", "ttsVoice": "TTS voice", + "ttsBaseUrl": "TTS base URL", "notFound": "Conversation not found", "contentRequired": "Content required" }, diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index 68c11f38..87480325 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -84,6 +84,7 @@ "ttsEngine": "TTS 引擎", "ttsModel": "TTS 模型", "ttsVoice": "TTS 声音", + "ttsBaseUrl": "TTS 请求地址", "notFound": "未找到对话", "contentRequired": "对话内容不能为空" }, diff --git a/enjoy/src/main/db/models/speech.ts b/enjoy/src/main/db/models/speech.ts index 3ce0808c..30c883f3 100644 --- a/enjoy/src/main/db/models/speech.ts +++ b/enjoy/src/main/db/models/speech.ts @@ -161,6 +161,7 @@ export class Speech extends Model { engine = "openai", model = "tts-1", voice = "alloy", + baseUrl, } = configuration || {}; logger.debug("Generating speech", { engine, model, voice }); @@ -176,7 +177,9 @@ export class Speech extends Model { } const openai = new OpenAI({ apiKey: key, + baseURL: baseUrl, }); + logger.debug("baseURL", openai.baseURL); const file = await openai.audio.speech.create({ input: text, diff --git a/enjoy/src/renderer/components/conversations/conversation-form.tsx b/enjoy/src/renderer/components/conversations/conversation-form.tsx index a28d414c..69db60b9 100644 --- a/enjoy/src/renderer/components/conversations/conversation-form.tsx +++ b/enjoy/src/renderer/components/conversations/conversation-form.tsx @@ -53,6 +53,7 @@ const conversationFormSchema = z.object({ engine: z.enum(["openai"]).default("openai"), model: z.string().default("tts-1"), voice: z.string().optional(), + baseUrl: z.string().optional(), }) .optional(), }) @@ -102,6 +103,9 @@ export const ConversationForm = (props: { engine: conversation.engine, configuration: { ...conversation.configuration, + tts: { + ...conversation.configuration?.tts, + }, }, } : { @@ -128,6 +132,10 @@ export const ConversationForm = (props: { configuration.baseUrl = LLM_PROVIDERS[engine]?.baseUrl; } + if (!configuration.tts.baseUrl) { + configuration.tts.baseUrl = LLM_PROVIDERS[engine]?.baseUrl; + } + if (conversation?.id) { EnjoyApp.conversations .update(conversation.id, { @@ -547,6 +555,21 @@ export const ConversationForm = (props: { )} /> + + ( + + {t("models.conversation.ttsBaseUrl")} + + + {t("models.conversation.baseUrl")} + + + + )} + /> @@ -584,7 +607,9 @@ export const ConversationForm = (props: { )}