Langchain-Chatchat icon indicating copy to clipboard operation
Langchain-Chatchat copied to clipboard

[BUG] TypeError: ApiRequest.knowledge_base_chat() got an unexpected keyword argument 'conversation_id'

Open Liwan-Chen opened this issue 1 year ago • 1 comments

保存知识库会话到database 在设计保存知识库会话到数据库时, 在ApiRequest.knowledge_base_chat() 中加入conversation_id , 但是会报错TypeError: ApiRequest.knowledge_base_chat() got an unexpected keyword argument 'conversation_id'

Liwan-Chen avatar Mar 14 '24 05:03 Liwan-Chen

嗨,@Liwan-Chen!很高兴再次见到你。希望一切都好!

根据您提供的上下文,ApiRequest.knowledge_base_chat() 方法当前并不接受 conversation_id 参数。这可能是导致您遇到 TypeError: ApiRequest.knowledge_base_chat() got an unexpected keyword argument 'conversation_id' 错误的原因。

如果您希望在保存知识库会话到数据库时使用 conversation_id,您可能需要修改 ApiRequest.knowledge_base_chat() 方法以接受此参数。然后,您可以在方法内部使用此参数,例如,将其传递给 add_conversation_to_db 函数。

请注意,任何对代码库的修改都应遵循良好的软件开发实践,包括编写相应的单元测试以确保新代码的正确性,以及更新任何相关的文档以反映新的 API 行为。

这是一个可能的修改示例:

async def knowledge_base_chat(self, query: str, knowledge_base_name: str, top_k: int = 5, score_threshold: float = 0.0, history: List[Dict[str, str]] = None, stream: bool = False, model_name: str = 'ChatGLM', temperature: float = 0.8, max_tokens: int = 1000, prompt_name: str = 'default', request: Request = None, conversation_id: str = None):
    # ... existing code ...
    conversation = await add_conversation_to_db(conversation_id, query, response)
    # ... existing code ...

在这个修改中,knowledge_base_chat() 方法现在接受一个新的 conversation_id 参数,并将其传递给 add_conversation_to_db 函数。

请注意,这只是一个示例,您可能需要根据您的具体需求进行调整。如果您在实施这个修改时遇到任何问题,或者需要进一步的帮助,请随时向我提问。

源代码参考

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Mar 14 '24 05:03 dosubot[bot]