- 01 实现基于 streamlit + OpenAI 的QA问答(文件格式:PDF)
streamlit run chatbot.py
- 02 实现基于 gradio + OpenAI 的QA问答(文件格式:PDF)
gradio chatbot_gradio.py
或者
访问HuggingFace Space体验:
https://huggingface.co/spaces/Tommy930/chatbot-PDF
基于LLM和LangChain实现基于本地文档的QA chatbot
遇到一个问题,使用streamlit构建的应用,执行chatbot.py脚本,第一次查询可以得到结果,第二次再输入查询,报错信息
ValueError: Unsupported chat history format: <class 'str'>. Full chat history: Human
报错位置
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])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.