Streamlit Tutorial: Build a ChatGPT Like App

I am using streamlit version 1.28.1 and openai version: 1.1.1.

It seem the tutorial “Build a ChatGPT Like App” is probably build on a different version of either streamlit or openai. If you literally copy the code across and run it on the above version, it doesn’t work. I have two questions:

  1. May I know the tutorial was build on which versions (Streamlit/openai)?
  2. I manage to resolve most of the issues except this error. Any one know what is the issue?

AttributeError: ‘list’ object has no attribute ‘delta’
Traceback:

File "C:\Users\xxxx\Documents\test\myenv\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)File "C:\Users\xxxx\demo.py", line 36, in <module>
    full_response += response.choices.delta.get("content","")

This is the code block (literally from the tutorial) that is probably giving the error above:
full_response += response.choices[0].delta.get(“content”, “”)
message_placeholder.markdown(full_response + “▌”)
message_placeholder.markdown(full_response)
st.session_state.messages.append({“role”: “assistant”, “content”: full_response})

Hi @gsoonh

Perhaps you are referring to the tutorial video on YouTube (https://youtube.com/watch?v=Z41pEtTAgfs).

The error that you’ve encountered:

seems to come from the fact that delta is expecting a single value whereas a list is provided.

As shown in the GitHub repo (https://github.com/dataprofessor/openai-chatbot/blob/master/streamlit_app.py) on Line 36, single value from selected from choices via choices[0].

It seems that you may have forgot to append [0] to choices

And the code block that you’ve mentioned had [0] appended to choices.

Hope this helps!

Try
full_response += response.choices[0].delta.content

1 Like

Thank you so much!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.