Skip to content

Commit

Permalink
refine the request payload when chatting for context clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Oct 26, 2024
1 parent 5c03c6f commit 26c94d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 10 additions & 4 deletions frontend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,23 @@
# Send message to backend
response = httpx.post(
f"{BACKEND_URL}/api/chat/{st.session_state.chat_session_id}",
json={"role": "user", "content": prompt},
json={
"message": {"role": "user", "content": prompt},
"content_type": content_type,
},
timeout=None,
)

response.raise_for_status()

if response.status_code == 200:
ai_message = response.json()
st.session_state.messages.append(ai_message)
ai_message = ""
for line in response.iter_lines():
ai_message += line
st.session_state.messages.append({"role": "assistant", "content": ai_message})

with st.chat_message("assistant"):
st.write(ai_message["content"])
st.write(ai_message)

# Show generate button if enough context
if len(st.session_state.messages) >= 2:
Expand Down
15 changes: 12 additions & 3 deletions frontend/example_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ def display_example_cards():
st.session_state.messages.append({"role": "user", "content": example})
response = httpx.post(
f"{BACKEND_URL}/api/chat/{st.session_state.chat_session_id}",
json={"role": "user", "content": example},
json={
"message": {"role": "user", "content": example},
"content_type": content_type,
},
timeout=None,
)

response.raise_for_status()

if response.status_code == 200:
ai_message = response.json()
st.session_state.messages.append(ai_message)
ai_message = ""
for line in response.iter_lines():
ai_message += line
st.session_state.messages.append(
{"role": "assistant", "content": ai_message}
)

st.rerun()

0 comments on commit 26c94d3

Please sign in to comment.