Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

Add dynamic model fetching for Anthropic using the Anthropic package

LearningCircuite42441670047
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index d083e07d69..23b7f2c458 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -908,19 +908,67 @@ def api_get_available_models():
{"value": "gpt-3.5-turbo", "label": "GPT-3.5 Turbo (OpenAI)"},
]
- # Add Anthropic models
- providers["anthropic_models"] = [
- {
- "value": "claude-3-5-sonnet-latest",
- "label": "Claude 3.5 Sonnet (Anthropic)",
- },
- {"value": "claude-3-opus-20240229", "label": "Claude 3 Opus (Anthropic)"},
- {
- "value": "claude-3-sonnet-20240229",
- "label": "Claude 3 Sonnet (Anthropic)",
- },
- {"value": "claude-3-haiku-20240307", "label": "Claude 3 Haiku (Anthropic)"},
- ]
+ # Try to get Anthropic models using the Anthropic package
+ anthropic_models = []
+ try:
+ logger.info(
+ "Attempting to connect to Anthropic API using Anthropic package"
+ )
+
+ # Get the API key from settings
+ api_key = get_db_setting("llm.anthropic.api_key", "")
+
+ if api_key:
+ # Import Anthropic package here to avoid dependency issues if not installed
+ from anthropic import Anthropic
+
+ # Create Anthropic client
+ client = Anthropic(api_key=api_key)
+
+ try:
+ # Fetch models using the client
+ logger.debug("Fetching models from Anthropic API")
+ models_response = client.models.list()
+
+ # Process models from the response
+ for model in models_response.data:
+ model_id = model.id
+ if model_id:
+ # Create a clean display name
+ display_name = model_id.replace("-", " ").strip()
+ display_name = " ".join(
+ word.capitalize() for word in display_name.split()
+ )
+
+ anthropic_models.append(
+ {
+ "value": model_id,
+ "label": f"{display_name} (Anthropic)",
+ "provider": "ANTHROPIC",
+ }
+ )
+ logger.debug(
+ f"Added Anthropic model: {model_id} -> {display_name}"
+ )
+
+ # Sort models alphabetically
+ anthropic_models.sort(key=lambda x: x["label"])
+
+ except Exception as api_err:
+ logger.error(f"Anthropic API error: {str(api_err)}")
+ else:
+ logger.info("Anthropic API key not configured")
+
+ except ImportError:
+ logger.warning(
+ "Anthropic package not installed. No models will be available."
+ )
+ except Exception as e:
+ logger.error(f"Error getting Anthropic models: {str(e)}")
+
+ # Set anthropic_models in providers (could be empty if API call failed)
+ providers["anthropic_models"] = anthropic_models
+ logger.info(f"Final Anthropic models count: {len(anthropic_models)}")
# Return all options
return jsonify({"provider_options": provider_options, "providers": providers})