problem with running OpenAI Cookbook‘s chatbot

题意:运行 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` 中就可以正常工作。它不应该从环境变量中获取。”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值