Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ToolKit for new interface #340

Merged
merged 37 commits into from
Jun 21, 2024

Conversation

koxudaxi
Copy link

The PR adds ToolKit for a new style interface.

class BookRecommendationTools(Toolkit):
    """A toolkit for recommending books."""

    reading_level: Literal["beginner", "advanced"]

    @toolkit_tool() # not sure about this naming...
    def format_book(self, title: str, author: str) -> str:
        """Returns the title and author of a book nicely formatted.

        Reading level: {self.reading_level}
        """
        return f"{title} by {author}"

@openai_call(model="gpt-4o")
def recommend_book(genre: str, reading_level: Literal["beginner", "advanced"]):
    """Recommend a {genre} book."""
    toolkit = BookRecommendationTools(reading_level=reading_level)
    return {"tools": [toolkit.create_tools()]}

The broad policy was discussed within #278, but any undecideds will be resolved within the PR.
Closes #278

@koxudaxi koxudaxi marked this pull request as draft June 19, 2024 15:38
@koxudaxi
Copy link
Author

@willbakst
I have made a rough implementation based on what we have discussed. I have not implemented create_tool or unittest yet, but first, I want to ensure that my implementation policy is not different from your assumptions.
Also, I have not confirmed my implementation policy for the part of the connection with the new interface (@openai_call), which is not yet completed, so it is currently a TODO.
Of course, type hints and variable names may need improvement, but please confirm the general framework.

mirascope/core/_internal/utils.py Outdated Show resolved Hide resolved
mirascope/core/base/toolkit.py Outdated Show resolved Hide resolved
mirascope/core/_internal/utils.py Outdated Show resolved Hide resolved
mirascope/core/_internal/utils.py Outdated Show resolved Hide resolved
mirascope/core/base/toolkit.py Outdated Show resolved Hide resolved
mirascope/core/base/toolkit.py Outdated Show resolved Hide resolved
mirascope/core/base/toolkit.py Outdated Show resolved Hide resolved
mirascope/core/base/toolkit.py Outdated Show resolved Hide resolved
mirascope/core/base/toolkit.py Outdated Show resolved Hide resolved
mirascope/core/base/toolkit.py Outdated Show resolved Hide resolved
@willbakst willbakst linked an issue Jun 21, 2024 that may be closed by this pull request
@koxudaxi koxudaxi marked this pull request as ready for review June 21, 2024 17:10
@koxudaxi koxudaxi requested a review from willbakst June 21, 2024 17:53
@willbakst willbakst merged commit 8b51c53 into Mirascope:v1 Jun 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable tool schemas to support more dynamic generation
2 participants