Skip to content

Commit

Permalink
Remove EnumParameterSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzocelli committed Mar 1, 2024
1 parent 3354a38 commit 3150df2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
19 changes: 8 additions & 11 deletions tool2schema/parameter_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def _get_default(self) -> Any:
# Parameter.empty to indicate that the default value is not present
return Parameter.empty

def add_enum(self, values: list) -> None:
"""
Convert this parameter to an enumeration type.
:param values: List of unique enumeration values.
"""
self.type_schema = EnumTypeSchema(values)

def to_json(self) -> dict:
"""
Return the json schema for this parameter.
Expand All @@ -95,14 +103,3 @@ def to_json(self) -> dict:
json = {f: v for f, v in fields.items() if v != Parameter.empty}

return json


class EnumParameterSchema(ParameterSchema):
"""
Parameter schema for enumeration types manually added via add_enum.
"""

def __init__(
self, values: list, parameter: Parameter, index: int, config: Config, docstring: str = None
):
super().__init__(EnumTypeSchema(values), parameter, index, config, docstring)
7 changes: 2 additions & 5 deletions tool2schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import tool2schema
from tool2schema.config import Config
from tool2schema.parameter_schema import EnumParameterSchema, ParameterSchema
from tool2schema.parameter_schema import ParameterSchema


class SchemaType(Enum):
Expand Down Expand Up @@ -150,10 +150,7 @@ def add_enum(self, n: str, enum: list) -> "FunctionSchema":
:param n: The name of the parameter with the enum values
:param enum: The list of values for the enum parameter
"""
p = self._all_parameter_schemas[n]
self._all_parameter_schemas[n] = EnumParameterSchema(
enum, p.parameter, p.index, self.config, p.docstring
)
self._all_parameter_schemas[n].add_enum(enum)
return self

def _get_schema(self) -> dict:
Expand Down

0 comments on commit 3150df2

Please sign in to comment.