Skip to content

Class swarmauri_standard.utils.method_signature_extractor_decorator.MethodSignatureExtractor

swarmauri_standard.utils.method_signature_extractor_decorator.MethodSignatureExtractor

MethodSignatureExtractor(**kwargs)

Bases: BaseModel

Source code in swarmauri_standard/utils/method_signature_extractor_decorator.py
30
31
32
def __init__(self, **kwargs):
    super().__init__(**kwargs)
    self.parameters = self.extract_signature_details()

method instance-attribute

method

parameters class-attribute instance-attribute

parameters = extract_signature_details()

extract_signature_details

extract_signature_details()
Source code in swarmauri_standard/utils/method_signature_extractor_decorator.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def extract_signature_details(self):
    sig = inspect.signature(self.method)
    type_hints = get_type_hints(self.method)
    parameters = sig.parameters
    details_list = []
    for param_name, param in parameters.items():
        if param_name == "self":
            continue

        param_type = type_hints.get(param_name, Any)
        (param.default if param.default is not inspect.Parameter.empty else None)
        required = param.default is inspect.Parameter.empty
        enum = None
        param_type_json_schema = self._python_type_to_json_schema_type(param_type)
        print(param_type_json_schema)

        if "oneOf" in param_type_json_schema:
            param_type_json_schema["type"] = [
                type_["type"] for type_ in param_type_json_schema["oneOf"]
            ]

        description = f"Parameter {param_name} of type {param_type_json_schema}"

        detail = Parameter(
            name=param_name,
            input_type=param_type_json_schema["type"],
            description=description,
            required=required,
            enum=enum,
        )
        details_list.append(detail)

    return details_list