Spaces:
Sleeping
Sleeping
Update utils/rag_utils.py
Browse files- utils/rag_utils.py +20 -12
utils/rag_utils.py
CHANGED
|
@@ -15,15 +15,23 @@ def process_pdf(file_path: str):
|
|
| 15 |
return splitter.split_text(text)
|
| 16 |
|
| 17 |
def get_groq_response(query, vector_db, model_name="mixtral-8x7b-32768"):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
return splitter.split_text(text)
|
| 16 |
|
| 17 |
def get_groq_response(query, vector_db, model_name="mixtral-8x7b-32768"):
|
| 18 |
+
try:
|
| 19 |
+
# Updated to use current LLaMA3 model (replace with latest from Groq docs)
|
| 20 |
+
llm = ChatGroq(
|
| 21 |
+
temperature=0.1,
|
| 22 |
+
model_name="llama3-70b-8192", # Current recommended model
|
| 23 |
+
max_tokens=2048
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
qa = RetrievalQA.from_chain_type(
|
| 27 |
+
llm=llm,
|
| 28 |
+
chain_type="stuff",
|
| 29 |
+
retriever=vector_db.as_retriever(search_kwargs={"k": 4})
|
| 30 |
+
)
|
| 31 |
+
return qa.run(query)
|
| 32 |
+
except Exception as e:
|
| 33 |
+
# Provide helpful error message
|
| 34 |
+
error_msg = str(e)
|
| 35 |
+
if "model_decommissioned" in error_msg:
|
| 36 |
+
return "Error: Please update the model name in rag_utils.py - check Groq's latest docs"
|
| 37 |
+
return f"Error processing request: {error_msg}"
|