@@ -86,7 +86,7 @@ def _initialize_model(action: str, model_type: str, model_id: str = None, model_
8686 quoted_model_id = urllib .parse .quote (model_id , safe = "" )
8787 model = api_call .get (endpoint = f"v1/models/{ model_provider } /{ quoted_model_id } " )
8888 else :
89- model = {"id" : "unset " , "type" : model_type , "provider" : "unset" , "status" : "CUSTOM" }
89+ model = {"id" : "" , "type" : model_type , "provider" : "unset" , "status" : "CUSTOM" }
9090
9191 if action == "add" :
9292 model ["enabled" ] = True
@@ -128,6 +128,11 @@ def _render_model_selection(model: dict, provider_models: list, action: str) ->
128128 model_keys = [m ["key" ] for m in provider_models ]
129129 model_index = next ((i for i , key in enumerate (model_keys ) if key == model ["id" ]), None )
130130
131+ # If the current model ID is not in the supported list, add it to the options
132+ if model_index is None and model ["id" ] not in model_keys :
133+ model_keys .append (model ["id" ])
134+ model_index = len (model_keys ) - 1
135+
131136 model ["id" ] = st .selectbox (
132137 "Model (Required):" ,
133138 help = help_text .help_dict ["model_id" ],
@@ -145,8 +150,7 @@ def _render_model_selection(model: dict, provider_models: list, action: str) ->
145150def _render_api_configuration (model : dict , provider_models : list , disable_for_oci : bool ) -> dict :
146151 """Render API configuration UI and return updated model"""
147152 api_base = next (
148- (m .get ("api_base" , "" ) for m in provider_models if m .get ("key" ) == model ["id" ]),
149- model .get ("api_base" , "" )
153+ (m .get ("api_base" , "" ) for m in provider_models if m .get ("key" ) == model ["id" ]), model .get ("api_base" , "" )
150154 )
151155
152156 model ["api_base" ] = st .text_input (
@@ -218,6 +222,8 @@ def _handle_form_submission(model: dict, action: str) -> bool:
218222
219223 try :
220224 if action == "add" and action_button .button (label = "Add" , type = "primary" , width = "stretch" ):
225+ if not all ([model ["id" ], model ["provider" ]]):
226+ raise ValueError
221227 create_model (model = model )
222228 return True
223229 if action == "edit" and action_button .button (label = "Save" , type = "primary" , width = "stretch" ):
@@ -228,6 +234,11 @@ def _handle_form_submission(model: dict, action: str) -> bool:
228234 return True
229235 except api_call .ApiError as ex :
230236 st .error (f"Failed to { action } model: { ex } " )
237+ except ValueError :
238+ if not model ["id" ]:
239+ st .error ("Model name is required." )
240+ if not model ["provider" ]:
241+ st .error ("Provider name is required." )
231242
232243 if cancel_button .button (label = "Cancel" , type = "secondary" ):
233244 st_common .clear_state_key ("model_configs" )
0 commit comments