Skip to content

Commit

Permalink
Added openapi_schema method in BaseTool.py
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Feb 23, 2024
1 parent 67d1dd4 commit 63265c8
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions agency_swarm/tools/BaseTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,65 @@ def openai_schema(cls):

return schema

@classmethod
def openapi_schema(cls, url):
openai_schema = cls.openai_schema
defs = {}
if '$defs' in openai_schema['parameters']:
defs = openai_schema['parameters']['$defs']
del openai_schema['parameters']['$defs']

schema = {
"openapi": "3.1.0",
"info": {
"title": openai_schema['name'],
"description": openai_schema['description'],
"version": "v1.0.0"
},
"servers": [
{
"url": url,
}
],
"paths": {},
"components": {
"schemas": {},
"securitySchemes": {
"apiKey": {
"type": "apiKey"
}
}
},
}

schema['paths']["/" + openai_schema['name']] = {
"post": {
"description": openai_schema['description'],
"operationId": openai_schema['name'],
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": openai_schema['parameters']
}
},
"required": True,
},
"deprecated": False,
"security": [
{
"apiKey": []
}
],
"x-openai-isConsequential": False,
}
}

if defs:
schema['components']['schemas'].update(**defs)

return schema

@abstractmethod
def run(self, **kwargs):
pass

0 comments on commit 63265c8

Please sign in to comment.