Cosmos LLM
Browse files
app.py
CHANGED
@@ -34,7 +34,7 @@ def convert_to_messages(message, history):
|
|
34 |
|
35 |
return messages
|
36 |
|
37 |
-
def
|
38 |
messages = convert_to_messages(message, history)
|
39 |
|
40 |
headers = {
|
@@ -63,8 +63,8 @@ def chat_cosmosllama(message: str, history: list, conversation_id: str, parent_m
|
|
63 |
if "assistantMessageId" in json_line:
|
64 |
new_parent_message_id = json_line["assistantMessageId"]
|
65 |
|
66 |
-
if "
|
67 |
-
full_response += json_line['
|
68 |
yield full_response, new_parent_message_id
|
69 |
except Exception:
|
70 |
traceback.print_exc()
|
@@ -77,7 +77,7 @@ def get_conversation_id():
|
|
77 |
def clear_conversation():
|
78 |
return get_conversation_id(), []
|
79 |
|
80 |
-
chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Cosmos
|
81 |
|
82 |
with gr.Blocks(fill_height=True, css=css) as demo:
|
83 |
conversation_id_state = gr.State(value=get_conversation_id())
|
@@ -85,7 +85,7 @@ with gr.Blocks(fill_height=True, css=css) as demo:
|
|
85 |
|
86 |
def handle_user_message(message, history, conversation_id_state, parent_message_history):
|
87 |
is_parent_message_set = False
|
88 |
-
response_generator =
|
89 |
for response, updated_parent_message_id in response_generator:
|
90 |
if not is_parent_message_set:
|
91 |
parent_message_history.append(updated_parent_message_id)
|
|
|
34 |
|
35 |
return messages
|
36 |
|
37 |
+
def chat_cosmosllm(message: str, history: list, conversation_id: str, parent_message_id: str) -> (str, str):
|
38 |
messages = convert_to_messages(message, history)
|
39 |
|
40 |
headers = {
|
|
|
63 |
if "assistantMessageId" in json_line:
|
64 |
new_parent_message_id = json_line["assistantMessageId"]
|
65 |
|
66 |
+
if "CosmosLLM" in json_line:
|
67 |
+
full_response += json_line['CosmosLLM']
|
68 |
yield full_response, new_parent_message_id
|
69 |
except Exception:
|
70 |
traceback.print_exc()
|
|
|
77 |
def clear_conversation():
|
78 |
return get_conversation_id(), []
|
79 |
|
80 |
+
chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Cosmos LLM')
|
81 |
|
82 |
with gr.Blocks(fill_height=True, css=css) as demo:
|
83 |
conversation_id_state = gr.State(value=get_conversation_id())
|
|
|
85 |
|
86 |
def handle_user_message(message, history, conversation_id_state, parent_message_history):
|
87 |
is_parent_message_set = False
|
88 |
+
response_generator = chat_cosmosllm(message, history, conversation_id_state, parent_message_history[-1] if parent_message_history else None)
|
89 |
for response, updated_parent_message_id in response_generator:
|
90 |
if not is_parent_message_set:
|
91 |
parent_message_history.append(updated_parent_message_id)
|