Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ def get_tool_owner_info():
|
|
32 |
}
|
33 |
return json.dumps(owner_info)
|
34 |
|
35 |
-
def run_conversation(user_prompt, messages):
|
36 |
tools = [
|
37 |
{
|
38 |
"type": "function",
|
@@ -155,32 +155,16 @@ if prompt := st.chat_input("Enter your prompt here..."):
|
|
155 |
|
156 |
# Fetch response from Groq API
|
157 |
try:
|
158 |
-
|
159 |
-
model=model_option,
|
160 |
-
messages=[
|
161 |
-
{"role": m["role"], "content": m["content"]}
|
162 |
-
for m in st.session_state.messages
|
163 |
-
],
|
164 |
-
max_tokens=max_tokens,
|
165 |
-
stream=True,
|
166 |
-
)
|
167 |
|
168 |
-
#
|
169 |
-
with st.chat_message("assistant", avatar="🤖"):
|
170 |
-
chat_responses_generator = generate_chat_responses(chat_completion)
|
171 |
-
full_response = st.write_stream(chat_responses_generator)
|
172 |
-
except Exception as e:
|
173 |
-
st.error(e, icon="🚨")
|
174 |
-
|
175 |
-
# Append the full response to session_state.messages
|
176 |
-
if isinstance(full_response, str):
|
177 |
st.session_state.messages.append(
|
178 |
{"role": "assistant", "content": full_response}
|
179 |
)
|
180 |
-
else:
|
181 |
-
# Handle the case where full_response is not a string
|
182 |
-
combined_response = "\n".join(str(item) for item in full_response)
|
183 |
-
st.session_state.messages.append(
|
184 |
-
{"role": "assistant", "content": combined_response}
|
185 |
-
)
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
return json.dumps(owner_info)
|
34 |
|
35 |
+
def run_conversation(user_prompt, messages, model_option, max_tokens):
|
36 |
tools = [
|
37 |
{
|
38 |
"type": "function",
|
|
|
155 |
|
156 |
# Fetch response from Groq API
|
157 |
try:
|
158 |
+
full_response = run_conversation(prompt, st.session_state.messages, model_option, max_tokens)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
+
# Append the full response to session_state.messages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
st.session_state.messages.append(
|
162 |
{"role": "assistant", "content": full_response}
|
163 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
+
# Display the assistant's response
|
166 |
+
with st.chat_message("assistant", avatar="🤖"):
|
167 |
+
st.markdown(full_response)
|
168 |
+
|
169 |
+
except Exception as e:
|
170 |
+
st.error(e, icon="🚨")
|