Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display translated messages in chat #19

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function Chat(params: { params: { project_id: string, chat_id: st
if (message.stop) setIsTyping(false);
};

const converseMutation = useMutation(() => API.chat.converse(project_id, chat_id, newChat, language, openai_key, streamChatMessage), {
const converseMutation = useMutation(() => API.chat.converse(project_id, chat_id, newChat, language, openai_key, streamChatMessage, 20), {
onSuccess: async () => {
await chatQuery.refetch();
setNewChat("");
Expand Down
11 changes: 8 additions & 3 deletions src/components/chatblock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type AudioStatus = "unloaded" | "loading" | "playing" | "paused" | "stopped";
export default function ChatBlock(props: { message?: ChatMessage, loading?: boolean, autoplay?: boolean, cursor?: boolean }) {

const { message, loading, cursor, autoplay } = props;
const cursorText = cursor ? (message?.message?.length || 0) % 2 === 0 ? "|" : "" : "";
const cursorText = cursor ? (message?.original_message?.length || 0) % 2 === 0 ? "|" : "" : "";
const [audio, setAudio] = useState<HTMLAudioElement | null>(null);
const [audioStatus, setAudioStatus] = useState<AudioStatus>("unloaded");
const [percentagePlayed, setPercentagePlayed] = useState(0);
Expand All @@ -21,7 +21,7 @@ export default function ChatBlock(props: { message?: ChatMessage, loading?: bool
return regex.test(str);
}

const chatMessage = message?.message + cursorText || "";
const chatMessage = (message?.message != message?.original_message ? message?.message : message?.original_message) + cursorText;

const getMessageSegments = (): { highlightText: string; blackText: string } => {
const messageLength = chatMessage.length || 0;
Expand Down Expand Up @@ -101,7 +101,12 @@ export default function ChatBlock(props: { message?: ChatMessage, loading?: bool
(
<div className="flex flex-col justify-center">
<ReactMarkdown rehypePlugins={[rehypeRaw]} remarkPlugins={[remarkGfm]} className="markdown-render">
{audioStatus === "unloaded" ? (message?.message + cursorText || "") : `<span className="text-green-600">${highlightText}</span><span>${blackText}</span>`}
{
(audioStatus === "unloaded" ?
((message?.message || message?.original_message) + cursorText || "") :
`<span className="text-green-600">${highlightText}</span><span>${blackText}</span>`
) + (message?.message != message?.original_message ? `<hr className="border-gray-300 my-4"></hr>${message?.original_message || ""}` : "")
}
</ReactMarkdown>
{message?.messageType === ChatMessageType.AYUSHMA && message?.ayushma_audio_url && (
<div className="flex gap-1 justify-left">
Expand Down
1 change: 1 addition & 0 deletions src/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Document = BaseModelType & {
export type ChatMessage = BaseModelType & {
messageType: ChatMessageType,
message: string,
translated_message?: string,
reference_documents?: Document[],
ayushma_audio_url?: string,
language: string,
Expand Down