may config tts baseURL

This commit is contained in:
an-lee
2024-01-11 11:07:30 +08:00
parent 7e0dfb57bf
commit ccf07b7948
5 changed files with 33 additions and 1 deletions

View File

@@ -84,6 +84,7 @@
"ttsEngine": "TTS engine",
"ttsModel": "TTS model",
"ttsVoice": "TTS voice",
"ttsBaseUrl": "TTS base URL",
"notFound": "Conversation not found",
"contentRequired": "Content required"
},

View File

@@ -84,6 +84,7 @@
"ttsEngine": "TTS 引擎",
"ttsModel": "TTS 模型",
"ttsVoice": "TTS 声音",
"ttsBaseUrl": "TTS 请求地址",
"notFound": "未找到对话",
"contentRequired": "对话内容不能为空"
},

View File

@@ -161,6 +161,7 @@ export class Speech extends Model<Speech> {
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<Speech> {
}
const openai = new OpenAI({
apiKey: key,
baseURL: baseUrl,
});
logger.debug("baseURL", openai.baseURL);
const file = await openai.audio.speech.create({
input: text,

View File

@@ -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: {
</FormItem>
)}
/>
<FormField
control={form.control}
name="configuration.tts.baseUrl"
render={({ field }) => (
<FormItem>
<FormLabel>{t("models.conversation.ttsBaseUrl")}</FormLabel>
<Input {...field} />
<FormDescription>
{t("models.conversation.baseUrl")}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</div>
</ScrollArea>
@@ -584,7 +607,9 @@ export const ConversationForm = (props: {
)}
<Button
disabled={submitting || (conversation.id && !form.formState.isDirty)}
disabled={
submitting || (conversation.id && !form.formState.isDirty)
}
className="w-full h-12"
size="lg"
type="submit"
@@ -688,6 +713,7 @@ const conversationDefaultConfiguration = {
frequencyPenalty: 0,
historyBufferSize: 0,
tts: {
baseUrl: "",
engine: "openai",
model: "tts-1",
voice: "alloy",

View File

@@ -54,6 +54,7 @@ export const AssistantMessageComponent = (props: {
engine: configuration?.tts?.engine,
model: configuration?.tts?.model,
voice: configuration?.tts?.voice,
baseUrl: configuration?.tts?.baseUrl,
})
.then((speech) => {
setSpeech(speech);