Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ import json
|
|
| 12 |
import re
|
| 13 |
import uuid
|
| 14 |
import time
|
| 15 |
-
import ast
|
| 16 |
|
| 17 |
# --- Pydantic Import ---
|
| 18 |
from pydantic import BaseModel, Field
|
|
@@ -29,7 +29,7 @@ from langgraph.prebuilt import ToolNode
|
|
| 29 |
from langgraph.graph import START, END, StateGraph
|
| 30 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 31 |
from langchain_core.tools import tool
|
| 32 |
-
from
|
| 33 |
|
| 34 |
# --- RAG Imports ---
|
| 35 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
@@ -696,9 +696,11 @@ class BasicAgent:
|
|
| 696 |
def __init__(self):
|
| 697 |
print("BasicAgent (Single LLM) initializing...")
|
| 698 |
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
|
|
|
|
|
|
| 702 |
|
| 703 |
self.tools = defined_tools
|
| 704 |
|
|
@@ -767,21 +769,22 @@ Your goal: Provide the EXACT answer in the EXACT format requested.
|
|
| 767 |
**REMEMBER:** One step at a time. Use tools. Format JSON correctly.
|
| 768 |
"""
|
| 769 |
|
| 770 |
-
|
|
|
|
| 771 |
try:
|
| 772 |
# --- Initialize ONE Powerful LLM for all tasks ---
|
| 773 |
-
self.llm_with_tools =
|
|
|
|
|
|
|
| 774 |
temperature=0,
|
| 775 |
-
|
| 776 |
-
model_name="llama-3.3-70b-versatile", # <-- Use the powerful model
|
| 777 |
-
max_tokens=4096,
|
| 778 |
-
timeout=60
|
| 779 |
).bind_tools(self.tools)
|
| 780 |
-
print("✅ Main LLM (
|
| 781 |
|
| 782 |
except Exception as e:
|
| 783 |
-
print(f"❌ Error initializing
|
| 784 |
raise
|
|
|
|
| 785 |
|
| 786 |
# --- Node 1: The Agent ---
|
| 787 |
def agent_node(state: AgentState):
|
|
|
|
| 12 |
import re
|
| 13 |
import uuid
|
| 14 |
import time
|
| 15 |
+
import ast
|
| 16 |
|
| 17 |
# --- Pydantic Import ---
|
| 18 |
from pydantic import BaseModel, Field
|
|
|
|
| 29 |
from langgraph.graph import START, END, StateGraph
|
| 30 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 31 |
from langchain_core.tools import tool
|
| 32 |
+
from langchain_google_genai import ChatGoogleGenerativeAI # <-- For Gemini
|
| 33 |
|
| 34 |
# --- RAG Imports ---
|
| 35 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
|
|
| 696 |
def __init__(self):
|
| 697 |
print("BasicAgent (Single LLM) initializing...")
|
| 698 |
|
| 699 |
+
# --- *** UPDATED: Check for Google API Key *** ---
|
| 700 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 701 |
+
if not GEMINI_API_KEY:
|
| 702 |
+
raise ValueError("GEMINI_API_KEY environment variable is not set!")
|
| 703 |
+
# --- *** END UPDATE *** ---
|
| 704 |
|
| 705 |
self.tools = defined_tools
|
| 706 |
|
|
|
|
| 769 |
**REMEMBER:** One step at a time. Use tools. Format JSON correctly.
|
| 770 |
"""
|
| 771 |
|
| 772 |
+
# --- *** UPDATED: Initialize Google Gemini LLM *** ---
|
| 773 |
+
print("Initializing Google Gemini LLM...")
|
| 774 |
try:
|
| 775 |
# --- Initialize ONE Powerful LLM for all tasks ---
|
| 776 |
+
self.llm_with_tools = ChatGoogleGenerativeAI(
|
| 777 |
+
model="gemini-1.5-pro-latest", # Use Gemini 1.5 Pro
|
| 778 |
+
google_api_key=GEMINI_API_KEY,
|
| 779 |
temperature=0,
|
| 780 |
+
convert_system_message_to_human=True # Helps with compatibility
|
|
|
|
|
|
|
|
|
|
| 781 |
).bind_tools(self.tools)
|
| 782 |
+
print("✅ Main LLM (Gemini 1.5 Pro with tools) initialized.")
|
| 783 |
|
| 784 |
except Exception as e:
|
| 785 |
+
print(f"❌ Error initializing Gemini: {e}")
|
| 786 |
raise
|
| 787 |
+
# --- *** END UPDATE *** ---
|
| 788 |
|
| 789 |
# --- Node 1: The Agent ---
|
| 790 |
def agent_node(state: AgentState):
|