Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
from dotenv import load_dotenv
|
| 2 |
from langchain_core.messages import SystemMessage, HumanMessage
|
| 3 |
-
from
|
| 4 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 5 |
from langgraph.graph import StateGraph, START, MessagesState
|
| 6 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 7 |
|
|
|
|
| 8 |
import requests
|
| 9 |
import base64
|
| 10 |
import tiktoken
|
|
@@ -34,13 +35,18 @@ system_message = SystemMessage(content=system_prompt)
|
|
| 34 |
|
| 35 |
class LangGraphAgent:
|
| 36 |
def __init__(self, tasks_api: str):
|
| 37 |
-
self.llm =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
#self.llm = ChatOpenAI(model="gpt-4o", max_retries=2)
|
| 39 |
#self.llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0, google_api_key=os.getenv("GEMINI_API_KEY"))
|
| 40 |
-
self.model_type = "
|
| 41 |
self.llm_with_tools = self.llm.bind_tools(tools)
|
| 42 |
self.tasks_api = tasks_api
|
| 43 |
-
self.encoding = tiktoken.
|
| 44 |
self.max_tokens = 25000 # Leave some buffer below the 30k limit
|
| 45 |
self.apply_max_tokens = True
|
| 46 |
self.logged_message_count = 0 # Track how many messages we've already logged
|
|
@@ -268,8 +274,11 @@ class LangGraphAgent:
|
|
| 268 |
def update_content(self, content: list, file_name: str, file_url: str, model_type: str):
|
| 269 |
try:
|
| 270 |
if file_name.endswith(".png"):
|
| 271 |
-
if model_type
|
| 272 |
-
content.append({
|
|
|
|
|
|
|
|
|
|
| 273 |
elif model_type == "google":
|
| 274 |
content.append({"type": "image_url", "image_url": file_url})
|
| 275 |
|
|
|
|
| 1 |
from dotenv import load_dotenv
|
| 2 |
from langchain_core.messages import SystemMessage, HumanMessage
|
| 3 |
+
from langchain_groq import ChatGroq
|
| 4 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 5 |
from langgraph.graph import StateGraph, START, MessagesState
|
| 6 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 7 |
|
| 8 |
+
import os
|
| 9 |
import requests
|
| 10 |
import base64
|
| 11 |
import tiktoken
|
|
|
|
| 35 |
|
| 36 |
class LangGraphAgent:
|
| 37 |
def __init__(self, tasks_api: str):
|
| 38 |
+
self.llm = ChatGroq(
|
| 39 |
+
model="llama-3.3-70b-versatile",
|
| 40 |
+
api_key=os.getenv("GROQ_API_KEY"),
|
| 41 |
+
temperature=0,
|
| 42 |
+
max_retries=2,
|
| 43 |
+
)
|
| 44 |
#self.llm = ChatOpenAI(model="gpt-4o", max_retries=2)
|
| 45 |
#self.llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0, google_api_key=os.getenv("GEMINI_API_KEY"))
|
| 46 |
+
self.model_type = "groq"
|
| 47 |
self.llm_with_tools = self.llm.bind_tools(tools)
|
| 48 |
self.tasks_api = tasks_api
|
| 49 |
+
self.encoding = tiktoken.get_encoding("cl100k_base")
|
| 50 |
self.max_tokens = 25000 # Leave some buffer below the 30k limit
|
| 51 |
self.apply_max_tokens = True
|
| 52 |
self.logged_message_count = 0 # Track how many messages we've already logged
|
|
|
|
| 274 |
def update_content(self, content: list, file_name: str, file_url: str, model_type: str):
|
| 275 |
try:
|
| 276 |
if file_name.endswith(".png"):
|
| 277 |
+
if model_type in ["groq", "openai"]:
|
| 278 |
+
content.append({
|
| 279 |
+
"type": "image_url",
|
| 280 |
+
"image_url": {"url": file_url}
|
| 281 |
+
})
|
| 282 |
elif model_type == "google":
|
| 283 |
content.append({"type": "image_url", "image_url": file_url})
|
| 284 |
|