stay hard
Browse files- __pycache__/controller.cpython-311.pyc +0 -0
- __pycache__/csv_service.cpython-311.pyc +0 -0
- __pycache__/intitial_q_handler.cpython-311.pyc +0 -0
- __pycache__/util_service.cpython-311.pyc +0 -0
- api_key_rotation.log +7 -0
- controller.py +5 -4
- generated_charts/ad7edf2e-aa17-41e8-9e45-2f8e0c97000d.png +0 -0
- generated_charts/chart_c7a1ac5d0fc64199a5f66f7082a48d18.png +0 -0
- rethink_gemini_agents/__pycache__/gemini_langchain_service.cpython-311.pyc +0 -0
- rethink_gemini_agents/__pycache__/rethink_chart.cpython-311.pyc +0 -0
- rethink_gemini_agents/__pycache__/rethink_chat.cpython-311.pyc +0 -0
- rethink_gemini_agents/gemini_langchain_service.py +6 -13
- rethink_gemini_agents/rethink_chart.py +31 -3
__pycache__/controller.cpython-311.pyc
ADDED
Binary file (26.1 kB). View file
|
|
__pycache__/csv_service.cpython-311.pyc
ADDED
Binary file (6.15 kB). View file
|
|
__pycache__/intitial_q_handler.cpython-311.pyc
ADDED
Binary file (1.49 kB). View file
|
|
__pycache__/util_service.cpython-311.pyc
ADDED
Binary file (4.89 kB). View file
|
|
api_key_rotation.log
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
2025-02-23 10:59:01,652 - INFO - Max CPUs: 12
|
2 |
+
2025-02-23 10:59:16,924 - INFO - Successfully configured with key: AIzaSyC6...YN7s
|
3 |
+
2025-02-23 10:59:19,466 - WARNING - Retry 1/5...
|
4 |
+
2025-02-23 11:00:44,274 - INFO - Max CPUs: 12
|
5 |
+
2025-02-23 11:02:10,466 - INFO - Successfully configured with key: AIzaSyC6...YN7s
|
6 |
+
2025-02-23 11:13:51,950 - INFO - Successfully configured with key: AIzaSyC6...YN7s
|
7 |
+
2025-02-23 11:16:15,194 - INFO - Successfully configured with key: AIzaSyC6...YN7s
|
controller.py
CHANGED
@@ -800,15 +800,16 @@ async def csv_chart(request: dict, authorization: str = Header(None)):
|
|
800 |
# First, try the langchain-based method if the question qualifies
|
801 |
|
802 |
if if_initial_chat_question(query):
|
803 |
-
|
804 |
langchain_gemini_csv_chat, csv_url, query, False
|
805 |
)
|
806 |
-
logger.info("gemini langchain_answer --> ",
|
807 |
-
|
|
|
808 |
|
809 |
gemini_answer = await asyncio.to_thread(gemini_llm_chart, csv_url, query)
|
810 |
logger.info("gemini_answer --> ", gemini_answer)
|
811 |
-
return
|
812 |
|
813 |
if if_initial_chart_question(query):
|
814 |
langchain_result = await loop.run_in_executor(
|
|
|
800 |
# First, try the langchain-based method if the question qualifies
|
801 |
|
802 |
if if_initial_chat_question(query):
|
803 |
+
langchain_gemini_chart_answer = await asyncio.to_thread(
|
804 |
langchain_gemini_csv_chat, csv_url, query, False
|
805 |
)
|
806 |
+
logger.info("gemini langchain_answer --> ", langchain_gemini_chart_answer)
|
807 |
+
if isinstance(langchain_gemini_chart_answer, list) and len(langchain_gemini_chart_answer) > 0:
|
808 |
+
return FileResponse(langchain_gemini_chart_answer[0], media_type="image/png")
|
809 |
|
810 |
gemini_answer = await asyncio.to_thread(gemini_llm_chart, csv_url, query)
|
811 |
logger.info("gemini_answer --> ", gemini_answer)
|
812 |
+
return FileResponse(gemini_answer, media_type="image/png")
|
813 |
|
814 |
if if_initial_chart_question(query):
|
815 |
langchain_result = await loop.run_in_executor(
|
generated_charts/ad7edf2e-aa17-41e8-9e45-2f8e0c97000d.png
ADDED
![]() |
generated_charts/chart_c7a1ac5d0fc64199a5f66f7082a48d18.png
ADDED
![]() |
rethink_gemini_agents/__pycache__/gemini_langchain_service.cpython-311.pyc
ADDED
Binary file (7.77 kB). View file
|
|
rethink_gemini_agents/__pycache__/rethink_chart.cpython-311.pyc
ADDED
Binary file (14.3 kB). View file
|
|
rethink_gemini_agents/__pycache__/rethink_chat.cpython-311.pyc
ADDED
Binary file (15 kB). View file
|
|
rethink_gemini_agents/gemini_langchain_service.py
CHANGED
@@ -197,16 +197,9 @@ def langchain_gemini_csv_chart(csv_url: str, question: str, chart_required: bool
|
|
197 |
|
198 |
|
199 |
# Example usage:
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
# # Define a regex pattern that matches 'temp' followed by one or more digits.
|
207 |
-
# pattern = r"temp\d+"
|
208 |
-
|
209 |
-
# # Use re.findall to extract all occurrences that match the pattern.
|
210 |
-
# names = re.findall(pattern, output)
|
211 |
-
|
212 |
-
# print(names)
|
|
|
197 |
|
198 |
|
199 |
# Example usage:
|
200 |
+
if __name__ == "__main__":
|
201 |
+
csv_url = "./documents/titanic.csv"
|
202 |
+
question = "Create a pie chart of males vs females"
|
203 |
+
output = langchain_gemini_csv_chat(csv_url, question, True)
|
204 |
+
print("Agent output:", output)
|
205 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rethink_gemini_agents/rethink_chart.py
CHANGED
@@ -10,7 +10,6 @@ from typing import Optional, Dict, Any, List
|
|
10 |
from pydantic import BaseModel, Field
|
11 |
from google.generativeai import GenerativeModel, configure
|
12 |
from dotenv import load_dotenv
|
13 |
-
from csv_service import clean_data
|
14 |
|
15 |
# Load environment variables from .env file
|
16 |
load_dotenv()
|
@@ -211,7 +210,7 @@ class RethinkAgent(BaseModel):
|
|
211 |
|
212 |
|
213 |
def gemini_llm_chart(csv_url: str, query: str) -> str:
|
214 |
-
df =
|
215 |
|
216 |
agent = RethinkAgent(df=df)
|
217 |
if not agent.initialize_model(API_KEYS):
|
@@ -221,6 +220,22 @@ def gemini_llm_chart(csv_url: str, query: str) -> str:
|
|
221 |
result = agent.execute_query(query)
|
222 |
print("\nAnalysis Result:")
|
223 |
print(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
|
226 |
|
@@ -235,4 +250,17 @@ def gemini_llm_chart(csv_url: str, query: str) -> str:
|
|
235 |
|
236 |
# result = agent.execute_query("Create a scatter plot of total_bill vs tip with kernel density estimate")
|
237 |
# print("\nAnalysis Result:")
|
238 |
-
# print(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
from pydantic import BaseModel, Field
|
11 |
from google.generativeai import GenerativeModel, configure
|
12 |
from dotenv import load_dotenv
|
|
|
13 |
|
14 |
# Load environment variables from .env file
|
15 |
load_dotenv()
|
|
|
210 |
|
211 |
|
212 |
def gemini_llm_chart(csv_url: str, query: str) -> str:
|
213 |
+
df = pd.read_csv(csv_url)
|
214 |
|
215 |
agent = RethinkAgent(df=df)
|
216 |
if not agent.initialize_model(API_KEYS):
|
|
|
220 |
result = agent.execute_query(query)
|
221 |
print("\nAnalysis Result:")
|
222 |
print(result)
|
223 |
+
|
224 |
+
if isinstance(result, str):
|
225 |
+
result = result.strip() # Remove any leading/trailing spaces or newlines
|
226 |
+
|
227 |
+
match = re.search(r'CHART_SAVED:\s*(\S+)', result)
|
228 |
+
|
229 |
+
if match:
|
230 |
+
chart_path = match.group(1)
|
231 |
+
print("Chart Path:", chart_path)
|
232 |
+
return chart_path
|
233 |
+
else:
|
234 |
+
print("Chart path not found")
|
235 |
+
return None
|
236 |
+
else:
|
237 |
+
print("Unexpected result format:", type(result))
|
238 |
+
return None
|
239 |
|
240 |
|
241 |
|
|
|
250 |
|
251 |
# result = agent.execute_query("Create a scatter plot of total_bill vs tip with kernel density estimate")
|
252 |
# print("\nAnalysis Result:")
|
253 |
+
# print(result)
|
254 |
+
|
255 |
+
# if isinstance(result, str):
|
256 |
+
# result = result.strip() # Remove any leading/trailing spaces or newlines
|
257 |
+
|
258 |
+
# match = re.search(r'CHART_SAVED:\s*(\S+)', result)
|
259 |
+
|
260 |
+
# if match:
|
261 |
+
# chart_path = match.group(1)
|
262 |
+
# print("Chart Path:", chart_path)
|
263 |
+
# else:
|
264 |
+
# print("Chart path not found")
|
265 |
+
# else:
|
266 |
+
# print("Unexpected result format:", type(result))
|