Post-initialization to set up model configurations and handle backward compatibility.
(self)
| 149 | reasoning_effort: Optional[str] = None |
| 150 | |
| 151 | def __post_init__(self): |
| 152 | """Post-initialization to set up model configurations and handle backward compatibility.""" |
| 153 | super().__post_init__() # Resolve ${VAR} in api_key at the LLMConfig level |
| 154 | |
| 155 | # Handle backward compatibility for primary_model/secondary_model settings |
| 156 | if self.primary_model: |
| 157 | primary_model = LLMModelConfig( |
| 158 | name=self.primary_model, weight=self.primary_model_weight or 1.0 |
| 159 | ) |
| 160 | self.models.append(primary_model) |
| 161 | |
| 162 | if self.secondary_model: |
| 163 | # Create secondary model only if weight is specified and > 0, or if not specified (defaults to 0.2) |
| 164 | if self.secondary_model_weight is None or self.secondary_model_weight > 0: |
| 165 | secondary_model = LLMModelConfig( |
| 166 | name=self.secondary_model, |
| 167 | weight=( |
| 168 | self.secondary_model_weight |
| 169 | if self.secondary_model_weight is not None |
| 170 | else 0.2 |
| 171 | ), |
| 172 | ) |
| 173 | self.models.append(secondary_model) |
| 174 | |
| 175 | # Validate that at least one model is configured if any model-related settings are present |
| 176 | if ( |
| 177 | self.primary_model |
| 178 | or self.secondary_model |
| 179 | or self.primary_model_weight |
| 180 | or self.secondary_model_weight |
| 181 | ) and not self.models: |
| 182 | raise ValueError( |
| 183 | "No LLM models configured. Please specify 'models' array or " |
| 184 | "'primary_model' in your configuration." |
| 185 | ) |
| 186 | |
| 187 | # If no evaluator models are defined, use the same models as for evolution |
| 188 | if not self.evaluator_models: |
| 189 | self.evaluator_models = self.models.copy() |
| 190 | |
| 191 | # Update all individual models with shared configuration values (api_base, etc.) |
| 192 | shared_config = { |
| 193 | "api_base": self.api_base, |
| 194 | "api_key": self.api_key, |
| 195 | "temperature": self.temperature, |
| 196 | "top_p": self.top_p, |
| 197 | "max_tokens": self.max_tokens, |
| 198 | "timeout": self.timeout, |
| 199 | "retries": self.retries, |
| 200 | "retry_delay": self.retry_delay, |
| 201 | "random_seed": self.random_seed, |
| 202 | "reasoning_effort": self.reasoning_effort, |
| 203 | } |
| 204 | self.update_model_params(shared_config) |
| 205 | |
| 206 | def update_model_params(self, args: Dict[str, Any], overwrite: bool = False) -> None: |
| 207 | """Update parameters for all models in both evolution and evaluator ensembles.""" |
nothing calls this directly
no test coverage detected