Skip to content

Commit

Permalink
Removed dependency on instructor 🥲
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Aug 15, 2024
1 parent b2f7375 commit 0e65ae1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
48 changes: 43 additions & 5 deletions agency_swarm/tools/BaseTool.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from abc import ABC, abstractmethod
from typing import Optional, Any, ClassVar
from typing import Any, ClassVar

from instructor import OpenAISchema
from docstring_parser import parse

from pydantic import Field
from pydantic import BaseModel
from agency_swarm.util.shared_state import SharedState


class BaseTool(OpenAISchema, ABC):
class BaseTool(BaseModel, ABC):
shared_state: ClassVar[SharedState] = None
caller_agent: Any = None
event_handler: Any = None
Expand All @@ -24,7 +24,45 @@ class ToolConfig:
@classmethod
@property
def openai_schema(cls):
schema = super(BaseTool, cls).openai_schema
"""
Return the schema in the format of OpenAI's schema as jsonschema
Note:
Its important to add a docstring to describe how to best use this class, it will be included in the description attribute and be part of the prompt.
Returns:
model_json_schema (dict): A dictionary in the format of OpenAI's schema as jsonschema
"""
schema = cls.model_json_schema()
docstring = parse(cls.__doc__ or "")
parameters = {
k: v for k, v in schema.items() if k not in ("title", "description")
}
for param in docstring.params:
if (name := param.arg_name) in parameters["properties"] and (
description := param.description
):
if "description" not in parameters["properties"][name]:
parameters["properties"][name]["description"] = description

parameters["required"] = sorted(
k for k, v in parameters["properties"].items() if "default" not in v
)

if "description" not in schema:
if docstring.short_description:
schema["description"] = docstring.short_description
else:
schema["description"] = (
f"Correctly extracted `{cls.__name__}` with all "
f"the required parameters with correct types"
)

schema = {
"name": schema["title"],
"description": schema["description"],
"parameters": parameters,
}

properties = schema.get("parameters", {}).get("properties", {})

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ classifiers = [
"License :: OSI Approved :: MIT License",
]
dependencies = [
"openai==1.40.1",
"instructor==1.3.7",
"openai==1.40.6",
"docstring_parser==0.16",
"pydantic==2.8.2",
"datamodel-code-generator==0.25.8",
"deepdiff==6.7.1",
"termcolor==2.4.0",
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
openai==1.40.1
instructor==1.3.7
openai==1.40.6
docstring_parser==0.16
pydantic==2.8.2
datamodel-code-generator==0.25.8
deepdiff==6.7.1
termcolor==2.4.0
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

setup(
name='agency-swarm',
version='0.2.6',
version='0.2.7',
author='VRSEN',
author_email='arseny9795@gmail.com',
author_email='me@vrsen.ai',
description='An opensource agent orchestration framework built on top of the latest OpenAI Assistants API.',
long_description=open('README.md', encoding='utf-8').read(),
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 0e65ae1

Please sign in to comment.