MoneyPrinterTurbo
MoneyPrinterTurbo copied to clipboard
运行报错:AttributeError: 'str' object has no attribute 'choices'
Traceback如下:
File "C:\Python310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 542, in _run_script
exec(code, module.dict)
File "E:\MoneyPrinterTurbo\webui\Main.py", line 264, in
根据报错信息看起来问题出在_generate_response函数返回的对象类型不是预期的类型。报错信息显示'str' object has no attribute 'choices',意味着response是一个字符串而不是期望的对象,因此无法通过choices属性来访问内容。但是我不知怎么解决0.0
macOS 14.4.1 在运行的时候提示报错
报错信息如下
`video subject: 生活如此美好
- number of paragraphs: 1
2024-03-28 16:15:58 | INFO | "./app/services/llm.py:15": _generate_response - llm provider: openai
2024-03-28 16:15:59.201 Uncaught app exception
Traceback (most recent call last):
File "/opt/miniconda3/envs/MoneyPrinterTurbo/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 542, in _run_script
exec(code, module.dict)
File "/Users/mac/AiCreate/MoneyPrinterTurbo/webui/Main.py", line 117, in
script = llm.generate_script(video_subject=cfg.video_subject, language=cfg.video_language) File "/Users/mac/AiCreate/MoneyPrinterTurbo/app/services/llm.py", line 105, in generate_script response = _generate_response(prompt=prompt) File "/Users/mac/AiCreate/MoneyPrinterTurbo/app/services/llm.py", line 73, in _generate_response content = response.choices[0].message.content AttributeError: 'str' object has no attribute 'choices'`
希望解决一下,谢谢。
这个问题是由于OPENAI没有返回正确的回复,大概率是网络原因导致的。
使用VPN
,或者找个代理,设置 openai_base_url
,应该就可以解决了
这个问题是由于OPENAI没有返回正确的回复,大概率是网络原因导致的。 使用
VPN
,或者找个代理,设置openai_base_url
,应该就可以解决了
我确信我设置好了openai_base_url,并且也用chatbox等软件测试了api和转发地址的有效性,但是还是同样的报错:
AttributeError: 'str' object has no attribute 'choices'
Traceback:
File "C:\Python310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 542, in _run_script
exec(code, module.dict)
File "E:\MoneyPrinterTurbo\webui\Main.py", line 264, in
设置如下,有些部分我用*
代替了,其他没有改变
########## OpenAI API Key
# Visit https://openai.com/api/ for details on obtaining an API key.
openai_api_key = "sk-b2h9IIfzAb5JWfNp*****************************************"
openai_base_url = "https://api.********.cn" # no need to set it unless you want to use your own proxy
openai_model_name = "gpt-4-turbo-preview"
openai_base_url
的配置看起来是错的?
一般是类似这样
openai_base_url = "http://xxx.xxxx.com/v1/"
我也发生了这个问题,我配置的转发地址是正确可用的,但在此项目无法使用。
@dx1995 你可以使用 curl
直接用的 转发地址 测试看看能不能用
后面计划提供一个公共的proxy地址出来
国内好多用户,卡在了这个环节
(MoneyPrinterTurbo) C:\Users\HASEE\MoneyPrinterTurbo>curl https://api.uu.ci
(MoneyPrinterTurbo) C:\Users\HASEE\MoneyPrinterTurbo>
openai_base_url
的配置看起来是错的? 一般是类似这样openai_base_url = "http://xxx.xxxx.com/v1/"
感谢,的确是我的openai_base_url
写错了,少写了/v1
0.0