A WeChat chatbot based on fastapi + langchain + itchat, inspired by the chatgpt-on-wechat project
Your star is the biggest encouragement to me?
Note
This project is only for personal learning and communication. Users must abide by OpenAI's terms of use and **Chinese laws and regulations** and may not use it for illegal purposes.
According to the requirements of the "Interim Measures for the Management of Generative Artificial Intelligence Services", please do not provide any unregistered generative artificial intelligence services to the public in China.
When executed in the default assistant mode, various tools will be configured, and LLM automatically selects appropriate tools to call, such as calling the DuCKDuckGo search engine, summarizing the search results and returning them to the user.
You need to provide a set of documents and then, based on the user's question, return the most relevant document snippets.
The OpenAI account preparation project uses the OpenAI interface by default. You need to go to the OpenAI registration page to create an account. After creating the account, go to the API management page to create an API Key and save it. The interface requires overseas network access and binding of credit card payment.
Add API Key to environment variables
export OPENAI_API_KEY= " sk-xxxxxxxxxxxxxxxxxxxxxx "
Install Python The code is developed and tested through Python3.10. You need to install python 3.10. After downloading, click the installation fool-proof next step.
redis is used to store WeChat user chat records
docker run -d -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
poetry install
or
pip install -r requirements.txt
cp config/.env.example config/.env
uvicorn src.main:app
Configure in config/.env file
# openai 模型
OPENAI_MODEL= " gpt-3.5-turbo-1106 "
# openai api key
OPENAI_API_KEY= " your-openai-api-key "
# 模型 temperature
AI_TEMPERATURE=0.7
# 模型系统角色提示词
AI_SYSTEM_ROLE_PROMPT= "系统: "
# 聊天记录保存最大长度
CHAT_MAX_MESSAGE_HISTORY_LENGTH=10
# 触发聊天记录总结的阈值
CHAT_MESSAGE_HISTORY_SUMMARY_THRESHOLD=5
# 微信是否开启热重载
WECHAT_HOT_RELOAD=False
# 微信用户数据保存路径
WECHAT_USER_DATA_STORAGE_PATH= " wechat.pkl "