Spaces:
Running
Running
added callback Manager instead of empty callbacks in the fallback groq llm
Browse files- pipeline.py +15 -13
pipeline.py
CHANGED
@@ -191,28 +191,31 @@ CACHE_SIZE_LIMIT = 1000
|
|
191 |
# logger.error(f"Failed to initialize ChatGroq: {e}")
|
192 |
# raise RuntimeError("ChatGroq initialization failed.") from e
|
193 |
|
194 |
-
# Fix for ChatGroq initialization with model_rebuild
|
195 |
|
196 |
from langchain_core.callbacks import CallbackManager
|
197 |
from langchain_core.callbacks.base import BaseCallbackHandler
|
198 |
-
from langchain_core.caches import BaseCache
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
|
203 |
# Initialize ChatGroq with the callback manager
|
204 |
try:
|
205 |
# First, ensure BaseCache is defined (if needed)
|
206 |
class NoCache(BaseCache):
|
207 |
"""Simple no-op cache implementation."""
|
208 |
-
def __init__(self):
|
209 |
-
|
210 |
-
|
211 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
|
213 |
# Call model_rebuild() before initializing
|
214 |
ChatGroq.model_rebuild()
|
215 |
-
|
216 |
# Then initialize the model
|
217 |
fallback_groq_api_key = os.environ.get("GROQ_API_KEY_FALLBACK", os.environ.get("GROQ_API_KEY"))
|
218 |
groq_fallback_llm = ChatGroq(
|
@@ -220,10 +223,9 @@ try:
|
|
220 |
temperature=0.7,
|
221 |
groq_api_key=fallback_groq_api_key,
|
222 |
max_tokens=2048,
|
223 |
-
|
224 |
)
|
225 |
-
|
226 |
-
|
227 |
except Exception as e:
|
228 |
logger.error(f"Failed to initialize ChatGroq: {e}")
|
229 |
raise RuntimeError("ChatGroq initialization failed.") from e
|
|
|
191 |
# logger.error(f"Failed to initialize ChatGroq: {e}")
|
192 |
# raise RuntimeError("ChatGroq initialization failed.") from e
|
193 |
|
|
|
194 |
|
195 |
from langchain_core.callbacks import CallbackManager
|
196 |
from langchain_core.callbacks.base import BaseCallbackHandler
|
197 |
+
from langchain_core.caches import BaseCache
|
|
|
|
|
|
|
198 |
|
199 |
# Initialize ChatGroq with the callback manager
|
200 |
try:
|
201 |
# First, ensure BaseCache is defined (if needed)
|
202 |
class NoCache(BaseCache):
|
203 |
"""Simple no-op cache implementation."""
|
204 |
+
def __init__(self):
|
205 |
+
pass
|
206 |
+
|
207 |
+
def lookup(self, prompt, llm_string):
|
208 |
+
return None
|
209 |
+
|
210 |
+
def update(self, prompt, llm_string, return_val):
|
211 |
+
pass
|
212 |
+
|
213 |
+
def clear(self):
|
214 |
+
pass
|
215 |
|
216 |
# Call model_rebuild() before initializing
|
217 |
ChatGroq.model_rebuild()
|
218 |
+
|
219 |
# Then initialize the model
|
220 |
fallback_groq_api_key = os.environ.get("GROQ_API_KEY_FALLBACK", os.environ.get("GROQ_API_KEY"))
|
221 |
groq_fallback_llm = ChatGroq(
|
|
|
223 |
temperature=0.7,
|
224 |
groq_api_key=fallback_groq_api_key,
|
225 |
max_tokens=2048,
|
226 |
+
callback_manager=CallbackManager([]) # Use CallbackManager instead of raw list
|
227 |
)
|
228 |
+
|
|
|
229 |
except Exception as e:
|
230 |
logger.error(f"Failed to initialize ChatGroq: {e}")
|
231 |
raise RuntimeError("ChatGroq initialization failed.") from e
|