Update app.py
Browse files
app.py
CHANGED
|
@@ -45,9 +45,9 @@ class CreativeAgenticAI:
|
|
| 45 |
else:
|
| 46 |
raise ValueError(f"Invalid provider or missing API key for {provider}")
|
| 47 |
|
| 48 |
-
async def _chutes_chat_async(self, messages: List[Dict], temperature: float = 0.7, max_tokens: int = 1024) ->
|
| 49 |
"""
|
| 50 |
-
Async method for Chutes API chat
|
| 51 |
"""
|
| 52 |
headers = {
|
| 53 |
"Authorization": f"Bearer {self.chutes_api_key}",
|
|
@@ -57,7 +57,7 @@ class CreativeAgenticAI:
|
|
| 57 |
body = {
|
| 58 |
"model": self.model,
|
| 59 |
"messages": messages,
|
| 60 |
-
"stream":
|
| 61 |
"max_tokens": max_tokens,
|
| 62 |
"temperature": temperature
|
| 63 |
}
|
|
@@ -69,13 +69,66 @@ class CreativeAgenticAI:
|
|
| 69 |
json=body
|
| 70 |
) as response:
|
| 71 |
if response.status == 200:
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
else:
|
| 75 |
error_text = await response.text()
|
| 76 |
raise Exception(f"Chutes API error: {response.status} - {error_text}")
|
| 77 |
|
| 78 |
-
def _chutes_chat_sync(self, messages: List[Dict], temperature: float = 0.7, max_tokens: int = 1024) ->
|
| 79 |
"""
|
| 80 |
Synchronous wrapper for Chutes API chat
|
| 81 |
"""
|
|
@@ -86,7 +139,7 @@ class CreativeAgenticAI:
|
|
| 86 |
asyncio.set_event_loop(loop)
|
| 87 |
|
| 88 |
return loop.run_until_complete(
|
| 89 |
-
self._chutes_chat_async(messages, temperature, max_tokens)
|
| 90 |
)
|
| 91 |
|
| 92 |
def chat(self, message: str,
|
|
@@ -136,10 +189,13 @@ IMPORTANT: When you search the web and find information, you MUST:
|
|
| 136 |
|
| 137 |
Your responses should be well-structured, informative, and properly cited with working links."""
|
| 138 |
else:
|
| 139 |
-
#
|
| 140 |
-
system_prompt = """You are a creative and intelligent AI assistant.
|
|
|
|
| 141 |
Be helpful, creative, and engaging while maintaining accuracy.
|
| 142 |
-
Your responses should be well-structured, informative, and comprehensive.
|
|
|
|
|
|
|
| 143 |
|
| 144 |
# Build messages
|
| 145 |
messages = [{"role": "system", "content": system_prompt}]
|
|
@@ -174,6 +230,7 @@ IMPORTANT: When you search the web and find information, you MUST:
|
|
| 174 |
|
| 175 |
return {
|
| 176 |
"content": error_msg,
|
|
|
|
| 177 |
"timestamp": datetime.now().isoformat(),
|
| 178 |
"model": self.model,
|
| 179 |
"provider": self.provider,
|
|
@@ -215,6 +272,7 @@ IMPORTANT: When you search the web and find information, you MUST:
|
|
| 215 |
# Create response object
|
| 216 |
return {
|
| 217 |
"content": processed_content,
|
|
|
|
| 218 |
"timestamp": datetime.now().isoformat(),
|
| 219 |
"model": self.model,
|
| 220 |
"provider": "groq",
|
|
@@ -228,16 +286,20 @@ IMPORTANT: When you search the web and find information, you MUST:
|
|
| 228 |
}
|
| 229 |
|
| 230 |
def _handle_chutes_chat(self, messages: List[Dict], temperature: float, max_tokens: int, original_message: str) -> Dict:
|
| 231 |
-
"""Handle Chutes API chat"""
|
| 232 |
-
|
| 233 |
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
| 235 |
self.conversation_history.append({"role": "user", "content": original_message})
|
| 236 |
-
self.conversation_history.append({"role": "assistant", "content":
|
| 237 |
|
| 238 |
# Create response object
|
| 239 |
return {
|
| 240 |
-
"content":
|
|
|
|
| 241 |
"timestamp": datetime.now().isoformat(),
|
| 242 |
"model": self.model,
|
| 243 |
"provider": "chutes",
|
|
@@ -381,14 +443,15 @@ def validate_api_keys(groq_api_key: str, chutes_api_key: str, provider: str, mod
|
|
| 381 |
test_response = test_ai._chutes_chat_sync(
|
| 382 |
[{"role": "user", "content": "Hello"}],
|
| 383 |
temperature=0.7,
|
| 384 |
-
max_tokens=10
|
|
|
|
| 385 |
)
|
| 386 |
|
| 387 |
# Create AI instance
|
| 388 |
ai_instance = CreativeAgenticAI(chutes_api_key=chutes_api_key, provider="chutes", model=model)
|
| 389 |
api_key_status["chutes"] = "Valid β
"
|
| 390 |
|
| 391 |
-
return f"β
Chutes API Key Valid! Creative AI is ready.\n\n**Provider:** Chutes\n**Model:** {model}\n**Status:** Connected
|
| 392 |
|
| 393 |
except Exception as e:
|
| 394 |
api_key_status["chutes"] = "Invalid β"
|
|
@@ -400,7 +463,7 @@ def get_available_models(provider: str) -> List[str]:
|
|
| 400 |
if provider == "groq":
|
| 401 |
return ["compound-beta", "compound-beta-mini"]
|
| 402 |
elif provider == "chutes":
|
| 403 |
-
return ["openai/gpt-oss-20b", "
|
| 404 |
return []
|
| 405 |
|
| 406 |
def update_model_choices(provider: str):
|
|
@@ -414,8 +477,9 @@ def chat_with_ai(message: str,
|
|
| 414 |
system_prompt: str,
|
| 415 |
temperature: float,
|
| 416 |
max_tokens: int,
|
| 417 |
-
history: List
|
| 418 |
-
|
|
|
|
| 419 |
global ai_instance, current_provider
|
| 420 |
|
| 421 |
if not ai_instance:
|
|
@@ -444,8 +508,20 @@ def chat_with_ai(message: str,
|
|
| 444 |
max_tokens=int(max_tokens)
|
| 445 |
)
|
| 446 |
|
| 447 |
-
# Format response
|
| 448 |
-
ai_response =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
|
| 450 |
# Add enhanced tool usage info (Groq only)
|
| 451 |
if response.get("tool_usage") and current_provider == "groq":
|
|
@@ -474,8 +550,15 @@ def chat_with_ai(message: str,
|
|
| 474 |
|
| 475 |
ai_response += f"\n\n*π Domain filtering applied: {' | '.join(filter_info)}*"
|
| 476 |
|
| 477 |
-
# Add provider info
|
| 478 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
|
| 480 |
# Add to history
|
| 481 |
history.append([message, ai_response])
|
|
@@ -546,40 +629,78 @@ def create_gradio_app():
|
|
| 546 |
padding: 15px;
|
| 547 |
margin: 10px 0;
|
| 548 |
}
|
| 549 |
-
|
| 550 |
-
background:
|
|
|
|
| 551 |
border-radius: 8px;
|
|
|
|
|
|
|
| 552 |
}
|
| 553 |
-
#neuroscope-
|
| 554 |
background: linear-gradient(to right, #00ff94, #00b4db);
|
| 555 |
border-radius: 8px;
|
| 556 |
-
margin-top: 10px;
|
| 557 |
}
|
| 558 |
"""
|
| 559 |
|
| 560 |
-
with gr.Blocks(css=css, title="π€ Multi-Provider Creative Agentic AI Chat", theme=gr.themes.Ocean()) as app:
|
| 561 |
|
| 562 |
# Header
|
| 563 |
gr.HTML("""
|
| 564 |
<div class="header">
|
| 565 |
-
<h1>π€ NeuroScope-AI Enhanced</h1>
|
| 566 |
-
<p>Multi-Provider AI Chat Tool -
|
| 567 |
</div>
|
| 568 |
""")
|
| 569 |
|
| 570 |
# Provider Selection
|
| 571 |
with gr.Group():
|
| 572 |
-
with gr.Accordion("π€ Multi-Provider NeuroScope AI", open=False, elem_id="neuroscope-accordion"):
|
| 573 |
gr.Markdown("""
|
| 574 |
-
**Enhanced with Multiple AI Providers:**
|
| 575 |
-
- π§ Intelligence (Neuro) - Now supports Groq & Chutes
|
| 576 |
-
- π Advanced capabilities (Scope) - Web search with Groq,
|
| 577 |
-
- π€ AI capabilities (AI) - Multiple model options
|
| 578 |
- β‘ Precision & Speed (Scope) - Choose the best provider for your needs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
""")
|
| 580 |
|
| 581 |
# Provider and API Key Section
|
| 582 |
with gr.Row():
|
|
|
|
| 583 |
with gr.Column():
|
| 584 |
provider_selection = gr.Radio(
|
| 585 |
choices=["groq", "chutes"],
|
|
@@ -604,8 +725,7 @@ def create_gradio_app():
|
|
| 604 |
info="Get your API key from: https://chutes.ai/",
|
| 605 |
visible=False
|
| 606 |
)
|
| 607 |
-
|
| 608 |
-
with gr.Column():
|
| 609 |
model_selection = gr.Radio(
|
| 610 |
choices=get_available_models("groq"),
|
| 611 |
label="π§ Groq Models",
|
|
@@ -613,6 +733,14 @@ def create_gradio_app():
|
|
| 613 |
info="compound-beta: More powerful | compound-beta-mini: Faster"
|
| 614 |
)
|
| 615 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
connect_btn = gr.Button("π Connect", variant="primary", size="lg")
|
| 617 |
|
| 618 |
# Status display
|
|
@@ -632,26 +760,29 @@ def create_gradio_app():
|
|
| 632 |
- β
**Citation System** - Automatic source linking and references
|
| 633 |
- β‘ **Ultra-fast inference** - Groq's hardware acceleration
|
| 634 |
- π§ **Models**: compound-beta, compound-beta-mini
|
|
|
|
| 635 |
|
| 636 |
-
**π― Chutes**
|
| 637 |
- β
**Multiple Model Access** - Various open-source and commercial models
|
| 638 |
-
- β
**
|
| 639 |
-
- β
**High-quality
|
|
|
|
| 640 |
- β‘ **Good performance** - Reliable and fast responses
|
| 641 |
-
- π§ **Models**: GPT-OSS-20B, Llama 3.1, Claude 3 Sonnet
|
| 642 |
- β **No web search** - Relies on training data only
|
| 643 |
|
| 644 |
**π‘ Use Groq when you need:**
|
| 645 |
- Real-time information and web search
|
| 646 |
- Research with source citations
|
| 647 |
- Domain-specific searches
|
| 648 |
-
-
|
| 649 |
|
| 650 |
**π‘ Use Chutes when you need:**
|
| 651 |
-
-
|
| 652 |
-
-
|
| 653 |
-
-
|
| 654 |
-
-
|
|
|
|
| 655 |
</div>
|
| 656 |
""")
|
| 657 |
|
|
@@ -666,15 +797,14 @@ def create_gradio_app():
|
|
| 666 |
gr.update(visible=chutes_visible), # chutes_api_key
|
| 667 |
gr.update(choices=models, value=models[0] if models else None,
|
| 668 |
label=f"π§ {provider.title()} Models"), # model_selection
|
| 669 |
-
gr.update(visible=
|
| 670 |
-
gr.update(visible=groq_visible), #
|
| 671 |
-
gr.update(visible=groq_visible) # exclude domains
|
| 672 |
)
|
| 673 |
|
| 674 |
provider_selection.change(
|
| 675 |
fn=update_provider_ui,
|
| 676 |
inputs=[provider_selection],
|
| 677 |
-
outputs=[groq_api_key, chutes_api_key, model_selection] #
|
| 678 |
)
|
| 679 |
|
| 680 |
# Connect button functionality
|
|
@@ -687,8 +817,8 @@ def create_gradio_app():
|
|
| 687 |
# Main Chat Interface
|
| 688 |
with gr.Tab("π¬ Chat"):
|
| 689 |
chatbot = gr.Chatbot(
|
| 690 |
-
label="Multi-Provider Creative AI Assistant",
|
| 691 |
-
height=
|
| 692 |
show_label=True,
|
| 693 |
bubble_full_width=False,
|
| 694 |
show_copy_button=True
|
|
@@ -732,7 +862,7 @@ def create_gradio_app():
|
|
| 732 |
)
|
| 733 |
|
| 734 |
# Domain Filtering Section (Groq only)
|
| 735 |
-
with gr.Group():
|
| 736 |
with gr.Accordion("π Domain Filtering (Groq Web Search Only)", open=False, elem_id="neuroscope-accordion"):
|
| 737 |
gr.Markdown("""
|
| 738 |
<div class="domain-info">
|
|
@@ -761,7 +891,7 @@ def create_gradio_app():
|
|
| 761 |
info="Never search these domains"
|
| 762 |
)
|
| 763 |
|
| 764 |
-
with gr.Accordion("π Common Domain Examples", open=False, elem_id="neuroscope-
|
| 765 |
gr.Markdown("""
|
| 766 |
**Academic & Research:**
|
| 767 |
- `arxiv.org`, `*.edu`, `scholar.google.com`, `researchgate.net`
|
|
@@ -779,7 +909,7 @@ def create_gradio_app():
|
|
| 779 |
- `nature.com`, `science.org`, `pubmed.ncbi.nlm.nih.gov`, `who.int`
|
| 780 |
""")
|
| 781 |
|
| 782 |
-
# Update provider UI function with domain filtering
|
| 783 |
def update_provider_ui_complete(provider):
|
| 784 |
groq_visible = provider == "groq"
|
| 785 |
chutes_visible = provider == "chutes"
|
|
@@ -790,25 +920,27 @@ def create_gradio_app():
|
|
| 790 |
gr.update(visible=chutes_visible), # chutes_api_key
|
| 791 |
gr.update(choices=models, value=models[0] if models else None,
|
| 792 |
label=f"π§ {provider.title()} Models"), # model_selection
|
|
|
|
| 793 |
gr.update(visible=groq_visible), # domain_group
|
| 794 |
)
|
| 795 |
|
| 796 |
provider_selection.change(
|
| 797 |
fn=update_provider_ui_complete,
|
| 798 |
inputs=[provider_selection],
|
| 799 |
-
outputs=[groq_api_key, chutes_api_key, model_selection]
|
| 800 |
)
|
| 801 |
|
| 802 |
-
# IMPORTANT Section with Citation Info
|
| 803 |
with gr.Group():
|
| 804 |
-
with gr.Accordion("π IMPORTANT - Citations &
|
| 805 |
gr.Markdown("""
|
| 806 |
<div class="citation-info">
|
| 807 |
-
<h3>π Multi-Provider Enhancement</h3>
|
| 808 |
<p>This enhanced version now supports both Groq and Chutes AI providers:</p>
|
| 809 |
<ul>
|
| 810 |
<li><strong>π Groq Integration:</strong> Agentic AI with web search, citations, and tool usage</li>
|
| 811 |
-
<li><strong>π― Chutes Integration:</strong> Multiple
|
|
|
|
| 812 |
<li><strong>π Easy Switching:</strong> Switch between providers based on your needs</li>
|
| 813 |
<li><strong>π Provider Comparison:</strong> Clear information about each provider's strengths</li>
|
| 814 |
</ul>
|
|
@@ -822,13 +954,14 @@ def create_gradio_app():
|
|
| 822 |
<li><strong>Search Query Tracking:</strong> Shows what queries were made to find information</li>
|
| 823 |
</ul>
|
| 824 |
|
| 825 |
-
<h3>
|
| 826 |
<p>When using Chutes, you get access to:</p>
|
| 827 |
<ul>
|
| 828 |
-
<li><strong>
|
| 829 |
-
<li><strong>
|
| 830 |
-
<li><strong>
|
| 831 |
-
<li><strong>
|
|
|
|
| 832 |
</ul>
|
| 833 |
</div>
|
| 834 |
|
|
@@ -849,10 +982,20 @@ def create_gradio_app():
|
|
| 849 |
- Useful for **filtering out unreliable or unwanted sources**.
|
| 850 |
- Allows broad search with **targeted exclusions**.
|
| 851 |
|
| 852 |
-
**
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 856 |
|
| 857 |
---
|
| 858 |
|
|
@@ -863,21 +1006,23 @@ def create_gradio_app():
|
|
| 863 |
- A **professional business consultant**
|
| 864 |
- A **coding mentor**
|
| 865 |
- A **creative writer**
|
|
|
|
| 866 |
- A **specific character or persona**
|
| 867 |
- Provides full control to **reshape the AI's tone, expertise, and conversational style** with a single prompt.
|
| 868 |
""")
|
| 869 |
|
| 870 |
# How to Use Section
|
| 871 |
-
with gr.Accordion("π How to Use This Enhanced Multi-Provider App", open=False, elem_id="neuroscope-accordion"):
|
| 872 |
gr.Markdown("""
|
| 873 |
### π Getting Started
|
| 874 |
-
1. **Choose your AI Provider** - Select between Groq (web search + agentic) or Chutes (
|
| 875 |
2. **Enter your API Key** -
|
| 876 |
- Groq: Get one from [console.groq.com](https://console.groq.com/)
|
| 877 |
- Chutes: Get one from [chutes.ai](https://chutes.ai/)
|
| 878 |
3. **Select a model** - Choose from provider-specific model options
|
| 879 |
-
4. **
|
| 880 |
-
5. **
|
|
|
|
| 881 |
|
| 882 |
### π― Key Features
|
| 883 |
**π Groq Features:**
|
|
@@ -887,10 +1032,11 @@ def create_gradio_app():
|
|
| 887 |
- **Ultra-fast**: Groq's hardware-accelerated inference
|
| 888 |
|
| 889 |
**π― Chutes Features:**
|
| 890 |
-
- **
|
| 891 |
-
- **
|
| 892 |
-
- **
|
| 893 |
-
- **
|
|
|
|
| 894 |
|
| 895 |
**π Universal Features:**
|
| 896 |
- **Memory**: Maintains conversation context throughout the session
|
|
@@ -904,73 +1050,83 @@ def create_gradio_app():
|
|
| 904 |
- Check the "Sources Used" section for all references
|
| 905 |
- Try different domain combinations to see varied results
|
| 906 |
|
| 907 |
-
**For Chutes:**
|
| 908 |
-
-
|
| 909 |
-
- Use
|
| 910 |
-
-
|
| 911 |
-
-
|
|
|
|
| 912 |
|
| 913 |
**General:**
|
| 914 |
- Adjust temperature: higher for creativity, lower for precision
|
| 915 |
- Try different system prompts for different conversation styles
|
| 916 |
- Use the provider that best fits your current task
|
|
|
|
|
|
|
| 917 |
""")
|
| 918 |
|
| 919 |
# Sample Examples Section
|
| 920 |
-
with gr.Accordion("π― Sample Examples to Test Both Providers", open=False, elem_id="neuroscope-accordion"):
|
| 921 |
gr.Markdown("""
|
| 922 |
<div class="example-box">
|
| 923 |
<h4>π Provider Comparison Examples</h4>
|
| 924 |
<p>Try the same prompts with both providers to see the difference:</p>
|
| 925 |
|
| 926 |
-
<h4>
|
| 927 |
<ul>
|
| 928 |
-
<li><strong>
|
| 929 |
-
<li><strong>
|
| 930 |
-
<li><strong>
|
|
|
|
| 931 |
</ul>
|
| 932 |
|
| 933 |
-
<h4>
|
| 934 |
<ul>
|
| 935 |
-
<li><strong>
|
| 936 |
-
<li><strong>
|
| 937 |
-
<li><strong>
|
|
|
|
| 938 |
</ul>
|
| 939 |
|
| 940 |
-
<h4>
|
| 941 |
<ul>
|
| 942 |
-
<li>"
|
| 943 |
-
<li>"
|
| 944 |
-
<li>"Generate ideas for a mobile app that helps with mental health"</li>
|
| 945 |
-
<li>"Write a poem about the beauty of code"</li>
|
| 946 |
</ul>
|
| 947 |
|
| 948 |
-
<h4>
|
| 949 |
<ul>
|
| 950 |
-
<li>
|
| 951 |
-
<li>
|
| 952 |
-
<li>
|
| 953 |
</ul>
|
| 954 |
|
| 955 |
-
<h4>π§ Model-Specific Testing (Chutes)</h4>
|
| 956 |
<ul>
|
| 957 |
-
<li><strong>GPT-OSS-20B:</strong> "Explain
|
| 958 |
-
<li><strong>Llama 3.1:</strong> "
|
| 959 |
-
<li><strong>Claude 3 Sonnet:</strong> "Analyze this business scenario and provide strategic recommendations"</li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 960 |
</ul>
|
| 961 |
</div>
|
| 962 |
""")
|
| 963 |
|
| 964 |
-
# Event handlers
|
| 965 |
send_btn.click(
|
| 966 |
fn=chat_with_ai,
|
| 967 |
-
inputs=[msg, include_domains, exclude_domains, system_prompt, temperature, max_tokens, chatbot],
|
| 968 |
outputs=[chatbot, msg]
|
| 969 |
)
|
| 970 |
|
| 971 |
msg.submit(
|
| 972 |
fn=chat_with_ai,
|
| 973 |
-
inputs=[msg, include_domains, exclude_domains, system_prompt, temperature, max_tokens, chatbot],
|
| 974 |
outputs=[chatbot, msg]
|
| 975 |
)
|
| 976 |
|
|
@@ -980,16 +1136,16 @@ def create_gradio_app():
|
|
| 980 |
)
|
| 981 |
|
| 982 |
# Footer
|
| 983 |
-
with gr.Accordion("π About This Enhanced Multi-Provider Tool", open=True, elem_id="neuroscope-accordion"):
|
| 984 |
gr.Markdown("""
|
| 985 |
-
**Enhanced Multi-Provider Creative Agentic AI Chat Tool** with
|
| 986 |
|
| 987 |
-
**π New
|
| 988 |
-
-
|
| 989 |
-
-
|
| 990 |
-
- π **
|
| 991 |
-
-
|
| 992 |
-
-
|
| 993 |
|
| 994 |
**π Groq Features:**
|
| 995 |
- π **Automatic Source Citations**: Every response includes clickable links to sources
|
|
@@ -1001,10 +1157,11 @@ def create_gradio_app():
|
|
| 1001 |
- π§ Advanced AI reasoning with tool usage
|
| 1002 |
|
| 1003 |
**π― Chutes Features:**
|
| 1004 |
-
- π€ **Multiple
|
| 1005 |
- π° **Cost-Effective**: Competitive pricing for AI access
|
| 1006 |
-
- π¨ **Creative Excellence**: Optimized for
|
| 1007 |
-
- β‘ **Reliable Performance**: Consistent and
|
|
|
|
| 1008 |
|
| 1009 |
**π Universal Features:**
|
| 1010 |
- π¬ Conversational memory and context
|
|
@@ -1014,7 +1171,14 @@ def create_gradio_app():
|
|
| 1014 |
|
| 1015 |
**π‘ Choose Your Provider:**
|
| 1016 |
- **Use Groq** when you need real-time information, web search, and citations
|
| 1017 |
-
- **Use Chutes** when you
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
""")
|
| 1019 |
|
| 1020 |
return app
|
|
|
|
| 45 |
else:
|
| 46 |
raise ValueError(f"Invalid provider or missing API key for {provider}")
|
| 47 |
|
| 48 |
+
async def _chutes_chat_async(self, messages: List[Dict], temperature: float = 0.7, max_tokens: int = 1024, stream: bool = False) -> Dict:
|
| 49 |
"""
|
| 50 |
+
Async method for Chutes API chat with thinking support
|
| 51 |
"""
|
| 52 |
headers = {
|
| 53 |
"Authorization": f"Bearer {self.chutes_api_key}",
|
|
|
|
| 57 |
body = {
|
| 58 |
"model": self.model,
|
| 59 |
"messages": messages,
|
| 60 |
+
"stream": stream,
|
| 61 |
"max_tokens": max_tokens,
|
| 62 |
"temperature": temperature
|
| 63 |
}
|
|
|
|
| 69 |
json=body
|
| 70 |
) as response:
|
| 71 |
if response.status == 200:
|
| 72 |
+
if stream:
|
| 73 |
+
thinking_content = ""
|
| 74 |
+
final_content = ""
|
| 75 |
+
in_thinking = False
|
| 76 |
+
|
| 77 |
+
async for line in response.content:
|
| 78 |
+
line = line.decode("utf-8").strip()
|
| 79 |
+
if line.startswith("data: "):
|
| 80 |
+
data = line[6:]
|
| 81 |
+
if data == "[DONE]":
|
| 82 |
+
break
|
| 83 |
+
try:
|
| 84 |
+
chunk_data = json.loads(data)
|
| 85 |
+
if 'choices' in chunk_data and len(chunk_data['choices']) > 0:
|
| 86 |
+
delta = chunk_data['choices'][0].get('delta', {})
|
| 87 |
+
content = delta.get('content', '')
|
| 88 |
+
|
| 89 |
+
if content:
|
| 90 |
+
# Check for thinking tags
|
| 91 |
+
if '<thinking>' in content:
|
| 92 |
+
in_thinking = True
|
| 93 |
+
thinking_content += content.replace('<thinking>', '')
|
| 94 |
+
elif '</thinking>' in content:
|
| 95 |
+
thinking_content += content.replace('</thinking>', '')
|
| 96 |
+
in_thinking = False
|
| 97 |
+
elif in_thinking:
|
| 98 |
+
thinking_content += content
|
| 99 |
+
else:
|
| 100 |
+
final_content += content
|
| 101 |
+
|
| 102 |
+
except json.JSONDecodeError:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
return {
|
| 106 |
+
"thinking": thinking_content.strip(),
|
| 107 |
+
"content": final_content.strip()
|
| 108 |
+
}
|
| 109 |
+
else:
|
| 110 |
+
result = await response.json()
|
| 111 |
+
full_content = result['choices'][0]['message']['content']
|
| 112 |
+
|
| 113 |
+
# Extract thinking and final content from non-streaming response
|
| 114 |
+
thinking_content = ""
|
| 115 |
+
final_content = full_content
|
| 116 |
+
|
| 117 |
+
if '<thinking>' in full_content and '</thinking>' in full_content:
|
| 118 |
+
start_idx = full_content.find('<thinking>') + len('<thinking>')
|
| 119 |
+
end_idx = full_content.find('</thinking>')
|
| 120 |
+
thinking_content = full_content[start_idx:end_idx].strip()
|
| 121 |
+
final_content = full_content[end_idx + len('</thinking>'):].strip()
|
| 122 |
+
|
| 123 |
+
return {
|
| 124 |
+
"thinking": thinking_content,
|
| 125 |
+
"content": final_content
|
| 126 |
+
}
|
| 127 |
else:
|
| 128 |
error_text = await response.text()
|
| 129 |
raise Exception(f"Chutes API error: {response.status} - {error_text}")
|
| 130 |
|
| 131 |
+
def _chutes_chat_sync(self, messages: List[Dict], temperature: float = 0.7, max_tokens: int = 1024, stream: bool = True) -> Dict:
|
| 132 |
"""
|
| 133 |
Synchronous wrapper for Chutes API chat
|
| 134 |
"""
|
|
|
|
| 139 |
asyncio.set_event_loop(loop)
|
| 140 |
|
| 141 |
return loop.run_until_complete(
|
| 142 |
+
self._chutes_chat_async(messages, temperature, max_tokens, stream)
|
| 143 |
)
|
| 144 |
|
| 145 |
def chat(self, message: str,
|
|
|
|
| 189 |
|
| 190 |
Your responses should be well-structured, informative, and properly cited with working links."""
|
| 191 |
else:
|
| 192 |
+
# System prompt for Chutes thinking models
|
| 193 |
+
system_prompt = """You are a creative and intelligent AI assistant with advanced reasoning capabilities.
|
| 194 |
+
Think through problems step-by-step, showing your reasoning process clearly.
|
| 195 |
Be helpful, creative, and engaging while maintaining accuracy.
|
| 196 |
+
Your responses should be well-structured, informative, and comprehensive.
|
| 197 |
+
|
| 198 |
+
When solving complex problems, break them down into steps and explain your thinking process."""
|
| 199 |
|
| 200 |
# Build messages
|
| 201 |
messages = [{"role": "system", "content": system_prompt}]
|
|
|
|
| 230 |
|
| 231 |
return {
|
| 232 |
"content": error_msg,
|
| 233 |
+
"thinking": "",
|
| 234 |
"timestamp": datetime.now().isoformat(),
|
| 235 |
"model": self.model,
|
| 236 |
"provider": self.provider,
|
|
|
|
| 272 |
# Create response object
|
| 273 |
return {
|
| 274 |
"content": processed_content,
|
| 275 |
+
"thinking": "", # Groq doesn't have thinking process
|
| 276 |
"timestamp": datetime.now().isoformat(),
|
| 277 |
"model": self.model,
|
| 278 |
"provider": "groq",
|
|
|
|
| 286 |
}
|
| 287 |
|
| 288 |
def _handle_chutes_chat(self, messages: List[Dict], temperature: float, max_tokens: int, original_message: str) -> Dict:
|
| 289 |
+
"""Handle Chutes API chat with thinking support"""
|
| 290 |
+
result = self._chutes_chat_sync(messages, temperature, max_tokens, stream=True)
|
| 291 |
|
| 292 |
+
thinking_content = result.get("thinking", "")
|
| 293 |
+
final_content = result.get("content", "")
|
| 294 |
+
|
| 295 |
+
# Add to conversation history (only store final content)
|
| 296 |
self.conversation_history.append({"role": "user", "content": original_message})
|
| 297 |
+
self.conversation_history.append({"role": "assistant", "content": final_content})
|
| 298 |
|
| 299 |
# Create response object
|
| 300 |
return {
|
| 301 |
+
"content": final_content,
|
| 302 |
+
"thinking": thinking_content,
|
| 303 |
"timestamp": datetime.now().isoformat(),
|
| 304 |
"model": self.model,
|
| 305 |
"provider": "chutes",
|
|
|
|
| 443 |
test_response = test_ai._chutes_chat_sync(
|
| 444 |
[{"role": "user", "content": "Hello"}],
|
| 445 |
temperature=0.7,
|
| 446 |
+
max_tokens=10,
|
| 447 |
+
stream=False # Use non-streaming for validation
|
| 448 |
)
|
| 449 |
|
| 450 |
# Create AI instance
|
| 451 |
ai_instance = CreativeAgenticAI(chutes_api_key=chutes_api_key, provider="chutes", model=model)
|
| 452 |
api_key_status["chutes"] = "Valid β
"
|
| 453 |
|
| 454 |
+
return f"β
Chutes API Key Valid! Creative AI with Thinking is ready.\n\n**Provider:** Chutes\n**Model:** {model}\n**Status:** Connected with thinking model capabilities!"
|
| 455 |
|
| 456 |
except Exception as e:
|
| 457 |
api_key_status["chutes"] = "Invalid β"
|
|
|
|
| 463 |
if provider == "groq":
|
| 464 |
return ["compound-beta", "compound-beta-mini"]
|
| 465 |
elif provider == "chutes":
|
| 466 |
+
return ["openai/gpt-oss-20b", "meta-llama/llama-3.1-8b-instruct", "anthropic/claude-3-sonnet"]
|
| 467 |
return []
|
| 468 |
|
| 469 |
def update_model_choices(provider: str):
|
|
|
|
| 477 |
system_prompt: str,
|
| 478 |
temperature: float,
|
| 479 |
max_tokens: int,
|
| 480 |
+
history: List,
|
| 481 |
+
show_thinking: bool = True) -> tuple:
|
| 482 |
+
"""Main chat function with thinking support"""
|
| 483 |
global ai_instance, current_provider
|
| 484 |
|
| 485 |
if not ai_instance:
|
|
|
|
| 508 |
max_tokens=int(max_tokens)
|
| 509 |
)
|
| 510 |
|
| 511 |
+
# Format response with thinking (if available and enabled)
|
| 512 |
+
ai_response = ""
|
| 513 |
+
|
| 514 |
+
# Add thinking section for Chutes models
|
| 515 |
+
if current_provider == "chutes" and response.get("thinking") and show_thinking:
|
| 516 |
+
thinking_content = response["thinking"].strip()
|
| 517 |
+
if thinking_content:
|
| 518 |
+
ai_response += f"### π€ **Model's Thinking Process:**\n\n"
|
| 519 |
+
ai_response += f"*The model is reasoning through your question...*\n\n"
|
| 520 |
+
ai_response += f"```thinking\n{thinking_content}\n```\n\n"
|
| 521 |
+
ai_response += "---\n\n### π‘ **Final Response:**\n\n"
|
| 522 |
+
|
| 523 |
+
# Add main content
|
| 524 |
+
ai_response += response["content"]
|
| 525 |
|
| 526 |
# Add enhanced tool usage info (Groq only)
|
| 527 |
if response.get("tool_usage") and current_provider == "groq":
|
|
|
|
| 550 |
|
| 551 |
ai_response += f"\n\n*π Domain filtering applied: {' | '.join(filter_info)}*"
|
| 552 |
|
| 553 |
+
# Add provider and thinking info
|
| 554 |
+
provider_info = f"π€ Powered by: {current_provider.title()} ({response.get('model', 'unknown')})"
|
| 555 |
+
if current_provider == "chutes" and response.get("thinking"):
|
| 556 |
+
if show_thinking:
|
| 557 |
+
provider_info += " | π€ Thinking process shown"
|
| 558 |
+
else:
|
| 559 |
+
provider_info += " | π€ Thinking process hidden"
|
| 560 |
+
|
| 561 |
+
ai_response += f"\n\n*{provider_info}*"
|
| 562 |
|
| 563 |
# Add to history
|
| 564 |
history.append([message, ai_response])
|
|
|
|
| 629 |
padding: 15px;
|
| 630 |
margin: 10px 0;
|
| 631 |
}
|
| 632 |
+
.thinking-info {
|
| 633 |
+
background-color: #e2e3e5;
|
| 634 |
+
border: 1px solid #d6d8db;
|
| 635 |
border-radius: 8px;
|
| 636 |
+
padding: 15px;
|
| 637 |
+
margin: 10px 0;
|
| 638 |
}
|
| 639 |
+
#neuroscope-accordion {
|
| 640 |
background: linear-gradient(to right, #00ff94, #00b4db);
|
| 641 |
border-radius: 8px;
|
|
|
|
| 642 |
}
|
| 643 |
"""
|
| 644 |
|
| 645 |
+
with gr.Blocks(css=css, title="π€ Multi-Provider Creative Agentic AI Chat with Thinking", theme=gr.themes.Ocean()) as app:
|
| 646 |
|
| 647 |
# Header
|
| 648 |
gr.HTML("""
|
| 649 |
<div class="header">
|
| 650 |
+
<h1>π€ NeuroScope-AI Enhanced with Thinking Models</h1>
|
| 651 |
+
<p>Multi-Provider AI Chat Tool - Groq's Compound Models & Chutes Thinking Models</p>
|
| 652 |
</div>
|
| 653 |
""")
|
| 654 |
|
| 655 |
# Provider Selection
|
| 656 |
with gr.Group():
|
| 657 |
+
with gr.Accordion("π€ Multi-Provider NeuroScope AI with Thinking", open=False, elem_id="neuroscope-accordion"):
|
| 658 |
gr.Markdown("""
|
| 659 |
+
**Enhanced with Multiple AI Providers & Thinking Models:**
|
| 660 |
+
- π§ Intelligence (Neuro) - Now supports Groq & Chutes Thinking Models
|
| 661 |
+
- π Advanced capabilities (Scope) - Web search with Groq, reasoning traces with Chutes
|
| 662 |
+
- π€ AI capabilities (AI) - Multiple model options including thinking models
|
| 663 |
- β‘ Precision & Speed (Scope) - Choose the best provider for your needs
|
| 664 |
+
- π€ **NEW**: Thinking process visualization for Chutes models
|
| 665 |
+
""")
|
| 666 |
+
|
| 667 |
+
# Thinking Models Info
|
| 668 |
+
with gr.Group():
|
| 669 |
+
with gr.Accordion("π€ About Chutes Thinking Models", open=False, elem_id="neuroscope-accordion"):
|
| 670 |
+
gr.Markdown("""
|
| 671 |
+
<div class="thinking-info">
|
| 672 |
+
<h3>π§ What are Thinking Models?</h3>
|
| 673 |
+
<p><strong>Chutes Thinking Models</strong> are advanced AI systems that show their reasoning process before providing the final answer.</p>
|
| 674 |
+
|
| 675 |
+
<h4>π How They Work:</h4>
|
| 676 |
+
<ul>
|
| 677 |
+
<li><strong>Step-by-Step Reasoning:</strong> Models think through problems systematically</li>
|
| 678 |
+
<li><strong>Transparent Process:</strong> You can see exactly how the AI reaches its conclusions</li>
|
| 679 |
+
<li><strong>Better Accuracy:</strong> The thinking process often leads to more accurate and well-reasoned responses</li>
|
| 680 |
+
<li><strong>Educational Value:</strong> Learn from the AI's problem-solving approach</li>
|
| 681 |
+
</ul>
|
| 682 |
+
|
| 683 |
+
<h4>π― Available Thinking Models:</h4>
|
| 684 |
+
<ul>
|
| 685 |
+
<li><strong>openai/gpt-oss-20b:</strong> Large-scale reasoning and analysis</li>
|
| 686 |
+
<li><strong>meta-llama/llama-3.1-8b-instruct:</strong> Efficient thinking and instruction following</li>
|
| 687 |
+
<li><strong>anthropic/claude-3-sonnet:</strong> Advanced reasoning and creative thinking</li>
|
| 688 |
+
</ul>
|
| 689 |
+
|
| 690 |
+
<h4>π‘ Best For:</h4>
|
| 691 |
+
<ul>
|
| 692 |
+
<li>Complex problem-solving tasks</li>
|
| 693 |
+
<li>Mathematical and logical reasoning</li>
|
| 694 |
+
<li>Step-by-step analysis</li>
|
| 695 |
+
<li>Educational explanations</li>
|
| 696 |
+
<li>Creative writing with detailed planning</li>
|
| 697 |
+
</ul>
|
| 698 |
+
</div>
|
| 699 |
""")
|
| 700 |
|
| 701 |
# Provider and API Key Section
|
| 702 |
with gr.Row():
|
| 703 |
+
|
| 704 |
with gr.Column():
|
| 705 |
provider_selection = gr.Radio(
|
| 706 |
choices=["groq", "chutes"],
|
|
|
|
| 725 |
info="Get your API key from: https://chutes.ai/",
|
| 726 |
visible=False
|
| 727 |
)
|
| 728 |
+
|
|
|
|
| 729 |
model_selection = gr.Radio(
|
| 730 |
choices=get_available_models("groq"),
|
| 731 |
label="π§ Groq Models",
|
|
|
|
| 733 |
info="compound-beta: More powerful | compound-beta-mini: Faster"
|
| 734 |
)
|
| 735 |
|
| 736 |
+
# Thinking toggle for Chutes
|
| 737 |
+
show_thinking = gr.Checkbox(
|
| 738 |
+
label="π€ Show Thinking Process",
|
| 739 |
+
value=True,
|
| 740 |
+
info="Display the model's reasoning process (Chutes only)",
|
| 741 |
+
visible=False
|
| 742 |
+
)
|
| 743 |
+
|
| 744 |
connect_btn = gr.Button("π Connect", variant="primary", size="lg")
|
| 745 |
|
| 746 |
# Status display
|
|
|
|
| 760 |
- β
**Citation System** - Automatic source linking and references
|
| 761 |
- β‘ **Ultra-fast inference** - Groq's hardware acceleration
|
| 762 |
- π§ **Models**: compound-beta, compound-beta-mini
|
| 763 |
+
- β **No thinking process** - Direct responses without visible reasoning
|
| 764 |
|
| 765 |
+
**π― Chutes (Thinking Models)**
|
| 766 |
- β
**Multiple Model Access** - Various open-source and commercial models
|
| 767 |
+
- β
**Thinking Process** - See the model's step-by-step reasoning
|
| 768 |
+
- β
**High-quality reasoning** - Better accuracy through visible thinking
|
| 769 |
+
- β
**Educational Value** - Learn from AI's problem-solving approach
|
| 770 |
- β‘ **Good performance** - Reliable and fast responses
|
| 771 |
+
- π§ **Models**: GPT-OSS-20B, Llama 3.1, Claude 3 Sonnet (all with thinking)
|
| 772 |
- β **No web search** - Relies on training data only
|
| 773 |
|
| 774 |
**π‘ Use Groq when you need:**
|
| 775 |
- Real-time information and web search
|
| 776 |
- Research with source citations
|
| 777 |
- Domain-specific searches
|
| 778 |
+
- Ultra-fast responses
|
| 779 |
|
| 780 |
**π‘ Use Chutes when you need:**
|
| 781 |
+
- Complex problem-solving with visible reasoning
|
| 782 |
+
- Educational explanations
|
| 783 |
+
- Mathematical and logical analysis
|
| 784 |
+
- Creative planning with detailed thinking
|
| 785 |
+
- Understanding AI's reasoning process
|
| 786 |
</div>
|
| 787 |
""")
|
| 788 |
|
|
|
|
| 797 |
gr.update(visible=chutes_visible), # chutes_api_key
|
| 798 |
gr.update(choices=models, value=models[0] if models else None,
|
| 799 |
label=f"π§ {provider.title()} Models"), # model_selection
|
| 800 |
+
gr.update(visible=chutes_visible), # show_thinking
|
| 801 |
+
gr.update(visible=groq_visible), # domain_group (will be defined later)
|
|
|
|
| 802 |
)
|
| 803 |
|
| 804 |
provider_selection.change(
|
| 805 |
fn=update_provider_ui,
|
| 806 |
inputs=[provider_selection],
|
| 807 |
+
outputs=[groq_api_key, chutes_api_key, model_selection, show_thinking, domain_group] # domain_group will be added later
|
| 808 |
)
|
| 809 |
|
| 810 |
# Connect button functionality
|
|
|
|
| 817 |
# Main Chat Interface
|
| 818 |
with gr.Tab("π¬ Chat"):
|
| 819 |
chatbot = gr.Chatbot(
|
| 820 |
+
label="Multi-Provider Creative AI Assistant with Thinking",
|
| 821 |
+
height=600,
|
| 822 |
show_label=True,
|
| 823 |
bubble_full_width=False,
|
| 824 |
show_copy_button=True
|
|
|
|
| 862 |
)
|
| 863 |
|
| 864 |
# Domain Filtering Section (Groq only)
|
| 865 |
+
with gr.Group() as domain_group:
|
| 866 |
with gr.Accordion("π Domain Filtering (Groq Web Search Only)", open=False, elem_id="neuroscope-accordion"):
|
| 867 |
gr.Markdown("""
|
| 868 |
<div class="domain-info">
|
|
|
|
| 891 |
info="Never search these domains"
|
| 892 |
)
|
| 893 |
|
| 894 |
+
with gr.Accordion("π Common Domain Examples", open=False, elem_id="neuroscope-accordion"):
|
| 895 |
gr.Markdown("""
|
| 896 |
**Academic & Research:**
|
| 897 |
- `arxiv.org`, `*.edu`, `scholar.google.com`, `researchgate.net`
|
|
|
|
| 909 |
- `nature.com`, `science.org`, `pubmed.ncbi.nlm.nih.gov`, `who.int`
|
| 910 |
""")
|
| 911 |
|
| 912 |
+
# Update provider UI function with domain filtering and thinking toggle
|
| 913 |
def update_provider_ui_complete(provider):
|
| 914 |
groq_visible = provider == "groq"
|
| 915 |
chutes_visible = provider == "chutes"
|
|
|
|
| 920 |
gr.update(visible=chutes_visible), # chutes_api_key
|
| 921 |
gr.update(choices=models, value=models[0] if models else None,
|
| 922 |
label=f"π§ {provider.title()} Models"), # model_selection
|
| 923 |
+
gr.update(visible=chutes_visible), # show_thinking
|
| 924 |
gr.update(visible=groq_visible), # domain_group
|
| 925 |
)
|
| 926 |
|
| 927 |
provider_selection.change(
|
| 928 |
fn=update_provider_ui_complete,
|
| 929 |
inputs=[provider_selection],
|
| 930 |
+
outputs=[groq_api_key, chutes_api_key, model_selection, show_thinking, domain_group]
|
| 931 |
)
|
| 932 |
|
| 933 |
+
# IMPORTANT Section with Citation Info and Thinking
|
| 934 |
with gr.Group():
|
| 935 |
+
with gr.Accordion("π IMPORTANT - Citations & Thinking Models!", open=False, elem_id="neuroscope-accordion"):
|
| 936 |
gr.Markdown("""
|
| 937 |
<div class="citation-info">
|
| 938 |
+
<h3>π Multi-Provider Enhancement with Thinking Models</h3>
|
| 939 |
<p>This enhanced version now supports both Groq and Chutes AI providers:</p>
|
| 940 |
<ul>
|
| 941 |
<li><strong>π Groq Integration:</strong> Agentic AI with web search, citations, and tool usage</li>
|
| 942 |
+
<li><strong>π― Chutes Integration:</strong> Multiple thinking models with visible reasoning processes</li>
|
| 943 |
+
<li><strong>π€ Thinking Process:</strong> See step-by-step reasoning from Chutes models</li>
|
| 944 |
<li><strong>π Easy Switching:</strong> Switch between providers based on your needs</li>
|
| 945 |
<li><strong>π Provider Comparison:</strong> Clear information about each provider's strengths</li>
|
| 946 |
</ul>
|
|
|
|
| 954 |
<li><strong>Search Query Tracking:</strong> Shows what queries were made to find information</li>
|
| 955 |
</ul>
|
| 956 |
|
| 957 |
+
<h3>π€ Chutes Thinking Model Features</h3>
|
| 958 |
<p>When using Chutes, you get access to:</p>
|
| 959 |
<ul>
|
| 960 |
+
<li><strong>Thinking Process Visualization:</strong> See exactly how the AI reasons through problems</li>
|
| 961 |
+
<li><strong>Step-by-Step Analysis:</strong> Watch the model break down complex questions</li>
|
| 962 |
+
<li><strong>Toggle Thinking Display:</strong> Choose to show or hide the reasoning process</li>
|
| 963 |
+
<li><strong>Educational Value:</strong> Learn from AI's problem-solving approaches</li>
|
| 964 |
+
<li><strong>Multiple Thinking Models:</strong> Different models with unique reasoning styles</li>
|
| 965 |
</ul>
|
| 966 |
</div>
|
| 967 |
|
|
|
|
| 982 |
- Useful for **filtering out unreliable or unwanted sources**.
|
| 983 |
- Allows broad search with **targeted exclusions**.
|
| 984 |
|
| 985 |
+
### π€ **Thinking Models Behavior (Chutes Only)**
|
| 986 |
+
|
| 987 |
+
**How Thinking Models Work:**
|
| 988 |
+
- Models first **reason through the problem** in a thinking section
|
| 989 |
+
- You can see the **step-by-step thought process**
|
| 990 |
+
- The model then provides its **final polished answer**
|
| 991 |
+
- **Toggle thinking display** on/off as needed
|
| 992 |
+
|
| 993 |
+
**Best Use Cases for Thinking Models:**
|
| 994 |
+
- Complex mathematical problems
|
| 995 |
+
- Logical reasoning tasks
|
| 996 |
+
- Creative writing with planning
|
| 997 |
+
- Educational explanations
|
| 998 |
+
- Problem-solving scenarios
|
| 999 |
|
| 1000 |
---
|
| 1001 |
|
|
|
|
| 1006 |
- A **professional business consultant**
|
| 1007 |
- A **coding mentor**
|
| 1008 |
- A **creative writer**
|
| 1009 |
+
- A **step-by-step tutor** (especially effective with thinking models)
|
| 1010 |
- A **specific character or persona**
|
| 1011 |
- Provides full control to **reshape the AI's tone, expertise, and conversational style** with a single prompt.
|
| 1012 |
""")
|
| 1013 |
|
| 1014 |
# How to Use Section
|
| 1015 |
+
with gr.Accordion("π How to Use This Enhanced Multi-Provider App with Thinking", open=False, elem_id="neuroscope-accordion"):
|
| 1016 |
gr.Markdown("""
|
| 1017 |
### π Getting Started
|
| 1018 |
+
1. **Choose your AI Provider** - Select between Groq (web search + agentic) or Chutes (thinking models)
|
| 1019 |
2. **Enter your API Key** -
|
| 1020 |
- Groq: Get one from [console.groq.com](https://console.groq.com/)
|
| 1021 |
- Chutes: Get one from [chutes.ai](https://chutes.ai/)
|
| 1022 |
3. **Select a model** - Choose from provider-specific model options
|
| 1023 |
+
4. **Configure thinking display** - For Chutes, decide if you want to see the reasoning process
|
| 1024 |
+
5. **Click Connect** - Validate your key and connect to the AI
|
| 1025 |
+
6. **Start chatting!** - Type your message and get intelligent responses
|
| 1026 |
|
| 1027 |
### π― Key Features
|
| 1028 |
**π Groq Features:**
|
|
|
|
| 1032 |
- **Ultra-fast**: Groq's hardware-accelerated inference
|
| 1033 |
|
| 1034 |
**π― Chutes Features:**
|
| 1035 |
+
- **Thinking Models**: See the model's step-by-step reasoning process
|
| 1036 |
+
- **Multiple Models**: Access to GPT-OSS-20B, Llama 3.1, Claude 3 Sonnet
|
| 1037 |
+
- **Educational**: Learn from AI's problem-solving approaches
|
| 1038 |
+
- **Toggle Thinking**: Show/hide the reasoning process as needed
|
| 1039 |
+
- **High Quality**: Excellent reasoning and analysis capabilities
|
| 1040 |
|
| 1041 |
**π Universal Features:**
|
| 1042 |
- **Memory**: Maintains conversation context throughout the session
|
|
|
|
| 1050 |
- Check the "Sources Used" section for all references
|
| 1051 |
- Try different domain combinations to see varied results
|
| 1052 |
|
| 1053 |
+
**For Chutes (Thinking Models):**
|
| 1054 |
+
- Ask complex, multi-step questions to see rich thinking processes
|
| 1055 |
+
- Use for educational purposes - the thinking is very instructive
|
| 1056 |
+
- Try mathematical problems, logical puzzles, or creative planning tasks
|
| 1057 |
+
- Toggle thinking display based on whether you want to see the process
|
| 1058 |
+
- Different models have different thinking styles - experiment!
|
| 1059 |
|
| 1060 |
**General:**
|
| 1061 |
- Adjust temperature: higher for creativity, lower for precision
|
| 1062 |
- Try different system prompts for different conversation styles
|
| 1063 |
- Use the provider that best fits your current task
|
| 1064 |
+
- For learning: use Chutes with thinking display enabled
|
| 1065 |
+
- For research: use Groq with appropriate domain filtering
|
| 1066 |
""")
|
| 1067 |
|
| 1068 |
# Sample Examples Section
|
| 1069 |
+
with gr.Accordion("π― Sample Examples to Test Both Providers & Thinking", open=False, elem_id="neuroscope-accordion"):
|
| 1070 |
gr.Markdown("""
|
| 1071 |
<div class="example-box">
|
| 1072 |
<h4>π Provider Comparison Examples</h4>
|
| 1073 |
<p>Try the same prompts with both providers to see the difference:</p>
|
| 1074 |
|
| 1075 |
+
<h4>π€ Perfect for Thinking Models (Chutes)</h4>
|
| 1076 |
<ul>
|
| 1077 |
+
<li><strong>Math & Logic:</strong> "Solve this step by step: If a train travels 120 miles in 2 hours, and then 180 miles in 3 hours, what's the average speed for the entire journey?"</li>
|
| 1078 |
+
<li><strong>Problem Solving:</strong> "I have a budget of $1000 for a home office setup. Help me plan the best allocation across desk, chair, computer, and lighting."</li>
|
| 1079 |
+
<li><strong>Creative Planning:</strong> "Plan a short story about a time traveler who accidentally changes history. Walk through the plot structure."</li>
|
| 1080 |
+
<li><strong>Analysis:</strong> "Compare and contrast the pros and cons of remote work vs office work, considering productivity, collaboration, and work-life balance."</li>
|
| 1081 |
</ul>
|
| 1082 |
|
| 1083 |
+
<h4>π¬ Research & Real-time Info (Groq)</h4>
|
| 1084 |
<ul>
|
| 1085 |
+
<li><strong>Current Events:</strong> "What are the latest developments in AI research in 2024?"</li>
|
| 1086 |
+
<li><strong>Tech Updates:</strong> "What are the newest features in React 19?"</li>
|
| 1087 |
+
<li><strong>Market Analysis:</strong> "Current trends in cryptocurrency markets with sources"</li>
|
| 1088 |
+
<li><strong>Scientific Updates:</strong> "Recent breakthroughs in quantum computing research"</li>
|
| 1089 |
</ul>
|
| 1090 |
|
| 1091 |
+
<h4>π» Programming & Tech (Compare Both)</h4>
|
| 1092 |
<ul>
|
| 1093 |
+
<li><strong>Groq:</strong> "What are the current best practices for React 18 in 2024?" (with web search)</li>
|
| 1094 |
+
<li><strong>Chutes:</strong> "Explain how to build a React component with useState, and walk through your reasoning for the design choices"</li>
|
|
|
|
|
|
|
| 1095 |
</ul>
|
| 1096 |
|
| 1097 |
+
<h4>π¨ Creative Tasks (Great for Thinking Models)</h4>
|
| 1098 |
<ul>
|
| 1099 |
+
<li>"Write a marketing strategy for a new eco-friendly product, showing your planning process"</li>
|
| 1100 |
+
<li>"Create a study plan for learning Python in 3 months, explaining your reasoning for each phase"</li>
|
| 1101 |
+
<li>"Design a mobile app concept for meditation, walking through your design thinking"</li>
|
| 1102 |
</ul>
|
| 1103 |
|
| 1104 |
+
<h4>π§ Model-Specific Testing (Chutes Thinking)</h4>
|
| 1105 |
<ul>
|
| 1106 |
+
<li><strong>GPT-OSS-20B:</strong> "Explain quantum entanglement in simple terms, showing your thought process for making it accessible"</li>
|
| 1107 |
+
<li><strong>Llama 3.1:</strong> "Debug this Python code and explain your debugging approach: [code with intentional errors]"</li>
|
| 1108 |
+
<li><strong>Claude 3 Sonnet:</strong> "Analyze this business scenario and provide strategic recommendations, showing your analytical framework"</li>
|
| 1109 |
+
</ul>
|
| 1110 |
+
|
| 1111 |
+
<h4>π Side-by-Side Comparisons</h4>
|
| 1112 |
+
<ul>
|
| 1113 |
+
<li><strong>Same Question, Different Providers:</strong> Ask "How do neural networks work?" to both providers</li>
|
| 1114 |
+
<li><strong>Groq Result:</strong> Fast response with potential web sources and current information</li>
|
| 1115 |
+
<li><strong>Chutes Result:</strong> Detailed thinking process showing how the model breaks down the explanation</li>
|
| 1116 |
</ul>
|
| 1117 |
</div>
|
| 1118 |
""")
|
| 1119 |
|
| 1120 |
+
# Event handlers - Updated to include thinking toggle
|
| 1121 |
send_btn.click(
|
| 1122 |
fn=chat_with_ai,
|
| 1123 |
+
inputs=[msg, include_domains, exclude_domains, system_prompt, temperature, max_tokens, chatbot, show_thinking],
|
| 1124 |
outputs=[chatbot, msg]
|
| 1125 |
)
|
| 1126 |
|
| 1127 |
msg.submit(
|
| 1128 |
fn=chat_with_ai,
|
| 1129 |
+
inputs=[msg, include_domains, exclude_domains, system_prompt, temperature, max_tokens, chatbot, show_thinking],
|
| 1130 |
outputs=[chatbot, msg]
|
| 1131 |
)
|
| 1132 |
|
|
|
|
| 1136 |
)
|
| 1137 |
|
| 1138 |
# Footer
|
| 1139 |
+
with gr.Accordion("π About This Enhanced Multi-Provider Tool with Thinking", open=True, elem_id="neuroscope-accordion"):
|
| 1140 |
gr.Markdown("""
|
| 1141 |
+
**Enhanced Multi-Provider Creative Agentic AI Chat Tool** with thinking model support:
|
| 1142 |
|
| 1143 |
+
**π New Thinking Model Features:**
|
| 1144 |
+
- π€ **Thinking Process Visualization**: See step-by-step reasoning from Chutes models
|
| 1145 |
+
- π§ **Multiple Thinking Models**: GPT-OSS-20B, Llama 3.1, Claude 3 Sonnet with reasoning
|
| 1146 |
+
- π **Toggle Thinking Display**: Choose to show or hide the reasoning process
|
| 1147 |
+
- π **Educational Value**: Learn from AI's problem-solving approaches
|
| 1148 |
+
- π― **Better Accuracy**: Thinking process often leads to more accurate responses
|
| 1149 |
|
| 1150 |
**π Groq Features:**
|
| 1151 |
- π **Automatic Source Citations**: Every response includes clickable links to sources
|
|
|
|
| 1157 |
- π§ Advanced AI reasoning with tool usage
|
| 1158 |
|
| 1159 |
**π― Chutes Features:**
|
| 1160 |
+
- π€ **Multiple Thinking Models**: Various AI models with visible reasoning
|
| 1161 |
- π° **Cost-Effective**: Competitive pricing for AI access
|
| 1162 |
+
- π¨ **Creative Excellence**: Optimized for reasoning and analysis tasks
|
| 1163 |
+
- β‘ **Reliable Performance**: Consistent and thoughtful responses
|
| 1164 |
+
- π **Learning Tool**: Perfect for understanding AI reasoning
|
| 1165 |
|
| 1166 |
**π Universal Features:**
|
| 1167 |
- π¬ Conversational memory and context
|
|
|
|
| 1171 |
|
| 1172 |
**π‘ Choose Your Provider:**
|
| 1173 |
- **Use Groq** when you need real-time information, web search, and citations
|
| 1174 |
+
- **Use Chutes** when you want to see the thinking process, need complex reasoning, or want educational explanations
|
| 1175 |
+
- **Toggle thinking display** in Chutes to customize your experience
|
| 1176 |
+
|
| 1177 |
+
**π Perfect for:**
|
| 1178 |
+
- Students learning problem-solving approaches
|
| 1179 |
+
- Developers wanting to understand AI reasoning
|
| 1180 |
+
- Researchers needing both current information (Groq) and deep analysis (Chutes)
|
| 1181 |
+
- Anyone curious about how AI thinks through problems
|
| 1182 |
""")
|
| 1183 |
|
| 1184 |
return app
|