@@ -182,7 +182,7 @@ def get_llm_model(provider: str, **kwargs):
182
182
183
183
184
184
# Callback to update the model name dropdown based on the selected provider
185
- def update_model_dropdown (llm_provider , api_key = None , base_url = None ):
185
+ def update_model_dropdown (llm_provider , current_model_value , api_key = None , base_url = None ):
186
186
"""
187
187
Update the model name dropdown with predefined models for the selected provider.
188
188
"""
@@ -194,10 +194,13 @@ def update_model_dropdown(llm_provider, api_key=None, base_url=None):
194
194
base_url = os .getenv (f"{ llm_provider .upper ()} _BASE_URL" , "" )
195
195
196
196
# Use predefined models for the selected provider
197
- if llm_provider in model_names :
198
- return gr .Dropdown (choices = model_names [llm_provider ], value = model_names [llm_provider ][0 ], interactive = True )
199
- else :
200
- return gr .Dropdown (choices = [], value = "" , interactive = True , allow_custom_value = True )
197
+ choices = model_names [llm_provider ]
198
+ new_value = current_model_value
199
+
200
+ if not choices or current_model_value not in choices :
201
+ new_value = choices [0 ]
202
+
203
+ return gr .update (choices = choices , value = new_value )
201
204
202
205
203
206
class MissingAPIKeyError (Exception ):
@@ -289,13 +292,11 @@ def register_component(self, name: str, component):
289
292
self .component_order .append (name )
290
293
return component
291
294
292
- def save_current_config (self ):
293
- """Save the current configuration of all registered components ."""
295
+ def save_current_config (self , * component_values ):
296
+ """Save the current configuration passed directly from Gradio's inputs ."""
294
297
current_config = {}
295
- for name in self .component_order :
296
- component = self .components [name ]
297
- # Get the current value from the component
298
- current_config [name ] = getattr (component , "value" , None )
298
+ for i , name in enumerate (self .component_order ):
299
+ current_config [name ] = component_values [i ]
299
300
300
301
return save_config_to_file (current_config )
301
302
0 commit comments