File size: 1,561 Bytes
e98a02a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
from typing import Tuple

from src.modules.gradio_app.utils.api import update_model_list

def create_config_panel() -> Tuple[gr.Textbox, gr.Textbox, gr.Dropdown]:
    """Create configuration panel with endpoint, API key and model selection"""
    with gr.Column():
        endpoint_url = gr.Textbox(
            label="LiteLLM Endpoint URL",
            placeholder="Enter your LiteLLM endpoint URL",
        )
        api_key = gr.Textbox(
            label="API Key",
            placeholder="Enter your API key",
            type="password"
        )
        refresh_models = gr.Button("Refresh Models")
        model_dropdown = gr.Dropdown(
            label="Select Model",
            choices=[],
            interactive=True
        )

        # Update model list when endpoint or API key changes
        def update_models(endpoint_url, api_key):
            models = update_model_list(endpoint_url, api_key)
            return gr.Dropdown(choices=models)
        
        refresh_models.click(
            fn=update_models,
            inputs=[endpoint_url, api_key],
            outputs=model_dropdown
        )
        
        # Update models automatically when endpoint or API key changes
        endpoint_url.change(
            fn=update_models,
            inputs=[endpoint_url, api_key],
            outputs=model_dropdown
        )
        api_key.change(
            fn=update_models,
            inputs=[endpoint_url, api_key],
            outputs=model_dropdown
        )

    return endpoint_url, api_key, model_dropdown