mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
120 lines
4.5 KiB
Python
120 lines
4.5 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, Field, StrictBool, StrictFloat, StrictInt, StrictStr
|
|
from typing import Any, ClassVar, Dict, List, Optional, Union
|
|
from typing_extensions import Annotated
|
|
from typing import Optional, Set
|
|
from typing_extensions import Self
|
|
|
|
class ModelInfo(BaseModel):
|
|
"""
|
|
Information about a model's capabilities
|
|
""" # noqa: E501
|
|
context_limit: Annotated[int, Field(strict=True, ge=0)] = Field(description="The maximum context length this model supports")
|
|
currency: Optional[StrictStr] = Field(default=None, description="Currency for the costs (default: \"$\")")
|
|
input_token_cost: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Cost per token for input (optional)")
|
|
name: StrictStr = Field(description="The name of the model")
|
|
output_token_cost: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Cost per token for output (optional)")
|
|
supports_cache_control: Optional[StrictBool] = Field(default=None, description="Whether this model supports cache control")
|
|
__properties: ClassVar[List[str]] = ["context_limit", "currency", "input_token_cost", "name", "output_token_cost", "supports_cache_control"]
|
|
|
|
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 ModelInfo 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,
|
|
)
|
|
# set to None if currency (nullable) is None
|
|
# and model_fields_set contains the field
|
|
if self.currency is None and "currency" in self.model_fields_set:
|
|
_dict['currency'] = None
|
|
|
|
# set to None if input_token_cost (nullable) is None
|
|
# and model_fields_set contains the field
|
|
if self.input_token_cost is None and "input_token_cost" in self.model_fields_set:
|
|
_dict['input_token_cost'] = None
|
|
|
|
# set to None if output_token_cost (nullable) is None
|
|
# and model_fields_set contains the field
|
|
if self.output_token_cost is None and "output_token_cost" in self.model_fields_set:
|
|
_dict['output_token_cost'] = None
|
|
|
|
# set to None if supports_cache_control (nullable) is None
|
|
# and model_fields_set contains the field
|
|
if self.supports_cache_control is None and "supports_cache_control" in self.model_fields_set:
|
|
_dict['supports_cache_control'] = None
|
|
|
|
return _dict
|
|
|
|
@classmethod
|
|
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
"""Create an instance of ModelInfo from a dict"""
|
|
if obj is None:
|
|
return None
|
|
|
|
if not isinstance(obj, dict):
|
|
return cls.model_validate(obj)
|
|
|
|
_obj = cls.model_validate({
|
|
"context_limit": obj.get("context_limit"),
|
|
"currency": obj.get("currency"),
|
|
"input_token_cost": obj.get("input_token_cost"),
|
|
"name": obj.get("name"),
|
|
"output_token_cost": obj.get("output_token_cost"),
|
|
"supports_cache_control": obj.get("supports_cache_control")
|
|
})
|
|
return _obj
|
|
|
|
|