Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -93,10 +93,8 @@ class ReasoningOrchestra:
|
|
93 |
return {"error": "API key not set"}
|
94 |
|
95 |
prompt = f"""You are the Deep Thinker in a collaborative reasoning system. Your role is to provide thorough, methodical analysis with extensive step-by-step reasoning.
|
96 |
-
|
97 |
Problem: {problem}
|
98 |
{f"Additional Context: {context}" if context else ""}
|
99 |
-
|
100 |
Please provide a comprehensive analysis with deep reasoning. Think through all implications, consider multiple angles, and provide detailed step-by-step logic. Be thorough and methodical in your approach."""
|
101 |
|
102 |
try:
|
@@ -129,17 +127,14 @@ Please provide a comprehensive analysis with deep reasoning. Think through all i
|
|
129 |
return {"error": "API key not set"}
|
130 |
|
131 |
prompt = f"""You are the Quick Strategist in a collaborative reasoning system. Your role is to provide fast, efficient strategic analysis with clear action plans.
|
132 |
-
|
133 |
Problem: {problem}
|
134 |
{f"Additional Context: {context}" if context else ""}
|
135 |
-
|
136 |
Please provide a strategic analysis with:
|
137 |
1. Key insights and patterns
|
138 |
2. Practical solutions
|
139 |
3. Implementation priorities
|
140 |
4. Risk assessment
|
141 |
5. Clear next steps
|
142 |
-
|
143 |
Be decisive and solution-focused. Provide concrete, actionable recommendations."""
|
144 |
|
145 |
try:
|
@@ -171,10 +166,8 @@ Be decisive and solution-focused. Provide concrete, actionable recommendations."
|
|
171 |
return {"error": "API key not set"}
|
172 |
|
173 |
prompt = f"""You are the Detail Detective in a collaborative reasoning system. Your role is to provide meticulous investigation and comprehensive fact-checking.
|
174 |
-
|
175 |
Problem: {problem}
|
176 |
{f"Additional Context: {context}" if context else ""}
|
177 |
-
|
178 |
Please conduct a thorough investigation including:
|
179 |
1. Detailed analysis of all aspects
|
180 |
2. Potential edge cases and considerations
|
@@ -182,7 +175,6 @@ Please conduct a thorough investigation including:
|
|
182 |
4. Historical context or precedents
|
183 |
5. Comprehensive pros and cons
|
184 |
6. Hidden connections or implications
|
185 |
-
|
186 |
Be extremely thorough and leave no stone unturned. Provide detailed evidence and reasoning for your conclusions."""
|
187 |
|
188 |
try:
|
@@ -225,7 +217,7 @@ Be extremely thorough and leave no stone unturned. Provide detailed evidence and
|
|
225 |
return {"error": error_msg}
|
226 |
|
227 |
def synthesize_orchestra(self, deep_result: Dict, strategic_result: Dict, detective_result: Dict, original_problem: str) -> str:
|
228 |
-
"""Synthesize all three perspectives into a final orchestrated solution"""
|
229 |
if not self.is_api_key_set:
|
230 |
return "API key not set"
|
231 |
|
@@ -242,20 +234,20 @@ Be extremely thorough and leave no stone unturned. Provide detailed evidence and
|
|
242 |
strategic_reasoning = extract_reasoning(strategic_result, "Quick Strategist")
|
243 |
detective_reasoning = extract_reasoning(detective_result, "Detail Detective")
|
244 |
|
245 |
-
synthesis_prompt = f"""You are the Orchestra Conductor. You have received analytical perspectives from three different AI reasoning specialists on the same problem. Your job is to synthesize these into a comprehensive, unified solution.
|
246 |
|
247 |
ORIGINAL PROBLEM: {original_problem}
|
248 |
|
249 |
-
DEEP THINKER ANALYSIS:
|
250 |
{deep_reasoning}
|
251 |
|
252 |
-
STRATEGIC ANALYSIS:
|
253 |
{strategic_reasoning}
|
254 |
|
255 |
-
DETECTIVE INVESTIGATION:
|
256 |
{detective_reasoning}
|
257 |
|
258 |
-
|
259 |
1. Combines the best insights from all available analyses
|
260 |
2. Addresses any gaps where models didn't provide input
|
261 |
3. Resolves any contradictions between the analyses
|
@@ -265,11 +257,11 @@ Please create a unified synthesis that:
|
|
265 |
|
266 |
If some models didn't provide analysis, work with what's available and note any limitations.
|
267 |
|
268 |
-
Format your response as a well-structured final solution that leverages all available reasoning approaches."""
|
269 |
|
270 |
try:
|
271 |
completion = self.client.chat.completions.create(
|
272 |
-
model="
|
273 |
messages=[{"role": "user", "content": synthesis_prompt}],
|
274 |
temperature=0.7,
|
275 |
max_completion_tokens=4096,
|
@@ -378,7 +370,7 @@ def run_full_orchestra(problem: str, context: str = "") -> Tuple[str, str, str,
|
|
378 |
# Phase 3: Detail Detective
|
379 |
detective_result = orchestra.detail_detective_analyze(problem, context)
|
380 |
|
381 |
-
# Phase 4: Synthesis
|
382 |
synthesis = orchestra.synthesize_orchestra(deep_result, strategic_result, detective_result, problem)
|
383 |
|
384 |
def format_result_html(result: Dict, color: str, icon: str) -> str:
|
@@ -420,7 +412,7 @@ def run_full_orchestra(problem: str, context: str = "") -> Tuple[str, str, str,
|
|
420 |
<div style="border: 2px solid #dc3545; border-radius: 15px; padding: 25px; margin: 15px 0; background: linear-gradient(135deg, #fff5f5 0%, #fee);">
|
421 |
<div style="display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid #dc3545;">
|
422 |
<span style="font-size: 24px; margin-right: 10px;">πΌ</span>
|
423 |
-
<h2 style="margin: 0; color: #dc3545;">Orchestra Conductor - Final Synthesis</h2>
|
424 |
</div>
|
425 |
|
426 |
<div style="background-color: white; padding: 20px; border-radius: 10px; line-height: 1.6;">
|
@@ -481,7 +473,7 @@ with gr.Blocks(css=custom_css, title="Reasoning Orchestra") as app:
|
|
481 |
<div class="orchestra-header">
|
482 |
<h1>πΌ The Collaborative Reasoning Orchestra</h1>
|
483 |
<p><em>Where AI models collaborate like musicians in an orchestra to solve complex problems</em></p>
|
484 |
-
<p><strong>Now with
|
485 |
</div>
|
486 |
""")
|
487 |
|
@@ -549,7 +541,7 @@ with gr.Blocks(css=custom_css, title="Reasoning Orchestra") as app:
|
|
549 |
|
550 |
# Full Orchestra Tab
|
551 |
with gr.TabItem("πΌ Full Orchestra Collaboration"):
|
552 |
-
gr.Markdown("### Run all three models collaboratively with
|
553 |
|
554 |
with gr.Column():
|
555 |
with gr.Row():
|
@@ -571,7 +563,7 @@ with gr.Blocks(css=custom_css, title="Reasoning Orchestra") as app:
|
|
571 |
deep_output = gr.HTML(label="π Deep Thinker Analysis", elem_classes=["html-content"])
|
572 |
strategic_output = gr.HTML(label="π Quick Strategist Analysis", elem_classes=["html-content"])
|
573 |
detective_output = gr.HTML(label="π Detail Detective Analysis", elem_classes=["html-content"])
|
574 |
-
synthesis_output = gr.HTML(label="πΌ Final Orchestrated Solution", elem_classes=["html-content"])
|
575 |
|
576 |
orchestra_analyze_btn.click(
|
577 |
fn=run_full_orchestra,
|
|
|
93 |
return {"error": "API key not set"}
|
94 |
|
95 |
prompt = f"""You are the Deep Thinker in a collaborative reasoning system. Your role is to provide thorough, methodical analysis with extensive step-by-step reasoning.
|
|
|
96 |
Problem: {problem}
|
97 |
{f"Additional Context: {context}" if context else ""}
|
|
|
98 |
Please provide a comprehensive analysis with deep reasoning. Think through all implications, consider multiple angles, and provide detailed step-by-step logic. Be thorough and methodical in your approach."""
|
99 |
|
100 |
try:
|
|
|
127 |
return {"error": "API key not set"}
|
128 |
|
129 |
prompt = f"""You are the Quick Strategist in a collaborative reasoning system. Your role is to provide fast, efficient strategic analysis with clear action plans.
|
|
|
130 |
Problem: {problem}
|
131 |
{f"Additional Context: {context}" if context else ""}
|
|
|
132 |
Please provide a strategic analysis with:
|
133 |
1. Key insights and patterns
|
134 |
2. Practical solutions
|
135 |
3. Implementation priorities
|
136 |
4. Risk assessment
|
137 |
5. Clear next steps
|
|
|
138 |
Be decisive and solution-focused. Provide concrete, actionable recommendations."""
|
139 |
|
140 |
try:
|
|
|
166 |
return {"error": "API key not set"}
|
167 |
|
168 |
prompt = f"""You are the Detail Detective in a collaborative reasoning system. Your role is to provide meticulous investigation and comprehensive fact-checking.
|
|
|
169 |
Problem: {problem}
|
170 |
{f"Additional Context: {context}" if context else ""}
|
|
|
171 |
Please conduct a thorough investigation including:
|
172 |
1. Detailed analysis of all aspects
|
173 |
2. Potential edge cases and considerations
|
|
|
175 |
4. Historical context or precedents
|
176 |
5. Comprehensive pros and cons
|
177 |
6. Hidden connections or implications
|
|
|
178 |
Be extremely thorough and leave no stone unturned. Provide detailed evidence and reasoning for your conclusions."""
|
179 |
|
180 |
try:
|
|
|
217 |
return {"error": error_msg}
|
218 |
|
219 |
def synthesize_orchestra(self, deep_result: Dict, strategic_result: Dict, detective_result: Dict, original_problem: str) -> str:
|
220 |
+
"""Synthesize all three perspectives into a final orchestrated solution using Llama 3.3 70B"""
|
221 |
if not self.is_api_key_set:
|
222 |
return "API key not set"
|
223 |
|
|
|
234 |
strategic_reasoning = extract_reasoning(strategic_result, "Quick Strategist")
|
235 |
detective_reasoning = extract_reasoning(detective_result, "Detail Detective")
|
236 |
|
237 |
+
synthesis_prompt = f"""You are the Orchestra Conductor using Llama 3.3 70B Versatile model. You have received analytical perspectives from three different AI reasoning specialists on the same problem. Your job is to synthesize these into a comprehensive, unified solution.
|
238 |
|
239 |
ORIGINAL PROBLEM: {original_problem}
|
240 |
|
241 |
+
DEEP THINKER ANALYSIS (π DeepSeek R1):
|
242 |
{deep_reasoning}
|
243 |
|
244 |
+
STRATEGIC ANALYSIS (π Qwen3 32B):
|
245 |
{strategic_reasoning}
|
246 |
|
247 |
+
DETECTIVE INVESTIGATION (π QwQ 32B):
|
248 |
{detective_reasoning}
|
249 |
|
250 |
+
As the Orchestra Conductor, please create a unified synthesis that:
|
251 |
1. Combines the best insights from all available analyses
|
252 |
2. Addresses any gaps where models didn't provide input
|
253 |
3. Resolves any contradictions between the analyses
|
|
|
257 |
|
258 |
If some models didn't provide analysis, work with what's available and note any limitations.
|
259 |
|
260 |
+
Format your response as a well-structured final solution that leverages all available reasoning approaches. Use clear sections and bullet points where appropriate for maximum clarity."""
|
261 |
|
262 |
try:
|
263 |
completion = self.client.chat.completions.create(
|
264 |
+
model="llama-3.3-70b-versatile",
|
265 |
messages=[{"role": "user", "content": synthesis_prompt}],
|
266 |
temperature=0.7,
|
267 |
max_completion_tokens=4096,
|
|
|
370 |
# Phase 3: Detail Detective
|
371 |
detective_result = orchestra.detail_detective_analyze(problem, context)
|
372 |
|
373 |
+
# Phase 4: Synthesis using Llama 3.3 70B
|
374 |
synthesis = orchestra.synthesize_orchestra(deep_result, strategic_result, detective_result, problem)
|
375 |
|
376 |
def format_result_html(result: Dict, color: str, icon: str) -> str:
|
|
|
412 |
<div style="border: 2px solid #dc3545; border-radius: 15px; padding: 25px; margin: 15px 0; background: linear-gradient(135deg, #fff5f5 0%, #fee);">
|
413 |
<div style="display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid #dc3545;">
|
414 |
<span style="font-size: 24px; margin-right: 10px;">πΌ</span>
|
415 |
+
<h2 style="margin: 0; color: #dc3545;">Orchestra Conductor - Final Synthesis (Llama 3.3 70B Versatile)</h2>
|
416 |
</div>
|
417 |
|
418 |
<div style="background-color: white; padding: 20px; border-radius: 10px; line-height: 1.6;">
|
|
|
473 |
<div class="orchestra-header">
|
474 |
<h1>πΌ The Collaborative Reasoning Orchestra</h1>
|
475 |
<p><em>Where AI models collaborate like musicians in an orchestra to solve complex problems</em></p>
|
476 |
+
<p><strong>Now with Llama 3.3 70B Versatile as Orchestra Conductor & Enhanced HTML-Formatted Responses!</strong></p>
|
477 |
</div>
|
478 |
""")
|
479 |
|
|
|
541 |
|
542 |
# Full Orchestra Tab
|
543 |
with gr.TabItem("πΌ Full Orchestra Collaboration"):
|
544 |
+
gr.Markdown("### Run all three models collaboratively with Llama 3.3 70B as Orchestra Conductor and stunning HTML-formatted output")
|
545 |
|
546 |
with gr.Column():
|
547 |
with gr.Row():
|
|
|
563 |
deep_output = gr.HTML(label="π Deep Thinker Analysis", elem_classes=["html-content"])
|
564 |
strategic_output = gr.HTML(label="π Quick Strategist Analysis", elem_classes=["html-content"])
|
565 |
detective_output = gr.HTML(label="π Detail Detective Analysis", elem_classes=["html-content"])
|
566 |
+
synthesis_output = gr.HTML(label="πΌ Final Orchestrated Solution (Llama 3.3 70B)", elem_classes=["html-content"])
|
567 |
|
568 |
orchestra_analyze_btn.click(
|
569 |
fn=run_full_orchestra,
|