Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,19 +22,23 @@ def query_model(model_name: str, messages: List[Dict[str, str]]) -> str:
|
|
22 |
"Content-Type": "application/json"
|
23 |
}
|
24 |
|
25 |
-
#
|
|
|
|
|
|
|
26 |
model_prompts = {
|
27 |
"Qwen2.5-72B-Instruct": (
|
28 |
-
f"<|im_start|>
|
|
|
29 |
),
|
30 |
"Llama3.3-70B-Instruct": (
|
31 |
-
"<|begin_of_text|>"
|
32 |
-
"<|
|
33 |
-
|
34 |
-
"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
35 |
),
|
36 |
"Qwen2.5-Coder-32B-Instruct": (
|
37 |
-
f"<|im_start|>
|
|
|
38 |
)
|
39 |
}
|
40 |
|
@@ -68,33 +72,31 @@ def query_model(model_name: str, messages: List[Dict[str, str]]) -> str:
|
|
68 |
return f"{model_name} error: {str(e)}"
|
69 |
|
70 |
def respond(message: str, history: List[List[str]]) -> str:
|
71 |
-
"""Handle
|
72 |
-
# Prepare messages in OpenAI format
|
73 |
messages = [{"role": "user", "content": message}]
|
|
|
74 |
|
75 |
-
#
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
for model_name in MODEL_ENDPOINTS:
|
83 |
-
thread = threading.Thread(target=get_model_response, args=(model_name,))
|
84 |
-
thread.start()
|
85 |
-
threads.append(thread)
|
86 |
-
|
87 |
-
# Wait for all threads to complete
|
88 |
-
for thread in threads:
|
89 |
-
thread.join()
|
90 |
|
91 |
-
#
|
92 |
-
|
93 |
-
|
|
|
94 |
responses.append(f"**{model_name}**:\n{response}")
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
-
# Format
|
97 |
-
return "\n\n
|
98 |
|
99 |
# Create the Gradio interface
|
100 |
chat_interface = gr.ChatInterface(
|
|
|
22 |
"Content-Type": "application/json"
|
23 |
}
|
24 |
|
25 |
+
# Build full conversation history for context
|
26 |
+
conversation = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
27 |
+
|
28 |
+
# Model-specific prompt formatting with full history
|
29 |
model_prompts = {
|
30 |
"Qwen2.5-72B-Instruct": (
|
31 |
+
f"<|im_start|>system\nCollaborate with other experts. Previous discussion:\n{conversation}<|im_end|>\n"
|
32 |
+
"<|im_start|>assistant\nMy analysis:"
|
33 |
),
|
34 |
"Llama3.3-70B-Instruct": (
|
35 |
+
"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n"
|
36 |
+
f"Build upon this discussion:\n{conversation}<|eot_id|>\n"
|
37 |
+
"<|start_header_id|>assistant<|end_header_id|>\nMy contribution:"
|
|
|
38 |
),
|
39 |
"Qwen2.5-Coder-32B-Instruct": (
|
40 |
+
f"<|im_start|>system\nTechnical discussion context:\n{conversation}<|im_end|>\n"
|
41 |
+
"<|im_start|>assistant\nTechnical perspective:"
|
42 |
)
|
43 |
}
|
44 |
|
|
|
72 |
return f"{model_name} error: {str(e)}"
|
73 |
|
74 |
def respond(message: str, history: List[List[str]]) -> str:
|
75 |
+
"""Handle sequential model responses with collaboration"""
|
|
|
76 |
messages = [{"role": "user", "content": message}]
|
77 |
+
responses = []
|
78 |
|
79 |
+
# Define processing order
|
80 |
+
processing_order = [
|
81 |
+
"Qwen2.5-Coder-32B-Instruct",
|
82 |
+
"Qwen2.5-72B-Instruct",
|
83 |
+
"Llama3.3-70B-Instruct"
|
84 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
# Process models in sequence with accumulating context
|
87 |
+
for model_name in processing_order:
|
88 |
+
# Get current model's response
|
89 |
+
response = query_model(model_name, messages)
|
90 |
responses.append(f"**{model_name}**:\n{response}")
|
91 |
+
|
92 |
+
# Add model's response to message history for next model
|
93 |
+
messages.append({
|
94 |
+
"role": "assistant",
|
95 |
+
"content": f"{model_name} response: {response}"
|
96 |
+
})
|
97 |
|
98 |
+
# Format output with collaboration timeline
|
99 |
+
return "\n\nβββ Next Model Builds Upon This βββ\n\n".join(responses)
|
100 |
|
101 |
# Create the Gradio interface
|
102 |
chat_interface = gr.ChatInterface(
|