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

New tool abstraction #23

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

New tool abstraction #23

wants to merge 5 commits into from

Conversation

ProKil
Copy link
Collaborator

@ProKil ProKil commented Jul 27, 2024

Closes #14

📑 Description

Breaking change!!!

A new tool abstraction:

As an example,

class VenmoSendMoneyInput(BaseModel):
    recipient_username: str = Field(..., description="The username of the recipient.")
    amount: float = Field(..., description="The amount of money to send, must be positive.")
    note: Optional[str] = Field(..., description="A note to include with the payment. Default is an empty string.")

class VenmoSendMoneyOutput(BaseModel):
    success: bool = Field(..., description="Indicates whether the transaction was successful.")
    transaction_id: Optional[str] = Field(..., description="The unique identifier of the transaction, if successful.")
    error_message: Optional[str] = Field(..., description="If unsuccessful.")


class InvalidRequestException(Exception):
    value: str = "Invalid request"

class NotFoundException(Exception):
    value: str = "Not found"



@ToolRegistry.register(
    tool_name="venmo_send_money",
    toolkit_name="venmo",
    input_type=VenmoSendMoneyInput,
    output_type=VenmoSendMoneyOutput,
    exception_type=InvalidRequestException | NotFoundException,
    tool_summary="Send money to another Venmo user.",
)
class VenmoSendMoney(BaseTool[VenmoSendMoneyInput, VenmoSendMoneyOutput, InvalidRequestException | NotFoundException]):
    @classmethod
    def run(cls, input: VenmoSendMoneyInput) -> VenmoSendMoneyOutput:
        # Send money to another Venmo user
        return VenmoSendMoneyOutput(success=True, transaction_id="123456", error_message=None)

When you want to use it:

def test_venmo_send_money() -> None:
    venmo_send_money = ToolRegistry.registry["venmo"]["venmo_send_money"]

    result = venmo_send_money.call(
        {
            "recipient_username": "user",
            "amount": "10",
            "note": "Splitting the bill for last night's seafood dinner.",
        }
    )

    assert result.result.status == "ok"
    assert result.result.output.json() == "{\"success\": true, \"transaction_id\": \"123456\", \"error_message\": null}"

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed
  • Branch name follows type/descript (e.g. feature/add-llm-agents)
  • Ready for code review

ℹ Additional Information

Sorry, something went wrong.

@ProKil ProKil linked an issue Jul 27, 2024 that may be closed by this pull request
@ProKil
Copy link
Collaborator Author

ProKil commented Jul 27, 2024

@XuhuiZhou You may need to change llm_engine accordingly.

@ProKil
Copy link
Collaborator Author

ProKil commented Jul 28, 2024

@XuhuiZhou I added another example to it. But I don't know how you implemented Venmo, so I only added a dummy implementation.

@XuhuiZhou
Copy link
Owner

XuhuiZhou commented Jul 28, 2024

@XuhuiZhou I added another example to it. But I don't know how you implemented Venmo, so I only added a dummy implementation.

Thanksss!
btw, any chance you can clarify your confusion? The Venmo tool is implemented in the virtual_tools.py script?

@ProKil
Copy link
Collaborator Author

ProKil commented Jul 29, 2024

I meant the implementation, i.e. how send money is executed. For the Python example, I implemented the python executor, but for venmo I don't know how you want to implement it? Now I just use a dummy implementation:

class VenmoSendMoney(BaseTool[VenmoSendMoneyInput, VenmoSendMoneyOutput, InvalidRequestException | NotFoundException]):
    @classmethod
    def run(cls, input: VenmoSendMoneyInput) -> VenmoSendMoneyOutput:
        # Send money to another Venmo user
        return VenmoSendMoneyOutput(success=True, transaction_id="123456", error_message=None)

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.

[FEAT]: Revamping the tools
2 participants