~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
feat(web): add support for custom OpenAI endpoint models
JayLiubcba59a3e2be
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.pyindex f697b67b24..fbf4460fd2 100644--- a/src/local_deep_research/web/routes/settings_routes.py+++ b/src/local_deep_research/web/routes/settings_routes.py@@ -803,6 +803,87 @@ def api_get_available_models():},]+ # Try to get Custom OpenAI Endpoint models+ openai_endpoint_models = []+ try:+ current_app.logger.info("Attempting to connect to Custom OpenAI Endpoint")++ # Get the endpoint URL and API key from settings+ endpoint_url = get_db_setting("llm.openai_endpoint.url", "")+ api_key = get_db_setting("llm.openai_endpoint.api_key", "")++ if endpoint_url and api_key:+ # Ensure the URL ends with a slash+ if not endpoint_url.endswith('/'):+ endpoint_url += '/'++ # Make the request to the endpoint's models API+ headers = {"Authorization": f"Bearer {api_key}"}+ endpoint_response = requests.get(f"{endpoint_url}models", headers=headers, timeout=5)++ current_app.logger.debug(+ f"OpenAI Endpoint API response: Status {endpoint_response.status_code}"+ )++ if endpoint_response.status_code == 200:+ try:+ endpoint_data = endpoint_response.json()+ current_app.logger.debug(+ f"OpenAI Endpoint API data: {json.dumps(endpoint_data)[:500]}..."+ )++ # Process models from the response+ if "data" in endpoint_data:+ for model in endpoint_data.get("data", []):+ model_id = model.get("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()+ )++ openai_endpoint_models.append({+ "value": model_id,+ "label": f"{display_name} (Custom)",+ "provider": "OPENAI_ENDPOINT",+ })+ current_app.logger.debug(+ f"Added Custom OpenAI Endpoint model: {model_id} -> {display_name}"+ )++ # Sort models alphabetically+ openai_endpoint_models.sort(key=lambda x: x["label"])+ else:+ current_app.logger.warning("No 'data' field in OpenAI Endpoint API response")+ raise Exception("Invalid API response format from OpenAI Endpoint")++ except json.JSONDecodeError as json_err:+ current_app.logger.error(+ f"Failed to parse OpenAI Endpoint API response as JSON: {json_err}"+ )+ raise Exception(f"OpenAI Endpoint API returned invalid JSON: {json_err}")+ else:+ current_app.logger.warning(+ f"OpenAI Endpoint API returned non-200 status code: {endpoint_response.status_code}"+ )+ raise Exception(+ f"OpenAI Endpoint API returned status code {endpoint_response.status_code}"+ )+ else:+ current_app.logger.info("OpenAI Endpoint URL or API key not configured")+ # Don't raise an exception, just continue with empty models list++ except Exception as e:+ current_app.logger.error(f"Error getting OpenAI Endpoint models: {str(e)}")+ # Use fallback models (empty in this case)+ current_app.logger.info("Using fallback (empty) OpenAI Endpoint models due to error")++ # Always set the openai_endpoint_models in providers+ providers["openai_endpoint_models"] = openai_endpoint_models+ current_app.logger.info(f"Final OpenAI Endpoint models count: {len(openai_endpoint_models)}")+# Add OpenAI modelsproviders["openai_models"] = [{"value": "gpt-4o", "label": "GPT-4o (OpenAI)"},diff --git a/src/local_deep_research/web/static/js/components/research.js b/src/local_deep_research/web/static/js/components/research.jsindex e3051ff567..1971bc1888 100644--- a/src/local_deep_research/web/static/js/components/research.js+++ b/src/local_deep_research/web/static/js/components/research.js@@ -718,18 +718,54 @@usingFallbackModels = true;}} else if (providerUpper === 'OPENAI_ENDPOINT') {- // For custom endpoints, show a mix of models as examples+ // 优先过滤具有OPENAI_ENDPOINT提供商标记的模型models = allModels.filter(model => {if (!model || typeof model !== 'object') return false;// Skip provider optionsif (model.value && !model.id && !model.name) return false;- // Include OpenAI and Anthropic models as examples+ // 精确匹配OPENAI_ENDPOINT提供商const modelProvider = (model.provider || '').toUpperCase();- return modelProvider === 'OPENAI' || modelProvider === 'ANTHROPIC';+ return modelProvider === 'OPENAI_ENDPOINT';});+ console.log(`Found ${models.length} models with provider="OPENAI_ENDPOINT"`);++ // 如果没有找到足够的模型,使用从后端API获取的所有模型+ if (models.length === 0) {+ console.log('No OPENAI_ENDPOINT models found, checking for models with "Custom" in label');+ models = allModels.filter(model => {+ if (!model || typeof model !== 'object') return false;++ // Skip provider options+ if (model.value && !model.id && !model.name) return false;++ // 查找标签中包含"Custom"字样的模型+ const modelLabel = (model.label || '').toLowerCase();+ return modelLabel.includes('custom');+ });++ console.log(`Found ${models.length} models with "Custom" in label`);+ }++ // 如果仍然没有找到模型,才使用标准模型作为示例+ if (models.length === 0) {+ console.log('No OPENAI_ENDPOINT or Custom models found, using OpenAI models as examples');+ models = allModels.filter(model => {+ if (!model || typeof model !== 'object') return false;++ // Skip provider options+ if (model.value && !model.id && !model.name) return false;++ // 包含OpenAI模型作为示例+ const modelProvider = (model.provider || '').toUpperCase();+ const modelId = (model.id || model.value || '').toLowerCase();+ return modelProvider === 'OPENAI' ||+ modelId.includes('gpt');+ });+ }+// Add fallbacks if necessaryif (models.length === 0) {console.log('No models found for custom endpoint, using fallbacks');@@ -1411,6 +1447,17 @@});}+ // Process Custom OpenAI Endpoint models+ if (data.providers && data.providers.openai_endpoint_models) {+ data.providers.openai_endpoint_models.forEach(model => {+ formatted.push({+ ...model,+ id: model.value,+ provider: 'OPENAI_ENDPOINT'+ });+ });+ }+return formatted;}diff --git a/src/local_deep_research/web/static/js/components/settings.js b/src/local_deep_research/web/static/js/components/settings.jsindex 24d9a4a977..11f99d841d 100644--- a/src/local_deep_research/web/static/js/components/settings.js+++ b/src/local_deep_research/web/static/js/components/settings.js@@ -2761,6 +2761,21 @@});}+ // Add Custom OpenAI Endpoint models if available+ if (data.providers && data.providers.openai_endpoint_models && data.providers.openai_endpoint_models.length > 0) {+ const openai_endpoint_models = data.providers.openai_endpoint_models;+ console.log('Found OpenAI Endpoint models:', openai_endpoint_models.length);++ // Add provider information to each model+ openai_endpoint_models.forEach(model => {+ formattedModels.push({+ value: model.value,+ label: model.label,+ provider: 'OPENAI_ENDPOINT' // Ensure provider field is added+ });+ });+ }+// Update the global modelOptions arraymodelOptions = formattedModels;console.log('Final modelOptions:', modelOptions.length, 'models');@@ -3673,6 +3688,21 @@return false;}++ // 为OPENAI_ENDPOINT添加特殊处理+ if (providerUpper === 'OPENAI_ENDPOINT') {+ // 首先检查模型的provider属性+ if (model.provider && model.provider.toUpperCase() === 'OPENAI_ENDPOINT') {+ return true;+ }++ // 检查标签中是否包含"Custom"+ if (model.label && model.label.toLowerCase().includes('custom')) {+ return true;+ }++ return false;+ }// For other providers, use standard matchingif (model.provider) {diff --git a/src/temp_test/test_project.py b/src/temp_test/test_project.pynew file mode 100644index 0000000000..5086fc1784--- /dev/null+++ b/src/temp_test/test_project.py@@ -0,0 +1,5 @@+from local_deep_research.api import quick_summary++summary_results = quick_summary("advances in fusion energy")++print(summary_results["summary"])