Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why the PythonTools will always being called? #1084

Open
KevinZhang19870314 opened this issue Aug 5, 2024 · 2 comments
Open

Why the PythonTools will always being called? #1084

KevinZhang19870314 opened this issue Aug 5, 2024 · 2 comments
Assignees

Comments

@KevinZhang19870314
Copy link

KevinZhang19870314 commented Aug 5, 2024

For below code, why the 'PythonTools' will always being called? Even I am not say any date or time related words in text?

My opinion is, the python tools will be called when needed. The tool calls is a timeconsuming task, it should be better that the tool called as needed.

import os
import pathlib

from phi.assistant import Assistant
from phi.llm.openai import OpenAIChat
from phi.tools.python import PythonTools
from pydantic import BaseModel, Field
from dotenv import load_dotenv

load_dotenv()

STORAGE_ROOT = os.getenv('STORAGE_ROOT')
PYTHON_TOOLS_STORAGE = os.getenv('PYTHON_TOOLS')
PYTHON_TOOLS_STORAGE_FOLDER_PATH = os.path.join(STORAGE_ROOT, PYTHON_TOOLS_STORAGE)


class TradesAPIParameter(BaseModel):
	startTime: str = Field(None, description="Start time for transaction creation. Use the python_tools tool to generate the code and get the value, in the format '2024-07-26T00:00:00+08:00'.")
	endTime: str = Field(None, description="End time for transaction creation. Use the python_tools tool to generate the code and get the value, in the format '2024-07-26T23:59:59+08:00'.")
	page: int = Field(1, description="Current page number for pagination.")
	size: int = Field(10, description="Number of records per page for pagination.")


movie_assistant = Assistant(
	llm=OpenAIChat(model="gpt-4o"),
	description="You are a parameter parser for the transaction record query API, responsible for parsing the natural language input by the user into the parameter fields required by this API.",
	output_model=TradesAPIParameter,
	tools=[PythonTools(base_dir=pathlib.Path(PYTHON_TOOLS_STORAGE_FOLDER_PATH))],
	show_tool_calls=False,
	debug_mode=False,
)

params = movie_assistant.run("Query the records, and make sure 14 records are displayed per page.")
print("=========================")
print(params)
print("=========================")
@jacobweiss2305
Copy link
Contributor

@KevinZhang19870314 can you try adding instructions = ["Only use python tools when ..."] to the Assistant(instructions=[]) clss. Let me know if that helps.

@jacobweiss2305 jacobweiss2305 self-assigned this Aug 5, 2024
@KevinZhang19870314
Copy link
Author

@KevinZhang19870314 can you try adding instructions = ["Only use python tools when ..."] to the Assistant(instructions=[]) clss. Let me know if that helps.

@jacobweiss2305 It worked for me, thank you very much!

instructions=["Only use the python_tools tool when the user mentions date or time-related words or text."],

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

No branches or pull requests

2 participants