-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Can the toolkits "PythonTools" being reusable? #1083
Comments
@KevinZhang19870314 |
@jacobweiss2305 Thanks for your response, below is my code with Assistant instructions added, but it not worked for me. You can see the logs below(Run second time), it still save the file import os
import pathlib
import time
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.")
start_time = time.time()
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))],
instructions=[
"Only use the python_tools tool when the user mentions date or time-related words or text.",
f"When use python_tools tool, save the file to the folder {PYTHON_TOOLS_STORAGE_FOLDER_PATH}. If the file already exists, just run it to get the value; otherwise, save the file and then run it.",
],
show_tool_calls=False,
debug_mode=False,
)
params = movie_assistant.run("Query the today's records, and make sure 14 records are displayed per page.")
end_time = time.time()
execution_time = end_time - start_time
print("=========================")
print(params)
print(movie_assistant.llm.metrics)
print(f"Execution Time: {execution_time} seconds")
print("=========================") log
|
Here is another try, still not worked. 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))],
instructions=[
"Only use the python_tools tool when the user mentions date or time-related words or text.",
f"When use python_tools tool to obtain the startTime and endTime, name the generated python file as 'get_start_end_time.py' and save it in folder {PYTHON_TOOLS_STORAGE_FOLDER_PATH}.",
f"Only save the python file 'get_start_end_time.py' if the file does NOT already exist in folder {PYTHON_TOOLS_STORAGE_FOLDER_PATH}.",
# f"When use python_tools tool, check to see if python file already generated in folder {PYTHON_TOOLS_STORAGE_FOLDER_PATH} or not. If exists, just run it to get the value; otherwise, save the file and then run it.",
],
show_tool_calls=False,
debug_mode=False,
) |
Each time the python tools will generate the code file, can we reuse it the second time?
The text was updated successfully, but these errors were encountered: