Skip to content

Commit

Permalink
Added extra parameters in tool factory
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Jan 11, 2024
1 parent 3d0d793 commit 640345e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions agency_swarm/tools/ToolFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def create_fields(schema: Dict[str, Any], type_mapping: Dict[str, Type[Any]], re
return tool

@staticmethod
def from_openapi_schema(schema: str, headers: Dict[str, str] = None):
def from_openapi_schema(schema: str, headers: Dict[str, str] = None, params: Dict[str, Any] = None):
openapi_spec = jsonref.loads(schema)
tools = []
headers = headers or {}
Expand All @@ -174,10 +174,12 @@ def callback(self):
parameters = self.model_dump().get('parameters', {})
# replace all parameters in url
for param, value in parameters.items():
url = url.replace(f"{{{param}}}", str(value))
parameters[param] = None
if "{" + str(param) + "}" in url:
url = url.replace(f"{{{param}}}", str(value))
parameters[param] = None
url = url.rstrip("/")
parameters = {k: v for k, v in parameters.items() if v is not None}
parameters = {**parameters, **params} if params else parameters
if method == "get":
return requests.get(url, params=parameters, headers=headers,
json=self.model_dump().get('requestBody', None)
Expand Down Expand Up @@ -221,10 +223,10 @@ def callback(self):
if req_body:
schema["properties"]["requestBody"] = req_body

params = spec.get("parameters", [])
if params:
spec_params = spec.get("parameters", [])
if spec_params:
param_properties = {}
for param in params:
for param in spec_params:
param_properties[param["name"]] = param["schema"]
if "description" in param:
param_properties[param["name"]]["description"] = param["description"]
Expand Down

0 comments on commit 640345e

Please sign in to comment.