Update crew.py
Browse files
crew.py
CHANGED
@@ -11,7 +11,7 @@ from google import genai
|
|
11 |
from google.genai import types
|
12 |
from openinference.instrumentation.crewai import CrewAIInstrumentor
|
13 |
from phoenix.otel import register
|
14 |
-
from util import get_final_answer
|
15 |
|
16 |
## LLMs
|
17 |
|
@@ -182,7 +182,7 @@ def run_crew(question, file_path):
|
|
182 |
@tool("Code Generation Tool")
|
183 |
def code_generation_tool(question: str, file_path: str) -> str:
|
184 |
"""Generate and execute Python code to answer a question.
|
185 |
-
The question can be about an optional document.
|
186 |
|
187 |
Args:
|
188 |
question (str): Question to answer
|
@@ -195,20 +195,9 @@ def run_crew(question, file_path):
|
|
195 |
RuntimeError: If processing fails"""
|
196 |
try:
|
197 |
if file_path:
|
198 |
-
df =
|
199 |
-
|
200 |
-
|
201 |
-
pd.read_csv() for CSV files
|
202 |
-
|
203 |
-
pd.read_excel() for Excel files (.xls, .xlsx)
|
204 |
-
|
205 |
-
pd.read_json() for JSON files
|
206 |
-
|
207 |
-
pd.read_parquet() for Parquet files
|
208 |
-
|
209 |
-
pd.read_sql() for SQL queries
|
210 |
-
"""
|
211 |
-
|
212 |
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
213 |
|
214 |
file = client.files.upload(file=file_path)
|
|
|
11 |
from google.genai import types
|
12 |
from openinference.instrumentation.crewai import CrewAIInstrumentor
|
13 |
from phoenix.otel import register
|
14 |
+
from util import read_file, get_final_answer
|
15 |
|
16 |
## LLMs
|
17 |
|
|
|
182 |
@tool("Code Generation Tool")
|
183 |
def code_generation_tool(question: str, file_path: str) -> str:
|
184 |
"""Generate and execute Python code to answer a question.
|
185 |
+
The question can be about an optional csv, xls, xlsx, json, or jsonl document.
|
186 |
|
187 |
Args:
|
188 |
question (str): Question to answer
|
|
|
195 |
RuntimeError: If processing fails"""
|
196 |
try:
|
197 |
if file_path:
|
198 |
+
df = read_file(file_path)
|
199 |
+
question = f"Question:\n{question}\nData:\n{df.to_string()}"
|
200 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
202 |
|
203 |
file = client.files.upload(file=file_path)
|