mirror of
https://github.com/katanemo/plano.git
synced 2026-07-08 16:02:12 +02:00
improve code a bit
This commit is contained in:
parent
7d7af83f1e
commit
a4746ea1f9
1 changed files with 11 additions and 12 deletions
|
|
@ -58,22 +58,21 @@ def predict(message, state):
|
||||||
# extract arch_state from metadata and store it in gradio session state
|
# extract arch_state from metadata and store it in gradio session state
|
||||||
# this state must be passed back to the gateway in the next request
|
# this state must be passed back to the gateway in the next request
|
||||||
response_json = json.loads(raw_response.text)
|
response_json = json.loads(raw_response.text)
|
||||||
arch_state = {}
|
|
||||||
if response_json:
|
if response_json:
|
||||||
metadata = response_json.get("metadata", {})
|
# load arch_state from metadata
|
||||||
if metadata:
|
arch_state_str = response_json.get("metadata", {}).get(ARCH_STATE_HEADER, "{}")
|
||||||
arch_state_str = metadata.get(ARCH_STATE_HEADER, "{}")
|
# parse arch_state into json object
|
||||||
arch_state = json.loads(arch_state_str)
|
arch_state = json.loads(arch_state_str)
|
||||||
if arch_state:
|
# load messages from arch_state
|
||||||
state["arch_state"] = arch_state
|
arch_messages_str = arch_state.get("messages", "[]")
|
||||||
|
# parse messages into json object
|
||||||
arch_messages_str = arch_state.get("messages", "[]")
|
arch_messages = json.loads(arch_messages_str)
|
||||||
arch_messages = json.loads(arch_messages_str)
|
# append messages from arch gateway to history
|
||||||
|
for message in arch_messages:
|
||||||
|
history.append(message)
|
||||||
|
|
||||||
content = response.choices[0].message.content
|
content = response.choices[0].message.content
|
||||||
|
|
||||||
for message in arch_messages:
|
|
||||||
history.append(message)
|
|
||||||
history.append({"role": "assistant", "content": content, "model": response.model})
|
history.append({"role": "assistant", "content": content, "model": response.model})
|
||||||
history_view = [h for h in history if h["role"] != "tool" and "content" in h]
|
history_view = [h for h in history if h["role"] != "tool" and "content" in h]
|
||||||
messages = [
|
messages = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue