dbagent-cli 0.6.0__tar.gz → 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/PKG-INFO +1 -1
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/__init__.py +1 -1
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/cli.py +165 -54
- dbagent_cli-0.7.0/dbagent/llm/anthropic_provider.py +126 -0
- dbagent_cli-0.7.0/dbagent/llm/deepseek_provider.py +128 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/llm/factory.py +47 -10
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/llm/gemini_provider.py +4 -5
- dbagent_cli-0.7.0/dbagent/llm/mistral_provider.py +129 -0
- dbagent_cli-0.7.0/dbagent/llm/openai_provider.py +131 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent_cli.egg-info/PKG-INFO +1 -1
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent_cli.egg-info/SOURCES.txt +5 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/pyproject.toml +1 -1
- dbagent_cli-0.7.0/tests/test_providers.py +69 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/README.md +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/agent/confidence.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/agent/conversation.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/agent/doctor.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/agent/error_classifier.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/agent/generator.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/agent/pipeline.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/agent/recommender.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/agent/validator.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/config.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/connectors/base.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/connectors/factory.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/connectors/mongo.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/connectors/relational.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/execution/__init__.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/execution/cache.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/execution/changeset.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/execution/cost.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/execution/recovery.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/execution/sandbox.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/execution/streaming.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/llm/auto_setup.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/llm/base.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/llm/groq_provider.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/llm/mock_provider.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/llm/ollama_provider.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/llm/openrouter_provider.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/schema/cache.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/schema/formatter.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/schema/graph.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/schema/models.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/schema/retriever.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/schema/selector.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/security/__init__.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/security/audit.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/security/environment.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/security/masking.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/security/modes.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/security/rbac.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/semantic/__init__.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/semantic/dictionary.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/semantic/templates.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/sql/__init__.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/sql/optimizer.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/sql/validator.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/ui/chat_screen.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/ui/console.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/ui/grid_window.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/ui/viewer.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent/ui/visualizer.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent_cli.egg-info/dependency_links.txt +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent_cli.egg-info/entry_points.txt +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent_cli.egg-info/requires.txt +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/dbagent_cli.egg-info/top_level.txt +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/setup.cfg +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_cache.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_cli.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_connectors.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_doctor_and_viz.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_generator.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_graph.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_recovery.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_safety.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_sandbox.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_schema.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_security.py +0 -0
- {dbagent_cli-0.6.0 → dbagent_cli-0.7.0}/tests/test_semantic.py +0 -0
|
@@ -531,9 +531,9 @@ def chat_command(
|
|
|
531
531
|
console.print(" [bold]:doctor[/bold] -> Run database health diagnostics")
|
|
532
532
|
console.print(" [bold]:mode <name>[/bold] -> Switch mode (SAFE, READ_ONLY, CONFIRM, SANDBOX, ADMIN)")
|
|
533
533
|
console.print(" [bold]:changes[/bold] -> List recent write ChangeSets")
|
|
534
|
-
console.print(" [bold]:provider <name>[/bold] -> Switch AI provider (
|
|
535
|
-
console.print(" [bold]:
|
|
536
|
-
console.print(" [bold]:
|
|
534
|
+
console.print(" [bold]:provider <name>[/bold] -> Switch AI provider (gemini, ollama, groq, openrouter)")
|
|
535
|
+
console.print(" [bold]:models[/bold] -> View list of available AI models & speed benchmarks")
|
|
536
|
+
console.print(" [bold]:model <num|name>[/bold] -> Switch active model (:model 1, :model 3.7, :model 3.6)")
|
|
537
537
|
console.print(" [bold]:page <n>[/bold] -> View column page <n> for wide multi-column tables")
|
|
538
538
|
console.print(" [bold]:card[/bold] -> View last result in expanded vertical card format (all columns)")
|
|
539
539
|
console.print(" [bold]:wide[/bold] -> Force-show all columns in terminal (zoom out)")
|
|
@@ -687,33 +687,100 @@ def chat_command(
|
|
|
687
687
|
if not cmd_arg:
|
|
688
688
|
curr_model = model or getattr(llm, "default_model", "default")
|
|
689
689
|
console.print(f"\n[bold cyan]Active AI Provider:[/bold cyan] [bold white]{llm.name}[/bold white] | Model: [bold green]{curr_model}[/bold green]")
|
|
690
|
-
console.print("[dim]
|
|
690
|
+
console.print("[dim]Supported: [bold]claude, openai, deepseek, mistral, gemini, groq, openrouter, ollama[/bold][/dim]\n")
|
|
691
691
|
continue
|
|
692
|
-
prov_target = cmd_arg.lower()
|
|
693
|
-
if prov_target in ["
|
|
692
|
+
prov_target = cmd_arg.lower().strip()
|
|
693
|
+
if prov_target in ["claude", "anthropic", "openai", "chatgpt", "gpt", "deepseek", "mistral", "gemini", "groq", "openrouter", "ollama", "local", "mock"]:
|
|
694
694
|
llm = get_llm_provider(provider_name=prov_target, config_mgr=config_mgr)
|
|
695
695
|
model = None
|
|
696
696
|
pipeline.generator.llm = llm # Update reused pipeline
|
|
697
697
|
print_success(f"Switched AI provider to [bold cyan]{llm.name}[/bold cyan]")
|
|
698
|
+
if not llm.is_available() and llm.name not in ["ollama", "mock"]:
|
|
699
|
+
print_warning(f"Note: API key for {llm.name} is not set. Run `db-agent config` or set {llm.name.upper()}_API_KEY.")
|
|
698
700
|
else:
|
|
699
|
-
print_error(f"Unknown provider '{cmd_arg}'. Supported:
|
|
701
|
+
print_error(f"Unknown provider '{cmd_arg}'. Supported: claude, openai, deepseek, mistral, gemini, groq, openrouter, ollama")
|
|
700
702
|
continue
|
|
701
703
|
|
|
702
|
-
if cmd_name
|
|
703
|
-
if
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
704
|
+
if cmd_name in [":model", ":models", ":providers", ":ai"]:
|
|
705
|
+
avail_models = llm.list_models() if hasattr(llm, "list_models") else []
|
|
706
|
+
curr_model = model or getattr(llm, "default_model", "default")
|
|
707
|
+
|
|
708
|
+
# If no arg passed or :models/:providers called, show rich model selection menu
|
|
709
|
+
if not cmd_arg or cmd_name in [":models", ":providers", ":ai"]:
|
|
710
|
+
console.print(f"\n[bold cyan]Active AI Provider:[/bold cyan] [bold white]{llm.name}[/bold white]")
|
|
711
|
+
console.print(f"[bold cyan]Active Model:[/bold cyan] [bold green]{curr_model}[/bold green]\n")
|
|
712
|
+
if avail_models:
|
|
713
|
+
console.print(f"[bold]Available Models for {llm.name}:[/bold]")
|
|
714
|
+
model_descriptions = {
|
|
715
|
+
# Gemini
|
|
716
|
+
"gemini-flash-lite-latest": "⚡ Ultra-Fast (~0.8s) • Instant chat & queries",
|
|
717
|
+
"gemini-3.6-flash": "⚡ High Quality (~3.5s) • Strong SQL reasoning & accuracy",
|
|
718
|
+
"gemini-3.7-flash": "🧠 Deep Reasoning (~13s) • Latest flagship model",
|
|
719
|
+
"gemini-3.1-flash-lite": "⚡ Fast Lite (~4.0s) • Low latency",
|
|
720
|
+
"gemini-flash-latest": "⚡ Standard Flash (~7.0s)",
|
|
721
|
+
# Claude
|
|
722
|
+
"claude-3-7-sonnet-20250219": "🧠 Hybrid Reasoning Flagship • Deepest architecture understanding",
|
|
723
|
+
"claude-3-5-sonnet-20241022": "⚡ High Intelligence • Expert SQL engineer & schema specialist",
|
|
724
|
+
"claude-3-5-haiku-20241022": "⚡ Ultra-Fast (~1s) • High speed and cost efficient",
|
|
725
|
+
"claude-3-opus-20240229": "Deep complex schema reasoning",
|
|
726
|
+
# OpenAI
|
|
727
|
+
"gpt-4o": "⚡ Omni Flagship • High speed multimodal & complex SQL reasoning",
|
|
728
|
+
"gpt-4o-mini": "⚡ Ultra-Fast (~1s) • High speed and cost efficient",
|
|
729
|
+
"gpt-4.5-preview": "🧠 Next-Generation Reasoning model",
|
|
730
|
+
"o3-mini": "🧠 Deep STEM & Advanced Coding Reasoning",
|
|
731
|
+
"o1": "🧠 Maximum Reasoning & Math Architecture",
|
|
732
|
+
# DeepSeek
|
|
733
|
+
"deepseek-chat": "⚡ DeepSeek-V3 Ultra-Fast • Strong code & SQL",
|
|
734
|
+
"deepseek-reasoner": "🧠 DeepSeek-R1 Full Chain-of-Thought Reasoning",
|
|
735
|
+
# Mistral
|
|
736
|
+
"codestral-latest": "⚡ Specialized Code & SQL Architect (22B)",
|
|
737
|
+
"mistral-large-latest": "🧠 Flagship Reasoning & Multi-language",
|
|
738
|
+
"mistral-small-latest": "⚡ Fast & lightweight",
|
|
739
|
+
# Groq
|
|
740
|
+
"llama-3.3-70b-versatile": "⚡ Llama 3.3 70B (500+ tokens/sec on Groq LPUs)",
|
|
741
|
+
"llama-3.1-8b-instant": "⚡ Ultra-Fast Llama 3.1 8B (800+ tokens/sec)",
|
|
742
|
+
"qwen-2.5-coder-32b": "⚡ Qwen 2.5 Coder 32B specialized SQL engineer",
|
|
743
|
+
}
|
|
744
|
+
for idx, m_name in enumerate(avail_models, 1):
|
|
745
|
+
is_active = " [bold green]✓ Active[/bold green]" if m_name == curr_model else ""
|
|
746
|
+
desc = model_descriptions.get(m_name, "")
|
|
747
|
+
desc_str = f" - [dim]{desc}[/dim]" if desc else ""
|
|
748
|
+
console.print(f" [bold cyan]{idx}[/bold cyan]. [bold white]{m_name}[/bold white]{desc_str}{is_active}")
|
|
749
|
+
console.print("\n[dim]Quick Switch: [bold]:model <number|name>[/bold] (e.g. [bold]:model 1[/bold] or [bold]:model 3.7[/bold] or [bold]:model 4o[/bold] or [bold]:model r1[/bold])[/dim]\n")
|
|
707
750
|
continue
|
|
708
|
-
model = cmd_arg
|
|
709
|
-
print_success(f"Switched active model to [bold cyan]{model}[/bold cyan] (Provider: {llm.name})")
|
|
710
|
-
continue
|
|
711
751
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
752
|
+
# Handle numeric shortcut or name shortcut
|
|
753
|
+
target_model = cmd_arg.strip()
|
|
754
|
+
if target_model.isdigit() and avail_models:
|
|
755
|
+
choice_idx = int(target_model) - 1
|
|
756
|
+
if 0 <= choice_idx < len(avail_models):
|
|
757
|
+
target_model = avail_models[choice_idx]
|
|
758
|
+
elif target_model in ["3.7", "37"]:
|
|
759
|
+
target_model = "claude-3-7-sonnet-20250219" if llm.name == "claude" else "gemini-3.7-flash"
|
|
760
|
+
elif target_model in ["3.5", "35"]:
|
|
761
|
+
target_model = "claude-3-5-sonnet-20241022" if llm.name == "claude" else "gemini-3.5-flash"
|
|
762
|
+
elif target_model in ["3.6", "36"]:
|
|
763
|
+
target_model = "gemini-3.6-flash"
|
|
764
|
+
elif target_model in ["4o", "gpt4o"]:
|
|
765
|
+
target_model = "gpt-4o"
|
|
766
|
+
elif target_model in ["mini", "4o-mini"]:
|
|
767
|
+
target_model = "gpt-4o-mini"
|
|
768
|
+
elif target_model in ["r1", "reasoner"]:
|
|
769
|
+
target_model = "deepseek-reasoner"
|
|
770
|
+
elif target_model in ["v3", "chat"]:
|
|
771
|
+
target_model = "deepseek-chat"
|
|
772
|
+
elif target_model in ["codestral"]:
|
|
773
|
+
target_model = "codestral-latest"
|
|
774
|
+
elif target_model in ["lite", "fast", "flash-lite"]:
|
|
775
|
+
target_model = "gemini-flash-lite-latest" if llm.name == "gemini" else "claude-3-5-haiku-20241022"
|
|
776
|
+
elif avail_models:
|
|
777
|
+
matches = [m for m in avail_models if target_model.lower() in m.lower()]
|
|
778
|
+
if matches:
|
|
779
|
+
target_model = matches[0]
|
|
780
|
+
|
|
781
|
+
model = target_model
|
|
782
|
+
pipeline.model = model
|
|
783
|
+
print_success(f"Switched active model to [bold cyan]{model}[/bold cyan] (Provider: {llm.name})")
|
|
717
784
|
continue
|
|
718
785
|
|
|
719
786
|
if cmd_name == ":explain":
|
|
@@ -1554,7 +1621,7 @@ def run_command(
|
|
|
1554
1621
|
|
|
1555
1622
|
@app.command(name="config")
|
|
1556
1623
|
def config_command():
|
|
1557
|
-
"""Interactive wizard to configure AI providers and
|
|
1624
|
+
"""Interactive wizard to configure AI providers and credentials."""
|
|
1558
1625
|
print_banner()
|
|
1559
1626
|
console.print("[bold cyan]DB-Agent Configuration Wizard[/bold cyan]\n")
|
|
1560
1627
|
|
|
@@ -1562,14 +1629,38 @@ def config_command():
|
|
|
1562
1629
|
console.print(f"Current Default AI Provider: [bold green]{curr_provider}[/bold green]")
|
|
1563
1630
|
provider_choice = Prompt.ask(
|
|
1564
1631
|
"Select Default AI Provider",
|
|
1565
|
-
choices=["
|
|
1632
|
+
choices=["gemini", "claude", "openai", "deepseek", "mistral", "groq", "openrouter", "ollama", "keep"],
|
|
1566
1633
|
default="keep",
|
|
1567
1634
|
)
|
|
1568
1635
|
if provider_choice != "keep":
|
|
1569
1636
|
config_mgr.set_setting("default_provider", provider_choice)
|
|
1570
1637
|
print_success(f"Default provider updated to [bold]{provider_choice}[/bold]")
|
|
1571
1638
|
|
|
1572
|
-
if provider_choice
|
|
1639
|
+
if provider_choice in ["claude", "anthropic"]:
|
|
1640
|
+
console.print("[dim]Get your Anthropic API key at: [bold]https://console.anthropic.com[/bold][/dim]")
|
|
1641
|
+
key = Prompt.ask("Enter ANTHROPIC_API_KEY", default=config_mgr.get_setting("anthropic_api_key", "")).strip()
|
|
1642
|
+
if key:
|
|
1643
|
+
config_mgr.set_setting("anthropic_api_key", key)
|
|
1644
|
+
print_success("Anthropic Claude API key saved.")
|
|
1645
|
+
elif provider_choice in ["openai", "chatgpt"]:
|
|
1646
|
+
console.print("[dim]Get your OpenAI API key at: [bold]https://platform.openai.com/api-keys[/bold][/dim]")
|
|
1647
|
+
key = Prompt.ask("Enter OPENAI_API_KEY", default=config_mgr.get_setting("openai_api_key", "")).strip()
|
|
1648
|
+
if key:
|
|
1649
|
+
config_mgr.set_setting("openai_api_key", key)
|
|
1650
|
+
print_success("OpenAI API key saved.")
|
|
1651
|
+
elif provider_choice == "deepseek":
|
|
1652
|
+
console.print("[dim]Get your DeepSeek API key at: [bold]https://platform.deepseek.com[/bold][/dim]")
|
|
1653
|
+
key = Prompt.ask("Enter DEEPSEEK_API_KEY", default=config_mgr.get_setting("deepseek_api_key", "")).strip()
|
|
1654
|
+
if key:
|
|
1655
|
+
config_mgr.set_setting("deepseek_api_key", key)
|
|
1656
|
+
print_success("DeepSeek API key saved.")
|
|
1657
|
+
elif provider_choice == "mistral":
|
|
1658
|
+
console.print("[dim]Get your Mistral API key at: [bold]https://console.mistral.ai[/bold][/dim]")
|
|
1659
|
+
key = Prompt.ask("Enter MISTRAL_API_KEY", default=config_mgr.get_setting("mistral_api_key", "")).strip()
|
|
1660
|
+
if key:
|
|
1661
|
+
config_mgr.set_setting("mistral_api_key", key)
|
|
1662
|
+
print_success("Mistral API key saved.")
|
|
1663
|
+
elif provider_choice == "gemini":
|
|
1573
1664
|
console.print("[dim]Get your free Gemini API key at: [bold]https://aistudio.google.com/apikey[/bold][/dim]")
|
|
1574
1665
|
key = Prompt.ask("Enter GEMINI_API_KEY", default=config_mgr.get_setting("gemini_api_key", "")).strip()
|
|
1575
1666
|
if key:
|
|
@@ -1620,33 +1711,29 @@ def profiles_command():
|
|
|
1620
1711
|
|
|
1621
1712
|
@app.command(name="models")
|
|
1622
1713
|
def models_command():
|
|
1623
|
-
"""List available models across local Ollama and
|
|
1714
|
+
"""List available models across local Ollama and all major cloud providers."""
|
|
1624
1715
|
print_banner()
|
|
1625
|
-
console.print("[bold cyan]Supported
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
gemini_status = "[green]Configured[/green]" if gemini.is_available() else "[yellow]Not Configured (Free Key: aistudio.google.com)[/yellow]"
|
|
1638
|
-
console.print(f"\n2. [bold white]Google Gemini (Free Tier)[/bold white] - Status: {gemini_status}")
|
|
1639
|
-
console.print(" Available Models: `gemini-3.6-flash`, `gemini-2.5-flash`, `gemini-2.5-pro`")
|
|
1640
|
-
|
|
1641
|
-
groq = get_llm_provider("groq")
|
|
1642
|
-
groq_status = "[green]Configured[/green]" if groq.is_available() else "[yellow]Not Configured (Free Key: console.groq.com)[/yellow]"
|
|
1643
|
-
console.print(f"\n3. [bold white]Groq (Free Ultra-Fast Tier)[/bold white] - Status: {groq_status}")
|
|
1644
|
-
console.print(" Available Models: `llama-3.3-70b-versatile`, `qwen-2.5-32b`")
|
|
1716
|
+
console.print("[bold cyan]Supported AI Providers & Available Models:[/bold cyan]\n")
|
|
1717
|
+
|
|
1718
|
+
providers_to_show = [
|
|
1719
|
+
("gemini", "Google Gemini", "https://aistudio.google.com/apikey"),
|
|
1720
|
+
("claude", "Anthropic Claude", "https://console.anthropic.com"),
|
|
1721
|
+
("openai", "OpenAI / ChatGPT", "https://platform.openai.com"),
|
|
1722
|
+
("deepseek", "DeepSeek AI", "https://platform.deepseek.com"),
|
|
1723
|
+
("mistral", "Mistral AI", "https://console.mistral.ai"),
|
|
1724
|
+
("groq", "Groq (Ultra-Fast LPUs)", "https://console.groq.com"),
|
|
1725
|
+
("openrouter", "OpenRouter (100+ Models)", "https://openrouter.ai"),
|
|
1726
|
+
("ollama", "Ollama (100% Offline / Local)", "http://localhost:11434"),
|
|
1727
|
+
]
|
|
1645
1728
|
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1729
|
+
for idx, (p_slug, p_label, p_url) in enumerate(providers_to_show, 1):
|
|
1730
|
+
prov = get_llm_provider(p_slug, config_mgr=config_mgr)
|
|
1731
|
+
status = "[bold green]✓ Configured & Ready[/bold green]" if prov.is_available() else f"[yellow]Not Configured ({p_url})[/yellow]"
|
|
1732
|
+
console.print(f"{idx}. [bold white]{p_label}[/bold white] - Status: {status}")
|
|
1733
|
+
models = prov.list_models() if hasattr(prov, "list_models") else []
|
|
1734
|
+
if models:
|
|
1735
|
+
console.print(f" Models: [cyan]{', '.join(models[:5])}[/cyan]")
|
|
1736
|
+
console.print("")
|
|
1650
1737
|
|
|
1651
1738
|
|
|
1652
1739
|
# ---- setup ----
|
|
@@ -1667,7 +1754,7 @@ def setup_command(
|
|
|
1667
1754
|
else:
|
|
1668
1755
|
console.print("[bold white]Choose how you would like to setup DB-Agent:[/bold white]")
|
|
1669
1756
|
console.print(" [bold green]1. Local Offline AI[/bold green] (Ollama + Coding Model) - [italic]100% Free, Private, Zero API Keys[/italic]")
|
|
1670
|
-
console.print(" [bold cyan]2.
|
|
1757
|
+
console.print(" [bold cyan]2. Cloud AI[/bold cyan] (Claude / OpenAI / DeepSeek / Mistral / Gemini / Groq) - [italic]High speed & accuracy[/italic]")
|
|
1671
1758
|
console.print(" [bold yellow]3. Normal Database CLI[/bold yellow] - [italic]No AI, use standard connect, scan & SQL tools only[/italic]\n")
|
|
1672
1759
|
|
|
1673
1760
|
choice = Prompt.ask(
|
|
@@ -1688,17 +1775,41 @@ def setup_command(
|
|
|
1688
1775
|
print_warning("Local setup incomplete. You can still use cloud AI or standard DB tools.")
|
|
1689
1776
|
chosen_provider = "cloud"
|
|
1690
1777
|
elif choice == "2":
|
|
1691
|
-
console.print("\n[bold cyan]Setting up
|
|
1692
|
-
prov = Prompt.ask("Choose provider", choices=["gemini", "groq", "openrouter"], default="gemini")
|
|
1778
|
+
console.print("\n[bold cyan]Setting up Cloud AI Provider...[/bold cyan]")
|
|
1779
|
+
prov = Prompt.ask("Choose provider", choices=["gemini", "claude", "openai", "deepseek", "mistral", "groq", "openrouter"], default="gemini")
|
|
1693
1780
|
config_mgr.set_setting("default_provider", prov)
|
|
1694
|
-
if prov
|
|
1695
|
-
console.print("[dim]Get
|
|
1781
|
+
if prov in ["claude", "anthropic"]:
|
|
1782
|
+
console.print("[dim]Get Anthropic key at: [bold]https://console.anthropic.com[/bold][/dim]")
|
|
1783
|
+
k = Prompt.ask("Enter ANTHROPIC_API_KEY", default="")
|
|
1784
|
+
if k:
|
|
1785
|
+
config_mgr.set_setting("anthropic_api_key", k)
|
|
1786
|
+
print_success("Anthropic Claude API key saved.")
|
|
1787
|
+
elif prov in ["openai", "chatgpt"]:
|
|
1788
|
+
console.print("[dim]Get OpenAI key at: [bold]https://platform.openai.com/api-keys[/bold][/dim]")
|
|
1789
|
+
k = Prompt.ask("Enter OPENAI_API_KEY", default="")
|
|
1790
|
+
if k:
|
|
1791
|
+
config_mgr.set_setting("openai_api_key", k)
|
|
1792
|
+
print_success("OpenAI API key saved.")
|
|
1793
|
+
elif prov == "deepseek":
|
|
1794
|
+
console.print("[dim]Get DeepSeek key at: [bold]https://platform.deepseek.com[/bold][/dim]")
|
|
1795
|
+
k = Prompt.ask("Enter DEEPSEEK_API_KEY", default="")
|
|
1796
|
+
if k:
|
|
1797
|
+
config_mgr.set_setting("deepseek_api_key", k)
|
|
1798
|
+
print_success("DeepSeek API key saved.")
|
|
1799
|
+
elif prov == "mistral":
|
|
1800
|
+
console.print("[dim]Get Mistral key at: [bold]https://console.mistral.ai[/bold][/dim]")
|
|
1801
|
+
k = Prompt.ask("Enter MISTRAL_API_KEY", default="")
|
|
1802
|
+
if k:
|
|
1803
|
+
config_mgr.set_setting("mistral_api_key", k)
|
|
1804
|
+
print_success("Mistral API key saved.")
|
|
1805
|
+
elif prov == "gemini":
|
|
1806
|
+
console.print("[dim]Get free Gemini key at: [bold]https://aistudio.google.com/apikey[/bold][/dim]")
|
|
1696
1807
|
k = Prompt.ask("Enter GEMINI_API_KEY", default="")
|
|
1697
1808
|
if k:
|
|
1698
1809
|
config_mgr.set_setting("gemini_api_key", k)
|
|
1699
1810
|
print_success("Gemini API key saved.")
|
|
1700
1811
|
elif prov == "groq":
|
|
1701
|
-
console.print("[dim]Get free key at: [bold]https://console.groq.com[/bold][/dim]")
|
|
1812
|
+
console.print("[dim]Get free Groq key at: [bold]https://console.groq.com[/bold][/dim]")
|
|
1702
1813
|
k = Prompt.ask("Enter GROQ_API_KEY", default="")
|
|
1703
1814
|
if k:
|
|
1704
1815
|
config_mgr.set_setting("groq_api_key", k)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Anthropic Claude LLM Provider.
|
|
3
|
+
Supports claude-3-7-sonnet-20250219, claude-3-5-sonnet-20241022, claude-3-5-haiku-20241022, claude-3-opus-20240229.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import requests
|
|
9
|
+
from typing import Optional, Callable, List
|
|
10
|
+
from dbagent.llm.base import BaseLLMProvider
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ClaudeProvider(BaseLLMProvider):
|
|
14
|
+
"""Anthropic Claude provider using direct HTTP REST API."""
|
|
15
|
+
|
|
16
|
+
FALLBACK_MODELS = [
|
|
17
|
+
"claude-3-7-sonnet-20250219",
|
|
18
|
+
"claude-3-5-sonnet-20241022",
|
|
19
|
+
"claude-3-5-haiku-20241022",
|
|
20
|
+
"claude-3-opus-20240229",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
def __init__(self, api_key: Optional[str] = None, default_model: str = "claude-3-7-sonnet-20250219"):
|
|
24
|
+
if api_key is not None:
|
|
25
|
+
self.api_key = api_key
|
|
26
|
+
else:
|
|
27
|
+
self.api_key = os.getenv("ANTHROPIC_API_KEY") or os.getenv("CLAUDE_API_KEY")
|
|
28
|
+
self.default_model = default_model
|
|
29
|
+
self._session = requests.Session()
|
|
30
|
+
self._session.headers.update({
|
|
31
|
+
"User-Agent": "DB-Agent/0.7.0",
|
|
32
|
+
"anthropic-version": "2023-06-01",
|
|
33
|
+
"content-type": "application/json",
|
|
34
|
+
})
|
|
35
|
+
if self.api_key:
|
|
36
|
+
self._session.headers.update({"x-api-key": self.api_key})
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def name(self) -> str:
|
|
40
|
+
return "claude"
|
|
41
|
+
|
|
42
|
+
def is_available(self) -> bool:
|
|
43
|
+
return bool(self.api_key)
|
|
44
|
+
|
|
45
|
+
def list_models(self) -> List[str]:
|
|
46
|
+
return self.FALLBACK_MODELS
|
|
47
|
+
|
|
48
|
+
def generate(
|
|
49
|
+
self,
|
|
50
|
+
prompt: str,
|
|
51
|
+
system_prompt: Optional[str] = None,
|
|
52
|
+
model: Optional[str] = None,
|
|
53
|
+
stream_callback: Optional[Callable[[str], None]] = None,
|
|
54
|
+
) -> str:
|
|
55
|
+
if not self.api_key:
|
|
56
|
+
raise ValueError(
|
|
57
|
+
"Anthropic API key is not configured. Set ANTHROPIC_API_KEY environment variable or run `db-agent config`."
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
requested_model = model or self.default_model
|
|
61
|
+
models_to_try = [requested_model]
|
|
62
|
+
for fb in self.FALLBACK_MODELS:
|
|
63
|
+
if fb != requested_model and fb not in models_to_try:
|
|
64
|
+
models_to_try.append(fb)
|
|
65
|
+
|
|
66
|
+
payload = {
|
|
67
|
+
"model": requested_model,
|
|
68
|
+
"max_tokens": 4096,
|
|
69
|
+
"temperature": 0.1,
|
|
70
|
+
"messages": [{"role": "user", "content": prompt}],
|
|
71
|
+
}
|
|
72
|
+
if system_prompt:
|
|
73
|
+
payload["system"] = system_prompt
|
|
74
|
+
|
|
75
|
+
endpoint = "https://api.anthropic.com/v1/messages"
|
|
76
|
+
last_error = None
|
|
77
|
+
|
|
78
|
+
for target_model in models_to_try:
|
|
79
|
+
payload["model"] = target_model
|
|
80
|
+
try:
|
|
81
|
+
if stream_callback:
|
|
82
|
+
payload["stream"] = True
|
|
83
|
+
response = self._session.post(endpoint, json=payload, stream=True, timeout=15)
|
|
84
|
+
if response.status_code == 200:
|
|
85
|
+
full_text = []
|
|
86
|
+
for line in response.iter_lines():
|
|
87
|
+
if line:
|
|
88
|
+
decoded = line.decode("utf-8")
|
|
89
|
+
if decoded.startswith("data: "):
|
|
90
|
+
raw_json = decoded[6:]
|
|
91
|
+
try:
|
|
92
|
+
chunk = json.loads(raw_json)
|
|
93
|
+
delta = chunk.get("delta", {})
|
|
94
|
+
text_piece = delta.get("text", "")
|
|
95
|
+
if text_piece:
|
|
96
|
+
full_text.append(text_piece)
|
|
97
|
+
stream_callback(text_piece)
|
|
98
|
+
except Exception:
|
|
99
|
+
pass
|
|
100
|
+
return "".join(full_text)
|
|
101
|
+
elif response.status_code in (404, 400, 503, 429):
|
|
102
|
+
last_error = f"Model {target_model} status {response.status_code}"
|
|
103
|
+
continue
|
|
104
|
+
else:
|
|
105
|
+
raise RuntimeError(f"Anthropic API error ({response.status_code}): {response.text}")
|
|
106
|
+
else:
|
|
107
|
+
payload["stream"] = False
|
|
108
|
+
response = self._session.post(endpoint, json=payload, timeout=20)
|
|
109
|
+
if response.status_code == 200:
|
|
110
|
+
data = response.json()
|
|
111
|
+
content_blocks = data.get("content", [])
|
|
112
|
+
text_blocks = [b.get("text", "") for b in content_blocks if b.get("type") == "text"]
|
|
113
|
+
return "".join(text_blocks)
|
|
114
|
+
elif response.status_code in (404, 400, 503, 429):
|
|
115
|
+
last_error = f"Model {target_model} status {response.status_code}"
|
|
116
|
+
continue
|
|
117
|
+
else:
|
|
118
|
+
raise RuntimeError(f"Anthropic API error ({response.status_code}): {response.text}")
|
|
119
|
+
except requests.exceptions.Timeout:
|
|
120
|
+
last_error = f"Model {target_model} timed out"
|
|
121
|
+
continue
|
|
122
|
+
except Exception as e:
|
|
123
|
+
last_error = str(e)
|
|
124
|
+
continue
|
|
125
|
+
|
|
126
|
+
raise RuntimeError(f"Anthropic generation error: {last_error or 'All model attempts failed'}")
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DeepSeek AI LLM Provider.
|
|
3
|
+
Supports deepseek-chat (V3) and deepseek-reasoner (R1).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import requests
|
|
9
|
+
from typing import Optional, Callable, List
|
|
10
|
+
from dbagent.llm.base import BaseLLMProvider
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DeepSeekProvider(BaseLLMProvider):
|
|
14
|
+
"""DeepSeek AI provider using direct HTTP REST API."""
|
|
15
|
+
|
|
16
|
+
FALLBACK_MODELS = [
|
|
17
|
+
"deepseek-chat",
|
|
18
|
+
"deepseek-reasoner",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
def __init__(self, api_key: Optional[str] = None, default_model: str = "deepseek-chat"):
|
|
22
|
+
if api_key is not None:
|
|
23
|
+
self.api_key = api_key
|
|
24
|
+
else:
|
|
25
|
+
self.api_key = os.getenv("DEEPSEEK_API_KEY")
|
|
26
|
+
self.default_model = default_model
|
|
27
|
+
self._session = requests.Session()
|
|
28
|
+
self._session.headers.update({
|
|
29
|
+
"User-Agent": "DB-Agent/0.7.0",
|
|
30
|
+
"content-type": "application/json",
|
|
31
|
+
})
|
|
32
|
+
if self.api_key:
|
|
33
|
+
self._session.headers.update({"Authorization": f"Bearer {self.api_key}"})
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def name(self) -> str:
|
|
37
|
+
return "deepseek"
|
|
38
|
+
|
|
39
|
+
def is_available(self) -> bool:
|
|
40
|
+
return bool(self.api_key)
|
|
41
|
+
|
|
42
|
+
def list_models(self) -> List[str]:
|
|
43
|
+
return self.FALLBACK_MODELS
|
|
44
|
+
|
|
45
|
+
def generate(
|
|
46
|
+
self,
|
|
47
|
+
prompt: str,
|
|
48
|
+
system_prompt: Optional[str] = None,
|
|
49
|
+
model: Optional[str] = None,
|
|
50
|
+
stream_callback: Optional[Callable[[str], None]] = None,
|
|
51
|
+
) -> str:
|
|
52
|
+
if not self.api_key:
|
|
53
|
+
raise ValueError(
|
|
54
|
+
"DeepSeek API key is not configured. Set DEEPSEEK_API_KEY environment variable or run `db-agent config`."
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
requested_model = model or self.default_model
|
|
58
|
+
models_to_try = [requested_model]
|
|
59
|
+
for fb in self.FALLBACK_MODELS:
|
|
60
|
+
if fb != requested_model and fb not in models_to_try:
|
|
61
|
+
models_to_try.append(fb)
|
|
62
|
+
|
|
63
|
+
messages = []
|
|
64
|
+
if system_prompt:
|
|
65
|
+
messages.append({"role": "system", "content": system_prompt})
|
|
66
|
+
messages.append({"role": "user", "content": prompt})
|
|
67
|
+
|
|
68
|
+
payload = {
|
|
69
|
+
"model": requested_model,
|
|
70
|
+
"messages": messages,
|
|
71
|
+
"temperature": 0.1,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
endpoint = "https://api.deepseek.com/v1/chat/completions"
|
|
75
|
+
last_error = None
|
|
76
|
+
|
|
77
|
+
for target_model in models_to_try:
|
|
78
|
+
payload["model"] = target_model
|
|
79
|
+
try:
|
|
80
|
+
if stream_callback:
|
|
81
|
+
payload["stream"] = True
|
|
82
|
+
response = self._session.post(endpoint, json=payload, stream=True, timeout=15)
|
|
83
|
+
if response.status_code == 200:
|
|
84
|
+
full_text = []
|
|
85
|
+
for line in response.iter_lines():
|
|
86
|
+
if line:
|
|
87
|
+
decoded = line.decode("utf-8")
|
|
88
|
+
if decoded.startswith("data: ") and not decoded.startswith("data: [DONE]"):
|
|
89
|
+
raw_json = decoded[6:]
|
|
90
|
+
try:
|
|
91
|
+
chunk = json.loads(raw_json)
|
|
92
|
+
choices = chunk.get("choices", [])
|
|
93
|
+
if choices:
|
|
94
|
+
delta = choices[0].get("delta", {})
|
|
95
|
+
t = delta.get("content", "")
|
|
96
|
+
if t:
|
|
97
|
+
full_text.append(t)
|
|
98
|
+
stream_callback(t)
|
|
99
|
+
except Exception:
|
|
100
|
+
pass
|
|
101
|
+
return "".join(full_text)
|
|
102
|
+
elif response.status_code in (404, 400, 503, 429):
|
|
103
|
+
last_error = f"Model {target_model} status {response.status_code}"
|
|
104
|
+
continue
|
|
105
|
+
else:
|
|
106
|
+
raise RuntimeError(f"DeepSeek API error ({response.status_code}): {response.text}")
|
|
107
|
+
else:
|
|
108
|
+
payload["stream"] = False
|
|
109
|
+
response = self._session.post(endpoint, json=payload, timeout=20)
|
|
110
|
+
if response.status_code == 200:
|
|
111
|
+
data = response.json()
|
|
112
|
+
choices = data.get("choices", [])
|
|
113
|
+
if choices:
|
|
114
|
+
return choices[0].get("message", {}).get("content", "")
|
|
115
|
+
return ""
|
|
116
|
+
elif response.status_code in (404, 400, 503, 429):
|
|
117
|
+
last_error = f"Model {target_model} status {response.status_code}"
|
|
118
|
+
continue
|
|
119
|
+
else:
|
|
120
|
+
raise RuntimeError(f"DeepSeek API error ({response.status_code}): {response.text}")
|
|
121
|
+
except requests.exceptions.Timeout:
|
|
122
|
+
last_error = f"Model {target_model} timed out"
|
|
123
|
+
continue
|
|
124
|
+
except Exception as e:
|
|
125
|
+
last_error = str(e)
|
|
126
|
+
continue
|
|
127
|
+
|
|
128
|
+
raise RuntimeError(f"DeepSeek generation error: {last_error or 'All model attempts failed'}")
|