TGLTommy / LangChain_LLM_ChatBot

基于LLM和LangChain实现基于本地文档的QA chatbot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

执行chatbot.py 执行, 构建vectorstore之后, 查询文档报错

beyondme121 opened this issue · comments

遇到一个问题,使用streamlit构建的应用,执行chatbot.py脚本,第一次查询可以得到结果,第二次再输入查询,报错信息
ValueError: Unsupported chat history format: <class 'str'>. Full chat history: Human

  • 使用的本地服务器部署的ChatGLM模型,没有使用openai

报错位置
def process_user_input(user_input):
if st.session_state.conversation is not None:
# 调用函数st.session_state.conversation,并把用户输入的内容作为一个问题传入,返回响应。
response = st.session_state.conversation({'question': user_input})
# session状态是Streamlit中的一个特性,允许在用户的多个请求之间保存数据。
st.session_state.chat_history = response['chat_history']

顺便看了一下源码
def _get_chat_history(chat_history: List[CHAT_TURN_TYPE]) -> str:
buffer = ""
for dialogue_turn in chat_history:
if isinstance(dialogue_turn, BaseMessage):
role_prefix = _ROLE_MAP.get(dialogue_turn.type, f"{dialogue_turn.type}: ")
buffer += f"\n{role_prefix}{dialogue_turn.content}"
elif isinstance(dialogue_turn, tuple):
human = "Human: " + dialogue_turn[0]
ai = "Assistant: " + dialogue_turn[1]
buffer += "\n" + "\n".join([human, ai])