Spaces:
Sleeping
Sleeping
Update rag_api.py
Browse files- rag_api.py +4 -5
rag_api.py
CHANGED
|
@@ -7,9 +7,8 @@ from pydantic import BaseModel
|
|
| 7 |
from langchain_huggingface import HuggingFaceEmbeddings
|
| 8 |
# from langchain_community.chains import RetrievalQA
|
| 9 |
# from langchain.schema.runnable import RunnablePassthrough
|
| 10 |
-
#from langchain.prompts import PromptTemplate
|
| 11 |
from langchain_core.runnables import RunnablePassthrough
|
| 12 |
-
from
|
| 13 |
from langchain_groq import ChatGroq
|
| 14 |
|
| 15 |
|
|
@@ -133,7 +132,7 @@ def load_and_configure_rag():
|
|
| 133 |
| RAG_PROMPT
|
| 134 |
| llm_groq
|
| 135 |
)
|
| 136 |
-
return qa_chain
|
| 137 |
|
| 138 |
except Exception as e:
|
| 139 |
# Imprime un mensaje de error claro en los logs
|
|
@@ -153,9 +152,9 @@ app = FastAPI(title="NutriActive RAG API")
|
|
| 153 |
qa_chain = None # Inicializamos a None
|
| 154 |
|
| 155 |
try:
|
| 156 |
-
qa_chain = load_and_configure_rag()
|
| 157 |
except RuntimeError:
|
| 158 |
-
# Si
|
| 159 |
# y el endpoint / lo reportará. No es necesario hacer nada más aquí.
|
| 160 |
pass
|
| 161 |
|
|
|
|
| 7 |
from langchain_huggingface import HuggingFaceEmbeddings
|
| 8 |
# from langchain_community.chains import RetrievalQA
|
| 9 |
# from langchain.schema.runnable import RunnablePassthrough
|
|
|
|
| 10 |
from langchain_core.runnables import RunnablePassthrough
|
| 11 |
+
from langchain.prompts import PromptTemplate
|
| 12 |
from langchain_groq import ChatGroq
|
| 13 |
|
| 14 |
|
|
|
|
| 132 |
| RAG_PROMPT
|
| 133 |
| llm_groq
|
| 134 |
)
|
| 135 |
+
return qa_chain,retriever
|
| 136 |
|
| 137 |
except Exception as e:
|
| 138 |
# Imprime un mensaje de error claro en los logs
|
|
|
|
| 152 |
qa_chain = None # Inicializamos a None
|
| 153 |
|
| 154 |
try:
|
| 155 |
+
qa_chain,retriever = load_and_configure_rag()
|
| 156 |
except RuntimeError:
|
| 157 |
+
# Si load,_and_configure_rag falla con RuntimeError, qa_chain se queda en None,
|
| 158 |
# y el endpoint / lo reportará. No es necesario hacer nada más aquí.
|
| 159 |
pass
|
| 160 |
|