Files
2025-10-02 20:13:20 -04:00

210 lines
10 KiB
Python

# coding: utf-8
"""
goose-server
An AI agent
The version of the OpenAPI document: 1.9.0
Contact: ai-oss-tools@block.xyz
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from goose_api.models.author import Author
from goose_api.models.extension_config import ExtensionConfig
from goose_api.models.recipe_parameter import RecipeParameter
from goose_api.models.response import Response
from goose_api.models.retry_config import RetryConfig
from goose_api.models.settings import Settings
from goose_api.models.sub_recipe import SubRecipe
from typing import Optional, Set
from typing_extensions import Self
class Recipe(BaseModel):
"""
A Recipe represents a personalized, user-generated agent configuration that defines specific behaviors and capabilities within the goose system. # Fields ## Required Fields * `version` - Semantic version of the Recipe file format (defaults to \"1.0.0\") * `title` - Short, descriptive name of the Recipe * `description` - Detailed description explaining the Recipe's purpose and functionality * `Instructions` - Instructions that defines the Recipe's behavior ## Optional Fields * `prompt` - the initial prompt to the session to start with * `extensions` - List of extension configurations required by the Recipe * `context` - Supplementary context information for the Recipe * `activities` - Activity labels that appear when loading the Recipe * `author` - Information about the Recipe's creator and metadata * `parameters` - Additional parameters for the Recipe * `response` - Response configuration including JSON schema validation * `retry` - Retry configuration for automated validation and recovery # Example use goose::recipe::Recipe; // Using the builder pattern let recipe = Recipe::builder() .title(\"Example Agent\") .description(\"An example Recipe configuration\") .instructions(\"Act as a helpful assistant\") .build() .expect(\"Missing required fields\"); // Or using struct initialization let recipe = Recipe { version: \"1.0.0\".to_string(), title: \"Example Agent\".to_string(), description: \"An example Recipe configuration\".to_string(), instructions: Some(\"Act as a helpful assistant\".to_string()), prompt: None, extensions: None, context: None, activities: None, author: None, settings: None, parameters: None, response: None, sub_recipes: None, retry: None, };
""" # noqa: E501
activities: Optional[List[StrictStr]] = None
author: Optional[Author] = None
context: Optional[List[StrictStr]] = None
description: StrictStr
extensions: Optional[List[ExtensionConfig]] = None
instructions: Optional[StrictStr] = None
parameters: Optional[List[RecipeParameter]] = None
prompt: Optional[StrictStr] = None
response: Optional[Response] = None
retry: Optional[RetryConfig] = None
settings: Optional[Settings] = None
sub_recipes: Optional[List[SubRecipe]] = None
title: StrictStr
version: Optional[StrictStr] = None
__properties: ClassVar[List[str]] = ["activities", "author", "context", "description", "extensions", "instructions", "parameters", "prompt", "response", "retry", "settings", "sub_recipes", "title", "version"]
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of Recipe from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of author
if self.author:
_dict['author'] = self.author.to_dict()
# override the default output from pydantic by calling `to_dict()` of each item in extensions (list)
_items = []
if self.extensions:
for _item_extensions in self.extensions:
if _item_extensions:
_items.append(_item_extensions.to_dict())
_dict['extensions'] = _items
# override the default output from pydantic by calling `to_dict()` of each item in parameters (list)
_items = []
if self.parameters:
for _item_parameters in self.parameters:
if _item_parameters:
_items.append(_item_parameters.to_dict())
_dict['parameters'] = _items
# override the default output from pydantic by calling `to_dict()` of response
if self.response:
_dict['response'] = self.response.to_dict()
# override the default output from pydantic by calling `to_dict()` of retry
if self.retry:
_dict['retry'] = self.retry.to_dict()
# override the default output from pydantic by calling `to_dict()` of settings
if self.settings:
_dict['settings'] = self.settings.to_dict()
# override the default output from pydantic by calling `to_dict()` of each item in sub_recipes (list)
_items = []
if self.sub_recipes:
for _item_sub_recipes in self.sub_recipes:
if _item_sub_recipes:
_items.append(_item_sub_recipes.to_dict())
_dict['sub_recipes'] = _items
# set to None if activities (nullable) is None
# and model_fields_set contains the field
if self.activities is None and "activities" in self.model_fields_set:
_dict['activities'] = None
# set to None if author (nullable) is None
# and model_fields_set contains the field
if self.author is None and "author" in self.model_fields_set:
_dict['author'] = None
# set to None if context (nullable) is None
# and model_fields_set contains the field
if self.context is None and "context" in self.model_fields_set:
_dict['context'] = None
# set to None if extensions (nullable) is None
# and model_fields_set contains the field
if self.extensions is None and "extensions" in self.model_fields_set:
_dict['extensions'] = None
# set to None if instructions (nullable) is None
# and model_fields_set contains the field
if self.instructions is None and "instructions" in self.model_fields_set:
_dict['instructions'] = None
# set to None if parameters (nullable) is None
# and model_fields_set contains the field
if self.parameters is None and "parameters" in self.model_fields_set:
_dict['parameters'] = None
# set to None if prompt (nullable) is None
# and model_fields_set contains the field
if self.prompt is None and "prompt" in self.model_fields_set:
_dict['prompt'] = None
# set to None if response (nullable) is None
# and model_fields_set contains the field
if self.response is None and "response" in self.model_fields_set:
_dict['response'] = None
# set to None if retry (nullable) is None
# and model_fields_set contains the field
if self.retry is None and "retry" in self.model_fields_set:
_dict['retry'] = None
# set to None if settings (nullable) is None
# and model_fields_set contains the field
if self.settings is None and "settings" in self.model_fields_set:
_dict['settings'] = None
# set to None if sub_recipes (nullable) is None
# and model_fields_set contains the field
if self.sub_recipes is None and "sub_recipes" in self.model_fields_set:
_dict['sub_recipes'] = None
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Recipe from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"activities": obj.get("activities"),
"author": Author.from_dict(obj["author"]) if obj.get("author") is not None else None,
"context": obj.get("context"),
"description": obj.get("description"),
"extensions": [ExtensionConfig.from_dict(_item) for _item in obj["extensions"]] if obj.get("extensions") is not None else None,
"instructions": obj.get("instructions"),
"parameters": [RecipeParameter.from_dict(_item) for _item in obj["parameters"]] if obj.get("parameters") is not None else None,
"prompt": obj.get("prompt"),
"response": Response.from_dict(obj["response"]) if obj.get("response") is not None else None,
"retry": RetryConfig.from_dict(obj["retry"]) if obj.get("retry") is not None else None,
"settings": Settings.from_dict(obj["settings"]) if obj.get("settings") is not None else None,
"sub_recipes": [SubRecipe.from_dict(_item) for _item in obj["sub_recipes"]] if obj.get("sub_recipes") is not None else None,
"title": obj.get("title"),
"version": obj.get("version")
})
return _obj