Find answers from the community

Updated 3 months ago

Is the `ToolRetrieverRouterQueryEngine.

Is there a way of making ToolRetrieverRouterQueryEngine.query method working with FunctionTool? Because it tries to call a query_engine attribute in FunctionTool which doesn't exist... More details in the thread.
C
5 comments
Plain Text
def my_fn_a(param_a: int, param_b: str) -> str:
    """This is a fisrt test function."""

    return "The result is {} and {}.".format(param_a, param_b)

def my_fn_b(param_a: int, param_b: str) -> str:
    """This is a second test function."""

    return "The result is {} and {}.".format(param_a, param_b)

transaction_tools = [
    FunctionTool.from_defaults(fn=my_fn_a),
    FunctionTool.from_defaults(fn=my_fn_b),
]


tool_mapping = SimpleToolNodeMapping.from_objects(transaction_tools)
transations_tool_index = ObjectIndex.from_objects(
    transaction_tools,
    tool_mapping,
    VectorStoreIndex,
)

transactions_router_query_engine = ToolRetrieverRouterQueryEngine(transations_tool_index.as_retriever(similarity_top_k=1))
transactions_router_query_engine.query("The result is 1 and a.")

# AttributeError: 'FunctionTool' object has no attribute 'query_engine'
I'm trying to find other alternatives, please let me know if you guys know any. My final goal was to pass a ToolRetrieverRouterQueryEngine to RouterQueryEngines query_engine_tools
Ok I was able to make it work. First I had to create a FnRetrieverOpenAIAgent using the transations_tool_index, then I could pass this created agent to a new QueryEngineTool, that is the type accepted by the RouterQueryEngine.

Plain Text
transactions_agent = FnRetrieverOpenAIAgent.from_retriever(
    transations_tool_index.as_retriever(), verbose=True
)

query_engine = RouterQueryEngine(
    selector=PydanticSingleSelector.from_defaults(),
    query_engine_tools=[
        QueryEngineTool(query_engine=transactions_agent),
        q_tool,
    ],
)
I'm get crazy about all these layers and abstractions, but I'm so happy that as a LLM noob, I'm being able to get things done with LlamaIndex. This framework rules. Thanks!
Add a reply
Sign up and join the conversation on Discord