Spaces:
Build error
Build error
added noops cache
Browse files- pipeline.py +32 -4
pipeline.py
CHANGED
|
@@ -173,15 +173,43 @@ CACHE_SIZE_LIMIT = 1000
|
|
| 173 |
# max_retries=2,
|
| 174 |
# )
|
| 175 |
|
| 176 |
-
# Fallback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
fallback_groq_api_key = os.environ.get("GROQ_API_KEY_FALLBACK", "GROQ_API_KEY")
|
| 178 |
-
|
| 179 |
-
# Attempt to initialize ChatGroq without a cache
|
| 180 |
try:
|
| 181 |
groq_fallback_llm = ChatGroq(
|
| 182 |
model=GROQ_MODELS["default"],
|
| 183 |
temperature=0.7,
|
| 184 |
-
|
| 185 |
max_tokens=2048
|
| 186 |
)
|
| 187 |
except Exception as e:
|
|
|
|
| 173 |
# max_retries=2,
|
| 174 |
# )
|
| 175 |
|
| 176 |
+
# # Fallback
|
| 177 |
+
# fallback_groq_api_key = os.environ.get("GROQ_API_KEY_FALLBACK", "GROQ_API_KEY")
|
| 178 |
+
|
| 179 |
+
# # Attempt to initialize ChatGroq without a cache
|
| 180 |
+
# try:
|
| 181 |
+
# groq_fallback_llm = ChatGroq(
|
| 182 |
+
# model=GROQ_MODELS["default"],
|
| 183 |
+
# temperature=0.7,
|
| 184 |
+
# # groq_api_key=fallback_groq_api_key,
|
| 185 |
+
# max_tokens=2048
|
| 186 |
+
# )
|
| 187 |
+
# except Exception as e:
|
| 188 |
+
# logger.error(f"Failed to initialize ChatGroq: {e}")
|
| 189 |
+
# raise RuntimeError("ChatGroq initialization failed.") from e
|
| 190 |
+
from langchain.cache import BaseCache
|
| 191 |
+
|
| 192 |
+
# Define a no-op cache that does nothing
|
| 193 |
+
class NoOpCache(BaseCache):
|
| 194 |
+
def lookup(self, key: str):
|
| 195 |
+
return None # Always return None, meaning no cache hit
|
| 196 |
+
|
| 197 |
+
def update(self, key: str, value: str):
|
| 198 |
+
pass # Do nothing on cache update
|
| 199 |
+
|
| 200 |
+
# Assign the no-op cache to ChatGroq
|
| 201 |
+
ChatGroq.cache = NoOpCache()
|
| 202 |
+
|
| 203 |
+
# Rebuild the ChatGroq model to finalize its definition
|
| 204 |
+
ChatGroq.model_rebuild()
|
| 205 |
+
|
| 206 |
+
# Initialize ChatGroq without using caching
|
| 207 |
fallback_groq_api_key = os.environ.get("GROQ_API_KEY_FALLBACK", "GROQ_API_KEY")
|
|
|
|
|
|
|
| 208 |
try:
|
| 209 |
groq_fallback_llm = ChatGroq(
|
| 210 |
model=GROQ_MODELS["default"],
|
| 211 |
temperature=0.7,
|
| 212 |
+
groq_api_key=fallback_groq_api_key,
|
| 213 |
max_tokens=2048
|
| 214 |
)
|
| 215 |
except Exception as e:
|