Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +4 -12
src/streamlit_app.py
CHANGED
@@ -34,6 +34,7 @@ def parse_and_render_streamed_response(streamed):
|
|
34 |
# Extract answer content (everything after </think>)
|
35 |
answer_start = streamed.find('</think>') + len('</think>')
|
36 |
answer = streamed[answer_start:].strip()
|
|
|
37 |
|
38 |
# Render reasoning section
|
39 |
if reasoning:
|
@@ -43,7 +44,7 @@ def parse_and_render_streamed_response(streamed):
|
|
43 |
# Render answer section
|
44 |
if answer:
|
45 |
st.subheader("π‘ Answer")
|
46 |
-
st.markdown(answer)
|
47 |
else:
|
48 |
# No <think> tags found, render entire content as answer
|
49 |
st.subheader("π‘ Answer")
|
@@ -137,17 +138,8 @@ if user_input:
|
|
137 |
with st.spinner("Thinking..."):
|
138 |
try:
|
139 |
full_response = call_perplexity_api(user_input).json()
|
140 |
-
|
141 |
-
|
142 |
-
if full_response_json.think:
|
143 |
-
st.markdown(full_response_json.think)
|
144 |
-
else:
|
145 |
-
st.markdown("... Reasoning not found ...")
|
146 |
-
st.subheader("π‘ Answer")
|
147 |
-
if full_response_json.answer:
|
148 |
-
st.markdown(full_response_json.answer)
|
149 |
-
else:
|
150 |
-
st.markdown("... Answer not found ...")
|
151 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
152 |
except requests.RequestException as err:
|
153 |
st.error(f"Error: {err}")
|
|
|
34 |
# Extract answer content (everything after </think>)
|
35 |
answer_start = streamed.find('</think>') + len('</think>')
|
36 |
answer = streamed[answer_start:].strip()
|
37 |
+
answer_json = json.loads(answer)
|
38 |
|
39 |
# Render reasoning section
|
40 |
if reasoning:
|
|
|
44 |
# Render answer section
|
45 |
if answer:
|
46 |
st.subheader("π‘ Answer")
|
47 |
+
st.markdown(answer_json.answer)
|
48 |
else:
|
49 |
# No <think> tags found, render entire content as answer
|
50 |
st.subheader("π‘ Answer")
|
|
|
138 |
with st.spinner("Thinking..."):
|
139 |
try:
|
140 |
full_response = call_perplexity_api(user_input).json()
|
141 |
+
full_response_content = full_response["choices"][0]["message"]["content"]
|
142 |
+
parse_and_render_streamed_response(full_response_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
144 |
except requests.RequestException as err:
|
145 |
st.error(f"Error: {err}")
|