Update agent.py
Browse files
agent.py
CHANGED
|
@@ -32,17 +32,6 @@ def build_gemini_llm():
|
|
| 32 |
raise ValueError("GOOGLE_API_KEY environment variable is not set.")
|
| 33 |
return ChatGoogleGenerativeAI(model = "gemini-3.7-flash", temperature = 0, max_output_tokens = 1025, include_thoughts=True)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
@tool
|
| 37 |
-
def search_web(query:str) -> str:
|
| 38 |
-
"""
|
| 39 |
-
Searches the web for the answer to a given question or topic.
|
| 40 |
-
Args:
|
| 41 |
-
query (str): the question or topic to search for.
|
| 42 |
-
"""
|
| 43 |
-
print(f"Query to ddsg: {query}")
|
| 44 |
-
return DuckDuckGoSearchRun()
|
| 45 |
-
|
| 46 |
@tool
|
| 47 |
def extract_text_from_image(img_path: str) -> str:
|
| 48 |
"""
|
|
@@ -184,6 +173,7 @@ def wikipedia_search(query: str):
|
|
| 184 |
print(f"Wikipedia search failed for {query}: {e}")
|
| 185 |
return f"Wikipedia search failed for {query} due to {e}."
|
| 186 |
|
|
|
|
| 187 |
model = build_gemini_llm()
|
| 188 |
tools = [
|
| 189 |
search_web,
|
|
@@ -195,7 +185,7 @@ def assistant(state: AgentState):
|
|
| 195 |
response = model_with_tools.invoke(state["messages"])
|
| 196 |
print("--- Thinking Section ---")
|
| 197 |
print(response.content[0].get("thinking").strip())
|
| 198 |
-
print("--- End of Thinking ---")
|
| 199 |
return {
|
| 200 |
"messages": [response],
|
| 201 |
"file_path": state["file_path"],
|
|
|
|
| 32 |
raise ValueError("GOOGLE_API_KEY environment variable is not set.")
|
| 33 |
return ChatGoogleGenerativeAI(model = "gemini-3.7-flash", temperature = 0, max_output_tokens = 1025, include_thoughts=True)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
@tool
|
| 36 |
def extract_text_from_image(img_path: str) -> str:
|
| 37 |
"""
|
|
|
|
| 173 |
print(f"Wikipedia search failed for {query}: {e}")
|
| 174 |
return f"Wikipedia search failed for {query} due to {e}."
|
| 175 |
|
| 176 |
+
web_search = DuckDuckGoSearchRun()
|
| 177 |
model = build_gemini_llm()
|
| 178 |
tools = [
|
| 179 |
search_web,
|
|
|
|
| 185 |
response = model_with_tools.invoke(state["messages"])
|
| 186 |
print("--- Thinking Section ---")
|
| 187 |
print(response.content[0].get("thinking").strip())
|
| 188 |
+
print("--- End of Thinking ---\n\n")
|
| 189 |
return {
|
| 190 |
"messages": [response],
|
| 191 |
"file_path": state["file_path"],
|