题意:运行 OpenAI Cookbook 的聊天机器人时遇到问题
问题背景:
I'm having trouble running the chatbot app in the OpenAI Cookbook repository.
我在运行 OpenAI Cookbook 仓库中的聊天机器人应用程序时遇到了问题。
What I tried 我尝试的内容
I installed the necessary packages with 'pip install -r requirements.txt'. I made .env file with my OpenAI API Key, and inserted the code below in chatbot.py line 9.
我使用 pip install -r requirements.txt
安装了必要的包。我创建了一个包含我的 OpenAI API 密钥的 .env 文件,并将以下代码插入到 chatbot.py
第 9 行。
import os
openai.api_key = os.getenv("OPENAI_API_KEY")
The setup above is by my guess, because the doc is totally unclear about how to set up.
以上设置是我猜测的,因为文档完全没有说明如何进行设置。
I run the app in local by the command "streamlit run apps/chatbot-kickstarter/chat.py." It didn't work properly. The app run but when I entered text and pressed 'submit' button in the app, I got an error:
我通过命令 streamlit run apps/chatbot-kickstarter/chat.py
在本地运行应用程序。但它没有正常工作。应用程序启动了,但当我输入文本并按下应用程序中的 'submit' 按钮时,我收到一个错误提示:
Uncaught app exception
Traceback (most recent call last):
File "C:\Users\XXX\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "F:\PythonProjects\openai-cookbook\apps\chatbot-kickstarter\chat.py", line 71, in <module>
response = query(messages)
File "F:\PythonProjects\openai-cookbook\apps\chatbot-kickstarter\chat.py", line 51, in query
response = st.session_state['chat'].ask_assistant(question)
File "F:\PythonProjects\openai-cookbook\apps/chatbot-kickstarter\chatbot.py", line 61, in ask_assistant
if 'searching for answers' in assistant_response['content'].lower():
TypeError: string indices must be integers
I use Python 3.10.6.
I would appreciate any help or guidance to resolve these issues.
如能提供任何帮助或指导来解决这些问题,我将不胜感激。
问题解决:
Putting the key directly in chatbot.py just worked. It shouldn't be taken from environment variables.
“直接将密钥放在 `chatbot.py` 中就可以正常工作。它不应该从环境变量中获取。”