|
18 | 18 | PositiveInt, |
19 | 19 | SecretStr, |
20 | 20 | ) |
| 21 | + |
| 22 | +from pydantic.dataclasses import dataclass |
21 | 23 | from typing_extensions import Self, Literal |
22 | 24 |
|
23 | 25 | import constants |
@@ -413,17 +415,44 @@ def jwk_configuration(self) -> JwkConfiguration: |
413 | 415 | return self.jwk_config |
414 | 416 |
|
415 | 417 |
|
| 418 | +@dataclass |
| 419 | +class CustomProfile: |
| 420 | + """Custom profile customization for prompts and validation.""" |
| 421 | + |
| 422 | + path: str |
| 423 | + prompts: dict[str, str] = Field(default={}, init=False) |
| 424 | + |
| 425 | + def __post_init__(self) -> None: |
| 426 | + """Validate and load profile.""" |
| 427 | + self._validate_and_process() |
| 428 | + |
| 429 | + def _validate_and_process(self) -> None: |
| 430 | + """Validate and load the profile.""" |
| 431 | + checks.file_check(Path(self.path), "custom profile") |
| 432 | + profile_module = checks.import_python_module("profile", self.path) |
| 433 | + if profile_module is not None and checks.is_valid_profile(profile_module): |
| 434 | + self.prompts = profile_module.PROFILE_CONFIG.get("system_prompts", {}) |
| 435 | + |
| 436 | + def get_prompts(self) -> dict[str, str]: |
| 437 | + """Retrieve prompt attribute.""" |
| 438 | + return self.prompts |
| 439 | + |
| 440 | + |
416 | 441 | class Customization(ConfigurationBase): |
417 | 442 | """Service customization.""" |
418 | 443 |
|
| 444 | + profile_path: Optional[str] = None |
419 | 445 | disable_query_system_prompt: bool = False |
420 | 446 | system_prompt_path: Optional[FilePath] = None |
421 | 447 | system_prompt: Optional[str] = None |
| 448 | + custom_profile: Optional[CustomProfile] = Field(default=None, init=False) |
422 | 449 |
|
423 | 450 | @model_validator(mode="after") |
424 | 451 | def check_customization_model(self) -> Self: |
425 | | - """Load system prompt from file.""" |
426 | | - if self.system_prompt_path is not None: |
| 452 | + """Load customizations.""" |
| 453 | + if self.profile_path: |
| 454 | + self.custom_profile = CustomProfile(path=self.profile_path) |
| 455 | + elif self.system_prompt_path is not None: |
427 | 456 | checks.file_check(self.system_prompt_path, "system prompt") |
428 | 457 | self.system_prompt = checks.get_attribute_from_file( |
429 | 458 | dict(self), "system_prompt_path" |
|
0 commit comments