Skip to content

Commit

Permalink
fix: first dialog not show content
Browse files Browse the repository at this point in the history
  • Loading branch information
lcxadml committed Mar 25, 2024
1 parent e22ecb5 commit 1a255cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion web/components/chat/chat-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ChatContainer = () => {
const contextTemp = list[list.length - 1]?.context;
if (contextTemp) {
try {
const contextObj = JSON.parse(contextTemp);
const contextObj = typeof contextTemp === 'string' ? JSON.parse(contextTemp) : contextTemp;
setChartsData(contextObj?.template_name === 'report' ? contextObj?.charts : undefined);
} catch (e) {
setChartsData(undefined);
Expand Down
2 changes: 1 addition & 1 deletion web/components/chat/db-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function DbEditor() {
key: i + '',
label: item?.title,
children: (
<div className="flex flex-col h-full">
<div className="flex flex-col h-[702px]">
<DbEditorContent
editorValue={item}
handleChange={(value) => {
Expand Down
23 changes: 17 additions & 6 deletions web/hooks/use-chat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { EventStreamContentType, fetchEventSource } from '@microsoft/fetch-event-source';
import { message } from 'antd';
import { useCallback, useEffect, useMemo } from 'react';
import { useCallback, useContext, useEffect, useMemo } from 'react';
import i18n from '@/app/i18n';
import { ChatContext } from '@/app/chat-context';

type Props = {
queryAgentURL?: string;
Expand All @@ -19,6 +20,7 @@ type ChatParams = {

const useChat = ({ queryAgentURL = '/api/v1/chat/completions' }: Props) => {
const ctrl = useMemo(() => new AbortController(), []);
const { scene } = useContext(ChatContext);

const chat = useCallback(
async ({ data, chatId, onMessage, onClose, onDone, onError }: ChatParams) => {
Expand Down Expand Up @@ -61,16 +63,25 @@ const useChat = ({ queryAgentURL = '/api/v1/chat/completions' }: Props) => {
onmessage: (event) => {
let message = event.data;
try {
message = JSON.parse(message).vis;
if (scene === 'chat_agent') {
message = JSON.parse(message).vis;
} else {
message = JSON.parse(message);
}
} catch (e) {
message.replaceAll('\\n', '\n');
}
if (message === '[DONE]') {
onDone?.();
} else if (message?.startsWith('[ERROR]')) {
onError?.(message?.replace('[ERROR]', ''));
if (typeof message === 'string') {
if (message === '[DONE]') {
onDone?.();
} else if (message?.startsWith('[ERROR]')) {
onError?.(message?.replace('[ERROR]', ''));
} else {
onMessage?.(message);
}
} else {
onMessage?.(message);
onDone?.();
}
},
});
Expand Down

0 comments on commit 1a255cb

Please sign in to comment.