AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
AutoGPT/plugins: Support full parameter defs for plugin commands
Reinier van der Leere99e9b6181f0
diff --git a/autogpts/autogpt/autogpt/agents/utils/prompt_scratchpad.py b/autogpts/autogpt/autogpt/agents/utils/prompt_scratchpad.pyindex f42f5eb913..07b324254f 100644--- a/autogpts/autogpt/autogpt/agents/utils/prompt_scratchpad.py+++ b/autogpts/autogpt/autogpt/agents/utils/prompt_scratchpad.py@@ -33,7 +33,7 @@ class PromptScratchpad(BaseModel):self,name: str,description: str,- params: dict[str, str],+ params: dict[str, str | dict],function: Callable,) -> None:"""@@ -50,15 +50,20 @@ class PromptScratchpad(BaseModel):function (callable, optional): A callable function to be called whenthe command is executed. Defaults to None."""- for p, t in params.items():+ for p, s in params.items():invalid = False- if t not in JSONSchema.Type._value2member_map_:+ if type(s) == str and s not in JSONSchema.Type._value2member_map_:invalid = Truelogger.warning(f"Cannot add command '{name}':"- f" parameter '{p}' has invalid type '{t}'."+ f" parameter '{p}' has invalid type '{s}'."f" Valid types are: {JSONSchema.Type._value2member_map_.keys()}")+ elif isinstance(s, dict):+ try:+ JSONSchema.from_dict(s)+ except KeyError:+ invalid = Trueif invalid:return@@ -66,9 +71,10 @@ class PromptScratchpad(BaseModel):name=name,description=description,parameters={- # TODO: require plugins to specify parameters as a JSON schema- name: JSONSchema(type=JSONSchema.Type._value2member_map_[type])- for name, type in params.items()+ name: JSONSchema(type=JSONSchema.Type._value2member_map_[spec])+ if type(spec) == str+ else JSONSchema.from_dict(spec)+ for name, spec in params.items()},method=function,)diff --git a/autogpts/autogpt/autogpt/core/utils/json_schema.py b/autogpts/autogpt/autogpt/core/utils/json_schema.pyindex 9529f91217..743d70d583 100644--- a/autogpts/autogpt/autogpt/core/utils/json_schema.py+++ b/autogpts/autogpt/autogpt/core/utils/json_schema.py@@ -148,6 +148,8 @@ class JSONSchema(BaseModel):if not self.properties:return "Record<string, any>"return self.to_typescript_object_interface()+ elif self.enum:+ return " | ".join(repr(v) for v in self.enum)else:raise NotImplementedError(f"JSONSchema.typescript_type does not support Type.{self.type.name} yet"