fix: improve handling of OpenAI responses and simplify MCP response wrapping
This commit is contained in:
@@ -37,10 +37,12 @@ def handle_user_input():
|
||||
response = st.session_state.client.get_chat_response(st.session_state.messages)
|
||||
|
||||
# Handle both MCP and standard OpenAI responses
|
||||
if hasattr(response, "__iter__"):
|
||||
# Check if it's NOT a dict (assuming stream is not a dict)
|
||||
if not isinstance(response, dict):
|
||||
# Standard OpenAI streaming response
|
||||
for chunk in response:
|
||||
if chunk.choices[0].delta.content:
|
||||
# Ensure chunk has choices and delta before accessing
|
||||
if chunk.choices and chunk.choices[0].delta and chunk.choices[0].delta.content:
|
||||
full_response += chunk.choices[0].delta.content
|
||||
response_placeholder.markdown(full_response + "▌")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user