Odrec
February 17, 2024, 9:56am
1
Using latest version of streamlit
This is the code:
with st.chat_message("assistant"):
stream = client.chat.completions.create(
model=st.session_state['open-ai-model'],
messages=messages,
stream=True,
)
response = st.write_stream(stream)
Formatting issue:
Hi @Odrec
This appears to be a when the output contains special formats. Instead of st.write_stream, could you try replacing that with st.markdown. The down side is that the typewriter effect would not be used.
Hope this helps
Odrec
February 17, 2024, 3:55pm
3
Hi, thanks for the answer.
I tried it like this but now I get random white spaces between words and every partial response is in a new line
with st.chat_message("assistant"):
stream = client.chat.completions.create(
model=st.session_state['open-ai-model'],
messages=messages,
stream=True,
)
response = []
partial_response = []
for chunk in stream:
delta = chunk.choices[0].delta
if delta:
if len(partial_response) < 50:
chunk_content = chunk.choices[0].delta.content
partial_response.append(chunk_content)
else:
st.markdown(' '.join(partial_response))
response.extend(partial_response)
partial_response = []
response = ' '.join(response)
system
Closed
August 15, 2024, 3:56pm
4
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.