Spaces:
Running
Running
File size: 1,451 Bytes
1cb4327 a9fb876 1cb4327 6646f61 0b1aa61 14653c6 1cb4327 14653c6 de37bdf 14653c6 6646f61 14653c6 1cb4327 a9fb876 1cb4327 0b1aa61 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
from typing import Annotated
from any_agent import AgentFramework
from any_agent.schema import AgentSchema
from pydantic import AfterValidator, BaseModel, ConfigDict, FutureDatetime, PositiveInt
import yaml
INPUT_PROMPT_TEMPLATE = """
According to the forecast, what will be the best spot to surf around {LOCATION},
in a {MAX_DRIVING_HOURS} hour driving radius,
at {DATE}?"
""".strip()
def validate_prompt(value) -> str:
for placeholder in ("{LOCATION}", "{MAX_DRIVING_HOURS}", "{DATE}"):
if placeholder not in value:
raise ValueError(f"prompt must contain {placeholder}")
return value
class Config(BaseModel):
model_config = ConfigDict(extra="forbid")
location: str
max_driving_hours: PositiveInt
date: FutureDatetime
input_prompt_template: Annotated[str, AfterValidator(validate_prompt)] = (
INPUT_PROMPT_TEMPLATE
)
framework: AgentFramework
main_agent: AgentSchema
managed_agents: list[AgentSchema] | None = None
@classmethod
def from_yaml(cls, yaml_path: str) -> "Config":
"""
with open(yaml_path, "r") as f:
data = yaml.safe_load(f)
return cls(**data) yaml_path: Path to the YAML configuration file
Returns:
Config: A new Config instance populated with values from the YAML file
"""
with open(yaml_path, "r") as f:
data = yaml.safe_load(f)
return cls(**data)
|