MoneyPrinterTurbo icon indicating copy to clipboard operation
MoneyPrinterTurbo copied to clipboard

运行报错:AttributeError: 'str' object has no attribute 'choices'

Open kid9547 opened this issue 10 months ago • 5 comments

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 tm.start(task_id=task_id, params=cfg) File "E:\MoneyPrinterTurbo\app\services\task.py", line 51, in start video_script = llm.generate_script(video_subject=video_subject, language=params.video_language, File "E:\MoneyPrinterTurbo\app\services\llm.py", line 118, in generate_script response = _generate_response(prompt=prompt) File "E:\MoneyPrinterTurbo\app\services\llm.py", line 86, in _generate_response content = response.choices[0].message.content

根据报错信息看起来问题出在_generate_response函数返回的对象类型不是预期的类型。报错信息显示'str' object has no attribute 'choices',意味着response是一个字符串而不是期望的对象,因此无法通过choices属性来访问内容。但是我不知怎么解决0.0

kid9547 avatar Mar 28 '24 05:03 kid9547

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'`

希望解决一下,谢谢。

GodJones avatar Mar 28 '24 08:03 GodJones

这个问题是由于OPENAI没有返回正确的回复,大概率是网络原因导致的。 使用VPN,或者找个代理,设置 openai_base_url ,应该就可以解决了

harry0703 avatar Mar 28 '24 09:03 harry0703

这个问题是由于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 tm.start(task_id=task_id, params=cfg) File "E:\MoneyPrinterTurbo\app\services\task.py", line 51, in start video_script = llm.generate_script(video_subject=video_subject, language=params.video_language, File "E:\MoneyPrinterTurbo\app\services\llm.py", line 118, in generate_script response = _generate_response(prompt=prompt) File "E:\MoneyPrinterTurbo\app\services\llm.py", line 86, in _generate_response content = response.choices[0].message.content

kid9547 avatar Mar 29 '24 05:03 kid9547

设置如下,有些部分我用*代替了,其他没有改变 ########## 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"

kid9547 avatar Mar 29 '24 05:03 kid9547

openai_base_url 的配置看起来是错的? 一般是类似这样

openai_base_url = "http://xxx.xxxx.com/v1/"

harry0703 avatar Mar 29 '24 10:03 harry0703

我也发生了这个问题,我配置的转发地址是正确可用的,但在此项目无法使用。

dx1995 avatar Mar 30 '24 03:03 dx1995

@dx1995 你可以使用 curl 直接用的 转发地址 测试看看能不能用 后面计划提供一个公共的proxy地址出来 国内好多用户,卡在了这个环节

harry0703 avatar Mar 30 '24 07:03 harry0703

(MoneyPrinterTurbo) C:\Users\HASEE\MoneyPrinterTurbo>curl https://api.uu.ci

UU免费接口

(MoneyPrinterTurbo) C:\Users\HASEE\MoneyPrinterTurbo>

dx1995 avatar Mar 30 '24 13:03 dx1995

openai_base_url 的配置看起来是错的? 一般是类似这样

openai_base_url = "http://xxx.xxxx.com/v1/"

感谢,的确是我的openai_base_url写错了,少写了/v1 0.0

kid9547 avatar Apr 01 '24 01:04 kid9547