feat: support pydantic models in tool uploads + patch dict/list types (#2112)

This commit is contained in:
Charles Packer
2024-11-30 10:09:03 -08:00
committed by GitHub
parent 58ec6238a8
commit 6be2000eda
26 changed files with 1173 additions and 53 deletions

View File

@@ -276,6 +276,25 @@ class ToolExecutionSandbox:
return code
def _convert_param_to_value(self, param_type: str, raw_value: str) -> str:
if param_type == "string":
value = '"' + raw_value + '"'
elif param_type == "integer" or param_type == "boolean" or param_type == "number":
value = raw_value
elif param_type == "array":
value = raw_value
elif param_type == "object":
value = raw_value
else:
raise TypeError(f"Unsupported type: {param_type}, raw_value={raw_value}")
return str(value)
def initialize_param(self, name: str, raw_value: str) -> str:
params = self.tool.json_schema["parameters"]["properties"]
spec = params.get(name)
@@ -287,14 +306,9 @@ class ToolExecutionSandbox:
if param_type is None and spec.get("parameters"):
param_type = spec["parameters"].get("type")
if param_type == "string":
value = '"' + raw_value + '"'
elif param_type == "integer" or param_type == "boolean":
value = raw_value
else:
raise TypeError(f"unsupported type: {param_type}")
value = self._convert_param_to_value(param_type, raw_value)
return name + " = " + str(value) + "\n"
return name + " = " + value + "\n"
def invoke_function_call(self, inject_agent_state: bool) -> str:
"""