1
resposta

ERRO

href="?__debugger__=yes&cmd=resource&f=console.png">

AttributeError

AttributeError: 'str' object has no attribute 'choices'

Traceback (most recent call last)

File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py",
line 1488,
in __call__
return self.wsgi_app(environ, start_response)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py",
line 1466,
in wsgi_app

response = self.handle_exception(e)
           ^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py",
line 1463,
in wsgi_app

response = self.full_dispatch_request()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py",
line 872,
in full_dispatch_request

rv = self.handle_user_exception(e)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py",
line 870,
in full_dispatch_request

rv = self.dispatch_request()
     ^^^^^^^^^^^^^^^^^^^^^^^
     
File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py",
line 855,
in dispatch_request

return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\rcssa\chatbot\app.py",
line 65,
in chat

texto_resposta = resposta.choices[0].message.content
                 ^^^^^^^^^^^^^^^^
                 
AttributeError: 'str' object has no attribute 'choices'

This is the Copy/Paste friendly version of the traceback.

Traceback (most recent call last):<br>  File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1488, in __call__<br>    return self.wsgi_app(environ, start_response)<br>           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>  File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1466, in wsgi_app<br>    response = self.handle_exception(e)<br>               ^^^^^^^^^^^^^^^^^^^^^^^^<br>  File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1463, in wsgi_app<br>    response = self.full_dispatch_request()<br>               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>  File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 872, in full_dispatch_request<br>    rv = self.handle_user_exception(e)<br>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>  File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 870, in full_dispatch_request<br>    rv = self.dispatch_request()<br>         ^^^^^^^^^^^^^^^^^^^^^^^<br>  File "C:\Users\rcssa\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 855, in dispatch_request<br>    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]<br>           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>  File "C:\Users\rcssa\chatbot\app.py", line 65, in chat<br>    texto_resposta = resposta.choices[0].message.content<br>                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>AttributeError: 'str' object has no attribute 'choices'<br>

The debugger caught an exception in your WSGI application. You can now
look at the traceback which led to the error.
If you enable JavaScript you can also use additional features such as code
execution (if the evalex feature is enabled), automatic pasting of the
exceptions and much more.
1 resposta

Oii, Ronan! Tudo bem?

Esse erro significa que há uma tentativa de acessar o atributo 'choices' de uma string, porém o atributo não existe para strings.

É importante revisar se o atributo e o tipo de dados passados estão corretos. Para isso você pode acessar o código feito pelo Instrutor, até o momento, para certificar que está tudo certinho: clique aqui para ser redirecionado.

E, peço por gentileza, que compartilhe o seu código para que eu possa te ajudar de forma mais assertiva.

Qualquer dúvida, conte conosco.

Bons estudos, Ronan!