Update gemini_agent.py
Browse files- gemini_agent.py +7 -3
gemini_agent.py
CHANGED
|
@@ -3,6 +3,10 @@ import time
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from typing import TypedDict, Annotated, Optional
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 7 |
from langgraph.graph import StateGraph, START
|
| 8 |
from langgraph.graph.message import add_messages
|
|
@@ -98,7 +102,7 @@ class GEMINI_AGENT:
|
|
| 98 |
keyword = "FINAL ANSWER: "
|
| 99 |
index = text.find(keyword)
|
| 100 |
if index != -1:
|
| 101 |
-
return text[index + len(keyword):]
|
| 102 |
else:
|
| 103 |
return ""
|
| 104 |
|
|
@@ -118,7 +122,7 @@ class GEMINI_AGENT:
|
|
| 118 |
try:
|
| 119 |
response = self.app.invoke({"messages": messages, "input_file": None})
|
| 120 |
final_ans = self.extract_after_final_answer(response['messages'][-1].content)
|
| 121 |
-
time.sleep(60)
|
| 122 |
return final_ans
|
| 123 |
except Exception as e:
|
| 124 |
sleep_time = base_sleep * (attempt + 1)
|
|
@@ -128,4 +132,4 @@ class GEMINI_AGENT:
|
|
| 128 |
time.sleep(sleep_time)
|
| 129 |
continue
|
| 130 |
return f"Error processing query after {max_retries} attempts: {str(e)}"
|
| 131 |
-
return "This is a default answer."
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from typing import TypedDict, Annotated, Optional
|
| 5 |
|
| 6 |
+
# Set USER_AGENT early to identify requests (fixes warning)
|
| 7 |
+
os.environ["USER_AGENT"] = "Hennessy2025-Final-Agent"
|
| 8 |
+
print(f"USER_AGENT set to: {os.getenv('USER_AGENT')}")
|
| 9 |
+
|
| 10 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 11 |
from langgraph.graph import StateGraph, START
|
| 12 |
from langgraph.graph.message import add_messages
|
|
|
|
| 102 |
keyword = "FINAL ANSWER: "
|
| 103 |
index = text.find(keyword)
|
| 104 |
if index != -1:
|
| 105 |
+
return text[index + len(keyword):].strip()
|
| 106 |
else:
|
| 107 |
return ""
|
| 108 |
|
|
|
|
| 122 |
try:
|
| 123 |
response = self.app.invoke({"messages": messages, "input_file": None})
|
| 124 |
final_ans = self.extract_after_final_answer(response['messages'][-1].content)
|
| 125 |
+
time.sleep(60) # avoid rate limit
|
| 126 |
return final_ans
|
| 127 |
except Exception as e:
|
| 128 |
sleep_time = base_sleep * (attempt + 1)
|
|
|
|
| 132 |
time.sleep(sleep_time)
|
| 133 |
continue
|
| 134 |
return f"Error processing query after {max_retries} attempts: {str(e)}"
|
| 135 |
+
return "This is a default answer."
|