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):
...
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.
After
Tool definition and registration are tightly bound.