cstr commited on
Commit
c61fd1d
·
verified ·
1 Parent(s): 209b15f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -6
app.py CHANGED
@@ -428,18 +428,52 @@ Leave **Provider** at `(none)` to skip the LLM pass entirely (fast, structural-o
428
  value="(none)",
429
  info="Select an LLM provider. API key must be available.",
430
  )
431
- llm_model = gr.Textbox(
432
- label="Model (leave blank for provider default)",
433
- placeholder="auto",
434
- info="e.g. gpt-4o, claude-opus-4-5, mistral-large-latest, …",
 
 
435
  )
 
436
  llm_api_key = gr.Textbox(
437
- label="API key (leave blank to use env var)",
438
  type="password",
439
  placeholder="sk-…",
440
- info="Falls back to the provider's env variable if empty.",
441
  )
442
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  with gr.Row():
444
  llm_mode = gr.Radio(
445
  label="LLM mode",
 
428
  value="(none)",
429
  info="Select an LLM provider. API key must be available.",
430
  )
431
+ llm_model = gr.Dropdown(
432
+ label="Model",
433
+ choices=["auto"],
434
+ value="auto",
435
+ allow_custom_value=True,
436
+ info="Select a model or type a custom one. Use 'Fetch Models' to update list.",
437
  )
438
+ fetch_models_btn = gr.Button("🔄 Fetch Models", size="sm")
439
  llm_api_key = gr.Textbox(
440
+ label="API key (optional)",
441
  type="password",
442
  placeholder="sk-…",
443
+ info="Overrides env variable if provided.",
444
  )
445
 
446
+ # --- Logic to fetch models ---
447
+ def _fetch_models(provider, api_key):
448
+ if provider == "(none)":
449
+ return gr.update(choices=["auto"], value="auto")
450
+
451
+ try:
452
+ # Temporary config to use for fetching
453
+ cfg = llm_config_from_args(provider, api_key=api_key)
454
+ client = MultiProviderLLMClient()
455
+ models = client.get_available_models(cfg)
456
+
457
+ if not models:
458
+ return gr.update(choices=["auto"], value="auto")
459
+
460
+ choices = [m["id"] for m in models]
461
+ # Also include the default model from PROVIDER_DEFAULTS if not in list
462
+ default_m = PROVIDER_DEFAULTS.get(provider, {}).get("model")
463
+ if default_m and default_m not in choices:
464
+ choices.insert(0, default_m)
465
+
466
+ return gr.update(choices=choices, value=choices[0])
467
+ except Exception as e:
468
+ logger.error(f"Fetch models failed: {e}")
469
+ return gr.update(choices=["auto", f"Error: {str(e)[:20]}..."], value="auto")
470
+
471
+ fetch_models_btn.click(
472
+ fn=_fetch_models,
473
+ inputs=[llm_provider, llm_api_key],
474
+ outputs=[llm_model]
475
+ )
476
+
477
  with gr.Row():
478
  llm_mode = gr.Radio(
479
  label="LLM mode",