Skip to content

Commit c5f0ab7

Browse files
committed
fix: address PR review feedback
- Add missing _get_nim_models() function to config_routes.py - Add NIM_API_KEY and NIM_MODEL to allowed_keys in save_settings() - Add nvidia.png provider icon - Fix indentation in translate.py
1 parent a12e56f commit c5f0ab7

3 files changed

Lines changed: 93 additions & 1 deletion

File tree

src/api/blueprints/config_routes.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,95 @@ def _get_poe_models(provided_api_key=None):
418418
"error": f"Error connecting to Poe API: {str(e)}"
419419
})
420420

421+
def _get_nim_models(provided_api_key=None):
422+
"""Get available models from NVIDIA NIM API"""
423+
from src.config import NIM_API_ENDPOINT
424+
425+
api_key = _resolve_api_key(provided_api_key, 'NIM_API_KEY', NIM_API_KEY)
426+
427+
# Use NIM_MODEL from .env, fallback to meta/llama-3.1-8b-instruct
428+
default_model = NIM_MODEL if NIM_MODEL else "meta/llama-3.1-8b-instruct"
429+
430+
if not api_key:
431+
return jsonify({
432+
"models": [],
433+
"model_names": [],
434+
"default": default_model,
435+
"status": "api_key_missing",
436+
"count": 0,
437+
"error": "NVIDIA NIM API key is required. Get your key at https://build.nvidia.com/"
438+
})
439+
440+
try:
441+
# Determine base URL from endpoint
442+
base_url = NIM_API_ENDPOINT.replace('/chat/completions', '').rstrip('/')
443+
models_url = f"{base_url}/models"
444+
headers = {'Authorization': f'Bearer {api_key}'}
445+
446+
response = requests.get(models_url, headers=headers, timeout=10)
447+
448+
if response.status_code == 200:
449+
data = response.json()
450+
models_data = data.get('data', [])
451+
452+
if models_data:
453+
# Filter and format models
454+
models = []
455+
for m in models_data:
456+
model_id = m.get('id', '')
457+
# Skip embedding models and other non-chat models
458+
if 'embedding' in model_id.lower() or 'whisper' in model_id.lower():
459+
continue
460+
models.append({
461+
'id': model_id,
462+
'name': model_id,
463+
'owned_by': m.get('owned_by', 'nvidia')
464+
})
465+
466+
# Sort models by name
467+
models.sort(key=lambda x: x['name'].lower())
468+
469+
if models:
470+
model_ids = [m['id'] for m in models]
471+
if default_model not in model_ids and model_ids:
472+
default_model = model_ids[0]
473+
return jsonify({
474+
"models": models,
475+
"model_names": model_ids,
476+
"default": default_model,
477+
"status": "nim_connected",
478+
"count": len(models)
479+
})
480+
481+
# If API call failed, return empty with error
482+
return jsonify({
483+
"models": [],
484+
"model_names": [],
485+
"default": default_model,
486+
"status": "nim_error",
487+
"count": 0,
488+
"error": f"Failed to retrieve NVIDIA NIM models (HTTP {response.status_code})"
489+
})
490+
491+
except requests.exceptions.ConnectionError:
492+
return jsonify({
493+
"models": [],
494+
"model_names": [],
495+
"default": default_model,
496+
"status": "nim_error",
497+
"count": 0,
498+
"error": "Could not connect to NVIDIA NIM API. Check your internet connection."
499+
})
500+
except Exception as e:
501+
return jsonify({
502+
"models": [],
503+
"model_names": [],
504+
"default": default_model,
505+
"status": "nim_error",
506+
"count": 0,
507+
"error": f"Error connecting to NVIDIA NIM API: {str(e)}"
508+
})
509+
421510
def _get_openai_models(provided_api_key=None, api_endpoint=None):
422511
"""Get available models from OpenAI-compatible API
423512
@@ -783,6 +872,8 @@ def save_settings():
783872
'DEEPSEEK_MODEL',
784873
'POE_API_KEY',
785874
'POE_MODEL',
875+
'NIM_API_KEY',
876+
'NIM_MODEL',
786877
'DEFAULT_MODEL',
787878
'LLM_PROVIDER',
788879
'API_ENDPOINT',
Lines changed: 1 addition & 0 deletions
Loading

translate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def stats_callback(stats: dict):
164164
mistral_api_key=args.mistral_api_key,
165165
deepseek_api_key=args.deepseek_api_key,
166166
poe_api_key=args.poe_api_key,
167-
nim_api_key=args.nim_api_key,
167+
nim_api_key=args.nim_api_key,
168168
prompt_options=prompt_options
169169
))
170170

0 commit comments

Comments
 (0)