Code: Select all
import pandas as pd
from time import time
from openai_tools import create_pandas_dataframe_agent
# Data import
csv_dir_path = 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv'
df = pd.read_csv(csv_dir_path)
# Creating Pandas Agent
agent_executor = create_pandas_dataframe_agent(
model,
df,
verbose=True,
agent_type="openai-tools",
max_iterations=5
)
def agent_query(question):
time_start = time()
res = agent_executor.invoke({"input": question})
time_finish = time()
print("Query execution time:", time_finish - time_start, "seconds")
return res['output']
# Example query
question = 'whats the percentage of male survivors'
agent_query(question)
Leistungsverzögerung: Abfragen dauern 8 bis 12 Sekunden, obwohl die Antwort manchmal früher bereit ist.
Lösungsversuche: Ich habe versucht, max_iterations ohne spürbare Auswirkungen auf die Antwortzeit anzupassen. Die Profilerstellung deutet darauf hin, dass die Verzögerung möglicherweise auf das Laden von Daten oder den Modellaufruf zurückzuführen ist.
Gewünschtes Ergebnis:
Ich möchte die Antwortzeit der Abfrage verbessern. Wie kann ich die Effizienz verbessern oder Engpässe identifizieren?
Hier ist eine Ausgabe, die ich regelmäßig erhalte:
Code: Select all
> Entering new AgentExecutor chain...
Invoking: `python_repl_ast` with `{'query': "male_survivors = df[(df['Sex'] == 'male') & (df['Survived'] == 1)].shape[0]\ntotal_males = df[df['Sex'] == 'male'].shape[0]\npercentage_male_survivors = (male_survivors / total_males) * 100\npercentage_male_survivors"}`
18.890814558058924The percentage of male survivors is approximately 18.89%.
> Finished chain.
9.06292200088501
Mobile version