Fix chat (#1047)
* handle chat error * update scrollbar style * darkmode for scrollbar * use azure if the stt engine not found
This commit is contained in:
@@ -102,3 +102,32 @@ body {
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* make scrollbar beautiful */
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
}
|
||||
::-webkit-scrollbar-track {
|
||||
background: #f8f8f8;
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #e0e0e0;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
/* Dark mode styles for scrollbar */
|
||||
html.dark {
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
}
|
||||
::-webkit-scrollbar-track {
|
||||
background: #1a1a1a;
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #444;
|
||||
border-radius: 10px;
|
||||
}
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #555;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
} from "@renderer/context";
|
||||
import { CHAT_SYSTEM_PROMPT_TEMPLATE, LANGUAGES } from "@/constants";
|
||||
import Mustache from "mustache";
|
||||
import { SttEngineOptionEnum } from "@/types/enums";
|
||||
|
||||
export const ChatForm = (props: {
|
||||
chat?: ChatType;
|
||||
@@ -57,7 +58,7 @@ export const ChatForm = (props: {
|
||||
const { user, learningLanguage, nativeLanguage } = useContext(
|
||||
AppSettingsProviderContext
|
||||
);
|
||||
const { whisperConfig } = useContext(AISettingsProviderContext);
|
||||
const { sttEngine } = useContext(AISettingsProviderContext);
|
||||
const [editingMember, setEditingMember] =
|
||||
useState<Partial<ChatMemberType> | null>();
|
||||
|
||||
@@ -97,7 +98,7 @@ export const ChatForm = (props: {
|
||||
topic: "Casual Chat.",
|
||||
language: learningLanguage,
|
||||
config: {
|
||||
sttEngine: whisperConfig.service,
|
||||
sttEngine,
|
||||
},
|
||||
members: [
|
||||
{
|
||||
@@ -191,22 +192,32 @@ export const ChatForm = (props: {
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="local">{t("local")}</SelectItem>
|
||||
<SelectItem value="azure">{t("enjoyAzure")}</SelectItem>
|
||||
<SelectItem value="cloudflare">
|
||||
<SelectItem value={SttEngineOptionEnum.LOCAL}>
|
||||
{t("local")}
|
||||
</SelectItem>
|
||||
<SelectItem value={SttEngineOptionEnum.ENJOY_AZURE}>
|
||||
{t("enjoyAzure")}
|
||||
</SelectItem>
|
||||
<SelectItem value={SttEngineOptionEnum.ENJOY_CLOUDFLARE}>
|
||||
{t("enjoyCloudflare")}
|
||||
</SelectItem>
|
||||
<SelectItem value="openai">OpenAI</SelectItem>
|
||||
<SelectItem value={SttEngineOptionEnum.OPENAI}>
|
||||
{t("openai")}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormDescription>
|
||||
{form.watch("config.sttEngine") === "local" &&
|
||||
{form.watch("config.sttEngine") ===
|
||||
SttEngineOptionEnum.LOCAL &&
|
||||
t("localSpeechToTextDescription")}
|
||||
{form.watch("config.sttEngine") === "azure" &&
|
||||
{form.watch("config.sttEngine") ===
|
||||
SttEngineOptionEnum.ENJOY_AZURE &&
|
||||
t("enjoyAzureSpeechToTextDescription")}
|
||||
{form.watch("config.sttEngine") === "cloudflare" &&
|
||||
{form.watch("config.sttEngine") ===
|
||||
SttEngineOptionEnum.ENJOY_CLOUDFLARE &&
|
||||
t("enjoyCloudflareSpeechToTextDescription")}
|
||||
{form.watch("config.sttEngine") === "openai" &&
|
||||
{form.watch("config.sttEngine") ===
|
||||
SttEngineOptionEnum.OPENAI &&
|
||||
t("openaiSpeechToTextDescription")}
|
||||
</FormDescription>
|
||||
</FormItem>
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
ScrollArea,
|
||||
Separator,
|
||||
Textarea,
|
||||
toast,
|
||||
} from "@renderer/components/ui";
|
||||
import { ReactElement, useContext, useEffect, useRef, useState } from "react";
|
||||
import { LiveAudioVisualizer } from "react-audio-visualize";
|
||||
@@ -339,6 +340,9 @@ const ChatSuggestionButton = (props: {
|
||||
cacheKey: contextCacheKey,
|
||||
})
|
||||
.then((res) => setSuggestions(res.suggestions))
|
||||
.catch((err) => {
|
||||
toast.error(err.message);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
|
||||
@@ -194,13 +194,14 @@ export const ChatSessionProvider = ({
|
||||
return toast.warning(t("itsYourTurn"));
|
||||
}
|
||||
|
||||
const llm = buildLlm(member.agent);
|
||||
const prompt = ChatPromptTemplate.fromMessages([
|
||||
["system", CHAT_SYSTEM_PROMPT_TEMPLATE],
|
||||
["user", "{input}"],
|
||||
]);
|
||||
const chain = prompt.pipe(llm);
|
||||
try {
|
||||
const llm = buildLlm(member.agent);
|
||||
const prompt = ChatPromptTemplate.fromMessages([
|
||||
["system", CHAT_SYSTEM_PROMPT_TEMPLATE],
|
||||
["user", "{input}"],
|
||||
]);
|
||||
const chain = prompt.pipe(llm);
|
||||
|
||||
setSubmitting(true);
|
||||
const reply = await chain.invoke({
|
||||
name: member.agent.name,
|
||||
@@ -244,6 +245,9 @@ export const ChatSessionProvider = ({
|
||||
.then((message) =>
|
||||
dispatchChatMessages({ type: "append", record: message })
|
||||
)
|
||||
.catch((error) => {
|
||||
toast.error(error.message);
|
||||
})
|
||||
.finally(() => setSubmitting(false));
|
||||
} catch (err) {
|
||||
setSubmitting(false);
|
||||
|
||||
@@ -50,7 +50,10 @@ export const useChatMessage = (chat: ChatType) => {
|
||||
})
|
||||
.then((message) =>
|
||||
dispatchChatMessages({ type: "append", record: message })
|
||||
);
|
||||
)
|
||||
.catch((error) => {
|
||||
toast.error(error.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -109,7 +109,8 @@ export const useTranscribe = () => {
|
||||
result = await transcribeByOpenAi(
|
||||
new File([blob], "audio.mp3", { type: "audio/mp3" })
|
||||
);
|
||||
} else if (service === SttEngineOptionEnum.ENJOY_AZURE) {
|
||||
} else {
|
||||
// Azure AI is the default service
|
||||
result = await transcribeByAzureAi(
|
||||
new File([blob], "audio.wav", { type: "audio/wav" }),
|
||||
language,
|
||||
@@ -118,8 +119,6 @@ export const useTranscribe = () => {
|
||||
targetType,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
throw new Error(t("whisperServiceNotSupported"));
|
||||
}
|
||||
|
||||
let transcript = result.text;
|
||||
|
||||
Reference in New Issue
Block a user