Get available model providers and their models. This endpoint returns the configuration of available model providers and their respective models that can be used throughout the application. Returns: ModelConfig: A configuration object containing providers and their models
()
| 166 | |
| 167 | @app.get("/models/config", response_model=ModelConfig) |
| 168 | async def get_model_config(): |
| 169 | """ |
| 170 | Get available model providers and their models. |
| 171 | |
| 172 | This endpoint returns the configuration of available model providers and their |
| 173 | respective models that can be used throughout the application. |
| 174 | |
| 175 | Returns: |
| 176 | ModelConfig: A configuration object containing providers and their models |
| 177 | """ |
| 178 | try: |
| 179 | logger.info("Fetching model configurations") |
| 180 | |
| 181 | # Create providers from the config file |
| 182 | providers = [] |
| 183 | default_provider = configs.get("default_provider", "google") |
| 184 | |
| 185 | # Add provider configuration based on config.py |
| 186 | for provider_id, provider_config in configs["providers"].items(): |
| 187 | models = [] |
| 188 | # Add models from config |
| 189 | for model_id in provider_config["models"].keys(): |
| 190 | # Get a more user-friendly display name if possible |
| 191 | models.append(Model(id=model_id, name=model_id)) |
| 192 | |
| 193 | # Add provider with its models |
| 194 | providers.append( |
| 195 | Provider( |
| 196 | id=provider_id, |
| 197 | name=f"{provider_id.capitalize()}", |
| 198 | supportsCustomModel=provider_config.get("supportsCustomModel", False), |
| 199 | models=models |
| 200 | ) |
| 201 | ) |
| 202 | |
| 203 | # Create and return the full configuration |
| 204 | config = ModelConfig( |
| 205 | providers=providers, |
| 206 | defaultProvider=default_provider |
| 207 | ) |
| 208 | return config |
| 209 | |
| 210 | except Exception as e: |
| 211 | logger.error(f"Error creating model configuration: {str(e)}") |
| 212 | # Return some default configuration in case of error |
| 213 | return ModelConfig( |
| 214 | providers=[ |
| 215 | Provider( |
| 216 | id="google", |
| 217 | name="Google", |
| 218 | supportsCustomModel=True, |
| 219 | models=[ |
| 220 | Model(id="gemini-2.5-flash", name="Gemini 2.5 Flash") |
| 221 | ] |
| 222 | ) |
| 223 | ], |
| 224 | defaultProvider="google" |
| 225 | ) |
nothing calls this directly
no test coverage detected