Update agent.py
Browse files
agent.py
CHANGED
|
@@ -18,6 +18,16 @@ from supabase.client import Client, create_client
|
|
| 18 |
|
| 19 |
load_dotenv()
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def multiply(a: int, b: int) -> int:
|
| 23 |
"""Multiply two numbers.
|
|
@@ -156,17 +166,15 @@ def build_graph(provider: str = "groq"):
|
|
| 156 |
"""Build the graph"""
|
| 157 |
# Load environment variables from .env file
|
| 158 |
if provider == "google":
|
| 159 |
-
|
| 160 |
-
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
|
| 161 |
elif provider == "groq":
|
| 162 |
-
|
| 163 |
-
llm = ChatGroq(model="qwen-qwq-32b", temperature=0) # optional : qwen-qwq-32b gemma2-9b-it
|
| 164 |
elif provider == "huggingface":
|
| 165 |
-
# TODO: Add huggingface endpoint
|
| 166 |
llm = ChatHuggingFace(
|
| 167 |
llm=HuggingFaceEndpoint(
|
| 168 |
url="https://api-inference.huggingface.co/models/Meta-DeepLearning/llama-2-7b-chat-hf",
|
| 169 |
temperature=0,
|
|
|
|
| 170 |
),
|
| 171 |
)
|
| 172 |
else:
|
|
|
|
| 18 |
|
| 19 |
load_dotenv()
|
| 20 |
|
| 21 |
+
from langchain_core.rate_limiters import InMemoryRateLimiter
|
| 22 |
+
|
| 23 |
+
# Create a rate limiter
|
| 24 |
+
rate_limiter = InMemoryRateLimiter(
|
| 25 |
+
requests_per_second=0.1, # Once every 10 seconds
|
| 26 |
+
check_every_n_seconds=0.1,
|
| 27 |
+
max_bucket_size=10,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
@tool
|
| 32 |
def multiply(a: int, b: int) -> int:
|
| 33 |
"""Multiply two numbers.
|
|
|
|
| 166 |
"""Build the graph"""
|
| 167 |
# Load environment variables from .env file
|
| 168 |
if provider == "google":
|
| 169 |
+
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0, rate_limiter=rate_limiter)
|
|
|
|
| 170 |
elif provider == "groq":
|
| 171 |
+
llm = ChatGroq(model="qwen-qwen3-32b", temperature=0, rate_limiter=rate_limiter)
|
|
|
|
| 172 |
elif provider == "huggingface":
|
|
|
|
| 173 |
llm = ChatHuggingFace(
|
| 174 |
llm=HuggingFaceEndpoint(
|
| 175 |
url="https://api-inference.huggingface.co/models/Meta-DeepLearning/llama-2-7b-chat-hf",
|
| 176 |
temperature=0,
|
| 177 |
+
rate_limiter=rate_limiter,
|
| 178 |
),
|
| 179 |
)
|
| 180 |
else:
|