Load configuration from a YAML file, or create a default config.
(config_path: Optional[Union[str, Path]] = None)
| 449 | |
| 450 | |
| 451 | def load_config(config_path: Optional[Union[str, Path]] = None) -> Config: |
| 452 | """Load configuration from a YAML file, or create a default config.""" |
| 453 | if config_path and os.path.exists(config_path): |
| 454 | # If a path is provided and the file exists, load from YAML |
| 455 | config = Config.from_yaml(config_path) |
| 456 | else: |
| 457 | # Otherwise, create a default Config object |
| 458 | config = Config() |
| 459 | |
| 460 | # Try to populate API key and base URL from environment variables as a fallback |
| 461 | api_key = os.environ.get("OPENAI_API_KEY") |
| 462 | api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1") |
| 463 | |
| 464 | config.llm.update_model_params({"api_key": api_key, "api_base": api_base}) |
| 465 | |
| 466 | # Ensure the system message from the prompt config is available to individual models, |
| 467 | # in case it's not provided directly by the prompt sampler during a call. |
| 468 | config.llm.update_model_params({"system_message": config.prompt.system_message}) |
| 469 | |
| 470 | return config |
no test coverage detected