Skip to content

New tool abstraction#23

Open
ProKil wants to merge 5 commits intomainfrom
feature/tool_abstraction
Open

New tool abstraction#23
ProKil wants to merge 5 commits intomainfrom
feature/tool_abstraction

Conversation

@ProKil
Copy link
Copy Markdown
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

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

ProKil commented Jul 27, 2024

@XuhuiZhou You may need to change llm_engine accordingly.

@ProKil
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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