# define tools for query engine
vector_tool = QueryEngineTool.from_defaults(
query_engine=mm_query_engine,
name="vector_tool",
description=(
"""Useful for retrieving specific context from the data."""
),
)
page_amounts_list_tool = QueryEngineTool.from_defaults(
query_engine=mm_query_engine,
name="page_amounts_list_tool",
description=(
"""Useful for retrieving total amount excluding tax from all line
items in a given page and putting them in a list."""
),
)
invoice_amount_validation_tool = QueryEngineTool.from_defaults(
query_engine=mm_query_engine,
name="invoice_amount_validation_tool",
description=(
"""Useful for validating the sum of all amounts of all line items
in the invoice against the total amount excluding tax of the
invoice. Validation is successful only when the two amounts are
equal."""
),
)
# define function tools with pydantic basemodels
class SumAmounts(BaseModel):
"""Data class for summing amounts of line items in a list."""
amounts: List[float] = Field(..., title="List of total amounts excluding tax of line items to sum.")
def sum_amounts(input_amounts: SumAmounts) -> float:
"""Sums a list of amounts provided in input_amounts."""
return round(sum(input_amounts.amounts), 2)
sum_tool = FunctionTool.from_defaults(
fn=sum_amounts,
name='sum_amounts',
description='Sums a list of amounts provided in the "amounts" field.'
)