Spaces:
Running
Running
added empty callbacks
Browse files- pipeline.py +4 -16
pipeline.py
CHANGED
@@ -192,33 +192,21 @@ CACHE_SIZE_LIMIT = 1000
|
|
192 |
# raise RuntimeError("ChatGroq initialization failed.") from e
|
193 |
|
194 |
|
|
|
|
|
195 |
|
196 |
-
# Define a no-op callback handler
|
197 |
-
class NoOpCallbacks(BaseCallbacks):
|
198 |
-
"""No-op callback handler."""
|
199 |
-
def on_llm_start(self, *args, **kwargs): pass
|
200 |
-
def on_llm_end(self, *args, **kwargs): pass
|
201 |
-
def on_llm_error(self, *args, **kwargs): pass
|
202 |
-
def on_chain_start(self, *args, **kwargs): pass
|
203 |
-
def on_chain_end(self, *args, **kwargs): pass
|
204 |
-
def on_chain_error(self, *args, **kwargs): pass
|
205 |
-
|
206 |
-
# Create a callback manager with no-op callbacks
|
207 |
-
callback_manager = CallbackManager([StdOutCallbackHandler()])
|
208 |
|
209 |
# Initialize ChatGroq with the callback manager
|
210 |
try:
|
211 |
-
fallback_groq_api_key = os.environ.get("GROQ_API_KEY_FALLBACK", "GROQ_API_KEY")
|
212 |
groq_fallback_llm = ChatGroq(
|
213 |
model=GROQ_MODELS["default"],
|
214 |
temperature=0.7,
|
215 |
groq_api_key=fallback_groq_api_key,
|
216 |
max_tokens=2048,
|
217 |
-
|
218 |
)
|
219 |
|
220 |
-
# Rebuild the model after initialization
|
221 |
-
ChatGroq.model_rebuild()
|
222 |
|
223 |
except Exception as e:
|
224 |
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
# Initialize ChatGroq with the callback manager
|
200 |
try:
|
201 |
+
fallback_groq_api_key = os.environ.get("GROQ_API_KEY_FALLBACK", os.environ.get("GROQ_API_KEY"))
|
202 |
groq_fallback_llm = ChatGroq(
|
203 |
model=GROQ_MODELS["default"],
|
204 |
temperature=0.7,
|
205 |
groq_api_key=fallback_groq_api_key,
|
206 |
max_tokens=2048,
|
207 |
+
callback_manager=CallbackManager([]) # Add the callback manager here
|
208 |
)
|
209 |
|
|
|
|
|
210 |
|
211 |
except Exception as e:
|
212 |
logger.error(f"Failed to initialize ChatGroq: {e}")
|