From 97abedc39c301433682a36a919b7d47a33e1e731 Mon Sep 17 00:00:00 2001 From: Hugh Lyu Date: Mon, 8 Jan 2024 19:18:20 +0800 Subject: [PATCH] fix(ui): render latex box expression in chat window --- api/app/main.py | 2 +- api/app/routers/chat_router.py | 2 +- api/app/services/chat_service.py | 2 +- ui/src/components/Markdown/index.tsx | 7 ++++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/app/main.py b/api/app/main.py index 7eb0e15a..1a831326 100644 --- a/api/app/main.py +++ b/api/app/main.py @@ -16,7 +16,7 @@ allow_headers=["*"] ) -app.include_router(chat_router.router, prefix="/chats", tags=["Chat"], trailing_slash=False) +app.include_router(chat_router.router, prefix="/chats", tags=["Chat"]) app.include_router(message_router.router, prefix="/messages", tags=["Message"]) app.include_router(dev_router.router, prefix="/dev", tags=["Dev"]) app.include_router(extension_router.router, prefix="/extensions", tags=["Extension"]) diff --git a/api/app/routers/chat_router.py b/api/app/routers/chat_router.py index b3f7b80a..9b4c58e2 100644 --- a/api/app/routers/chat_router.py +++ b/api/app/routers/chat_router.py @@ -4,7 +4,7 @@ from ..services.chat_service import ChatService from ..dependencies import get_chat_service -router = APIRouter(trailing_slash=False) +router = APIRouter() @router.get('', summary="Get existing chats", response_model=List[Chat]) async def get_chats(service: ChatService = Depends(get_chat_service)): diff --git a/api/app/services/chat_service.py b/api/app/services/chat_service.py index a8961fe7..6a108f6a 100644 --- a/api/app/services/chat_service.py +++ b/api/app/services/chat_service.py @@ -20,7 +20,7 @@ async def get_chats(self): async def create_chat(self, chat: dict): """Create a new chat session""" - new_chat = self.pocketbase_client.create_chat(self.token, chat) + new_chat = self.pocketbase_client.create_chat(self.user, chat) return new_chat async def start_chat(self, message: dict, chat_id: str): diff --git a/ui/src/components/Markdown/index.tsx b/ui/src/components/Markdown/index.tsx index db487e58..68ea9a54 100644 --- a/ui/src/components/Markdown/index.tsx +++ b/ui/src/components/Markdown/index.tsx @@ -87,6 +87,11 @@ const Markdown = ({ const markdownWithImages: string = preprocessImageTags(children as string); + const processedMarkdown = markdownWithImages.replace( + /\\\((.*?)\\\)/g, + (match, p1) => `$${p1}$` + ); + return ( - {markdownWithImages} + {processedMarkdown} ); };