Spaces:
Runtime error
Runtime error
Update retrieve.py
Browse files- retrieve.py +16 -2
retrieve.py
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
|
|
| 1 |
from langchain_community.vectorstores import Qdrant
|
| 2 |
from langchain_core.output_parsers import StrOutputParser
|
| 3 |
from langchain_core.runnables import RunnablePassthrough
|
| 4 |
from langchain.prompts import PromptTemplate
|
| 5 |
from utils import setup_openai_embeddings,setup_qdrant_client,openai_llm,format_document_metadata
|
|
|
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def retrieve_documents(query, api_key, qdrant_url, qdrant_api_key):
|
|
@@ -41,7 +54,8 @@ def retrieve_documents(query, api_key, qdrant_url, qdrant_api_key):
|
|
| 41 |
| llm
|
| 42 |
| StrOutputParser()
|
| 43 |
)
|
| 44 |
-
return rag_chain.invoke(query)
|
|
|
|
| 45 |
|
| 46 |
def retrieve_documents_from_collection(query, api_key, qdrant_url, qdrant_api_key, collection_name):
|
| 47 |
"""Retrieve documents based on the specified query from a specific collection."""
|
|
@@ -78,7 +92,7 @@ def retrieve_documents_from_collection(query, api_key, qdrant_url, qdrant_api_ke
|
|
| 78 |
| llm
|
| 79 |
| StrOutputParser()
|
| 80 |
)
|
| 81 |
-
return rag_chain.invoke(query)
|
| 82 |
|
| 83 |
def delete_collection(collection_name, qdrant_url, qdrant_api_key):
|
| 84 |
"""Delete a Qdrant collection."""
|
|
|
|
| 1 |
+
import os
|
| 2 |
from langchain_community.vectorstores import Qdrant
|
| 3 |
from langchain_core.output_parsers import StrOutputParser
|
| 4 |
from langchain_core.runnables import RunnablePassthrough
|
| 5 |
from langchain.prompts import PromptTemplate
|
| 6 |
from utils import setup_openai_embeddings,setup_qdrant_client,openai_llm,format_document_metadata
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
from langfuse.callback import CallbackHandler
|
| 9 |
+
load_dotenv()
|
| 10 |
|
| 11 |
+
os.environ["LANGFUSE_PUBLIC_KEY"] = os.getenv("LANGFUSE_PUBLIC_KEY")
|
| 12 |
+
os.environ["LANGFUSE_SECRET_KEY"] = os.getenv("LANGFUSE_SECRET_KEY")
|
| 13 |
+
os.environ["LANGFUSE_HOST"] = os.getenv("LANGFUSE_HOST")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
langfuse_handler = CallbackHandler()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
|
| 21 |
|
| 22 |
def retrieve_documents(query, api_key, qdrant_url, qdrant_api_key):
|
|
|
|
| 54 |
| llm
|
| 55 |
| StrOutputParser()
|
| 56 |
)
|
| 57 |
+
return rag_chain.invoke(query,{"callbacks":[langfuse_handler]})
|
| 58 |
+
|
| 59 |
|
| 60 |
def retrieve_documents_from_collection(query, api_key, qdrant_url, qdrant_api_key, collection_name):
|
| 61 |
"""Retrieve documents based on the specified query from a specific collection."""
|
|
|
|
| 92 |
| llm
|
| 93 |
| StrOutputParser()
|
| 94 |
)
|
| 95 |
+
return rag_chain.invoke(query,{"callbacks":[langfuse_handler]})
|
| 96 |
|
| 97 |
def delete_collection(collection_name, qdrant_url, qdrant_api_key):
|
| 98 |
"""Delete a Qdrant collection."""
|