added csv-agent-default in next.js
Browse files- controller.py +1 -1
- gemini_report_generator.py +11 -5
controller.py
CHANGED
@@ -621,7 +621,7 @@ async def csv_chart(request: dict, authorization: str = Header(None)):
|
|
621 |
chat_id = request.get("chat_id", "")
|
622 |
|
623 |
if generate_report is True:
|
624 |
-
report_files = await generate_csv_report(csv_url, query, chat_id)
|
625 |
if report_files is not None:
|
626 |
return {"orchestrator_response": jsonable_encoder(report_files)}
|
627 |
|
|
|
621 |
chat_id = request.get("chat_id", "")
|
622 |
|
623 |
if generate_report is True:
|
624 |
+
report_files = await generate_csv_report(csv_url, query, chat_id, conversation_history)
|
625 |
if report_files is not None:
|
626 |
return {"orchestrator_response": jsonable_encoder(report_files)}
|
627 |
|
gemini_report_generator.py
CHANGED
@@ -146,6 +146,7 @@ class RethinkAgent(BaseModel):
|
|
146 |
current_retry: int = Field(default=0, ge=0)
|
147 |
repl: Optional[PythonREPL] = None
|
148 |
key_manager: Optional[GeminiKeyManager] = None
|
|
|
149 |
|
150 |
class Config:
|
151 |
arbitrary_types_allowed = True
|
@@ -155,7 +156,10 @@ class RethinkAgent(BaseModel):
|
|
155 |
return code_match.group(1).strip() if code_match else response.strip()
|
156 |
|
157 |
def _generate_initial_prompt(self, query: str) -> str:
|
158 |
-
|
|
|
|
|
|
|
159 |
|
160 |
MANDATORY REQUIREMENTS:
|
161 |
1. Operate directly on existing 'df' variable
|
@@ -189,6 +193,8 @@ class RethinkAgent(BaseModel):
|
|
189 |
# Save results
|
190 |
sales_by_region.to_csv(f'{{output_dir}}/sales_by_region.csv')
|
191 |
"""
|
|
|
|
|
192 |
|
193 |
def _generate_retry_prompt(self, query: str, error: str, code: str) -> str:
|
194 |
return f"""FIX THIS CODE (failed with: {error}) by STRICTLY FOLLOWING:
|
@@ -261,10 +267,10 @@ class RethinkAgent(BaseModel):
|
|
261 |
"image_files": []
|
262 |
}
|
263 |
|
264 |
-
def gemini_llm_chat(csv_url: str, query: str) -> Dict[str, Any]:
|
265 |
try:
|
266 |
df = pd.read_csv(csv_url)
|
267 |
-
agent = RethinkAgent(df=df)
|
268 |
|
269 |
if not agent.initialize_model(API_KEYS):
|
270 |
return {"error": "API configuration failed"}
|
@@ -288,9 +294,9 @@ def gemini_llm_chat(csv_url: str, query: str) -> Dict[str, Any]:
|
|
288 |
}
|
289 |
|
290 |
|
291 |
-
async def generate_csv_report(csv_url: str, query: str, chat_id: str) -> FileBoxProps:
|
292 |
try:
|
293 |
-
result = gemini_llm_chat(csv_url, query)
|
294 |
logger.info(f"Raw result from gemini_llm_chat: {result}")
|
295 |
|
296 |
csv_files = []
|
|
|
146 |
current_retry: int = Field(default=0, ge=0)
|
147 |
repl: Optional[PythonREPL] = None
|
148 |
key_manager: Optional[GeminiKeyManager] = None
|
149 |
+
conversation: List[Dict[str, Any]] = Field(default_factory=list)
|
150 |
|
151 |
class Config:
|
152 |
arbitrary_types_allowed = True
|
|
|
156 |
return code_match.group(1).strip() if code_match else response.strip()
|
157 |
|
158 |
def _generate_initial_prompt(self, query: str) -> str:
|
159 |
+
initial_prompt = f"""Generate DIRECT EXECUTION CODE (no functions, no explanations) following STRICT RULES:
|
160 |
+
|
161 |
+
CONVERSATION HISTORY:
|
162 |
+
{json.dumps(self.conversation)}
|
163 |
|
164 |
MANDATORY REQUIREMENTS:
|
165 |
1. Operate directly on existing 'df' variable
|
|
|
193 |
# Save results
|
194 |
sales_by_region.to_csv(f'{{output_dir}}/sales_by_region.csv')
|
195 |
"""
|
196 |
+
logger.info(initial_prompt)
|
197 |
+
return initial_prompt
|
198 |
|
199 |
def _generate_retry_prompt(self, query: str, error: str, code: str) -> str:
|
200 |
return f"""FIX THIS CODE (failed with: {error}) by STRICTLY FOLLOWING:
|
|
|
267 |
"image_files": []
|
268 |
}
|
269 |
|
270 |
+
def gemini_llm_chat(csv_url: str, query: str, conversation_history: List[Dict[str, Any]]) -> Dict[str, Any]:
|
271 |
try:
|
272 |
df = pd.read_csv(csv_url)
|
273 |
+
agent = RethinkAgent(df=df, conversation_history=conversation_history)
|
274 |
|
275 |
if not agent.initialize_model(API_KEYS):
|
276 |
return {"error": "API configuration failed"}
|
|
|
294 |
}
|
295 |
|
296 |
|
297 |
+
async def generate_csv_report(csv_url: str, query: str, chat_id: str, conversation_history: List[Dict[str, Any]]) -> FileBoxProps:
|
298 |
try:
|
299 |
+
result = gemini_llm_chat(csv_url, query, conversation_history)
|
300 |
logger.info(f"Raw result from gemini_llm_chat: {result}")
|
301 |
|
302 |
csv_files = []
|