From 98833419240a2ef55b8dd270e9b50cdb340f6f58 Mon Sep 17 00:00:00 2001 From: liunux4odoo Date: Wed, 9 Aug 2023 10:48:37 +0800 Subject: [PATCH] update server.chat.*: set default value [] to history parameter. --- server/chat/chat.py | 14 +++++++------- server/chat/knowledge_base_chat.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/server/chat/chat.py b/server/chat/chat.py index 27d880e..a0c60b5 100644 --- a/server/chat/chat.py +++ b/server/chat/chat.py @@ -13,15 +13,15 @@ from server.chat.utils import History def chat(query: str = Body(..., description="用户输入", example="恼羞成怒"), - history: Optional[List[History]] = Body(..., - description="历史对话", - example=[ - {"role": "user", "content": "我们来玩成语接龙,我先来,生龙活虎"}, - {"role": "assistant", "content": "虎头虎脑"}] - ), + history: List[History] = Body([], + description="历史对话", + example=[ + {"role": "user", "content": "我们来玩成语接龙,我先来,生龙活虎"}, + {"role": "assistant", "content": "虎头虎脑"}] + ), ): async def chat_iterator(query: str, - history: Optional[List[History]] + history: List[History] = [], ) -> AsyncIterable[str]: callback = AsyncIteratorCallbackHandler() diff --git a/server/chat/knowledge_base_chat.py b/server/chat/knowledge_base_chat.py index 1a00abf..5c49175 100644 --- a/server/chat/knowledge_base_chat.py +++ b/server/chat/knowledge_base_chat.py @@ -19,14 +19,14 @@ import json def knowledge_base_chat(query: str = Body(..., description="用户输入", example="你好"), knowledge_base_name: str = Body(..., description="知识库名称", example="samples"), top_k: int = Body(VECTOR_SEARCH_TOP_K, description="匹配向量数"), - history: Optional[List[History]] = Body(..., - description="历史对话", - example=[ - {"role": "user", - "content": "我们来玩成语接龙,我先来,生龙活虎"}, - {"role": "assistant", - "content": "虎头虎脑"}] - ), + history: List[History] = Body([], + description="历史对话", + example=[ + {"role": "user", + "content": "我们来玩成语接龙,我先来,生龙活虎"}, + {"role": "assistant", + "content": "虎头虎脑"}] + ), ): kb = KBServiceFactory.get_service_by_name(knowledge_base_name) if kb is None: