Skip to content

Commit

Permalink
AutoGPT/plugins: Support full parameter defs for plugin commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Oct 8, 2023
1 parent 683257b commit e99e9b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 13 additions & 7 deletions autogpts/autogpt/autogpt/agents/utils/prompt_scratchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def add_command(
self,
name: str,
description: str,
params: dict[str, str],
params: dict[str, str | dict],
function: Callable,
) -> None:
"""
Expand All @@ -50,25 +50,31 @@ def add_command(
function (callable, optional): A callable function to be called when
the 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 = True
logger.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 = True
if invalid:
return

command = CallableCompletionModelFunction(
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,
)
Expand Down
2 changes: 2 additions & 0 deletions autogpts/autogpt/autogpt/core/utils/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def typescript_type(self) -> str:
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"
Expand Down

0 comments on commit e99e9b6

Please sign in to comment.