Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@idiotWu
Copy link
Collaborator

@idiotWu idiotWu commented Apr 6, 2024

This PR introduces a new decorator npi_tool so that we can register tool functions more elegantly:

Before

Tool definition and registration are coded in separated sections, making it difficult to maintain.

class MyApp(App):
    def get_functions(self) -> List[FunctionRegistration]:
         return [
            FunctionRegistration(
                fn=self.search_emails,
                Params=SearchEmailsParameters,
                description='Search for emails with a query'
            ),
         ]
    
    def search_emails(self, params: SearchEmailsParameters):
         ...

After

Tool definition and registration are tightly bound.

class MyApp(App):
    # Default: `Params` is inferred from type hints, and `description` is inferred from docstring
    @npi_tool
    def search_emails(self, params: SearchEmailsParameters):
         """Search for emails with a query"""
         ...

    # You can also explicitly set the `Param` and `description`
    @npi_tool(
        Params=WaitForReplyParameters,
        description='Wait for a reply from the last email sent in the previous chats'
    )
    def wait_for_reply(self, params):
         ...

@idiotWu idiotWu requested a review from wenfengwang April 6, 2024 11:56
@idiotWu idiotWu force-pushed the refactor-decorator branch from 23d537e to 9a6c640 Compare April 6, 2024 12:17
@idiotWu idiotWu force-pushed the refactor-decorator branch from 9a6c640 to f973587 Compare April 6, 2024 12:27
@idiotWu idiotWu force-pushed the refactor-decorator branch 2 times, most recently from e03d413 to 245fe2c Compare April 6, 2024 12:49
@idiotWu idiotWu force-pushed the refactor-decorator branch from 245fe2c to c9f1dab Compare April 6, 2024 13:07
@wenfengwang wenfengwang merged commit ef3a42e into main Apr 6, 2024
@idiotWu idiotWu deleted the refactor-decorator branch April 7, 2024 03:54
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.

3 participants