def get_customizable_model_schema( self, model: str, credentials: dict ) -> AIModelEntity: schema = {item.model: item for item in self.predefined_models()}.get( _base_model(model) ) if schema is None: # Fallback for custom / non-OpenAI base models served via an # OpenAI-compatible endpoint (e.g. Qwen, DeepSeek, local vLLM): # clone a chat-capable predefined schema so the model is listable # and can be set as the default model. template = next( (m for m in self.predefined_models() if m.model_properties.get("mode") == "chat"), None, ) if template is None: template = self.predefined_models()[0] props = dict(template.model_properties) mp = (credentials or {}).get("model_properties") or {} try: if "context_size" in mp: props["context_size"] = int(mp["context_size"]) if "max_tokens" in mp: props["max_tokens"] = int(mp["max_tokens"]) except (ValueError, TypeError): pass schema = template.model_copy(deep=True, update={"model_properties": props}) return schema.model_copy( deep=True, update={ "model": model, "label": I18nObject(zh_hans=model, en_us=model), "fetch_from": FetchFrom.CUSTOMIZABLE_MODEL, }, )