Spaces:
Runtime error
Runtime error
from langchain_openai import OpenAIEmbeddings, ChatOpenAI | |
from qdrant_client import QdrantClient | |
def setup_openai_embeddings(api_key): | |
"""Set up OpenAI embeddings.""" | |
return OpenAIEmbeddings(model='text-embedding-3-small', openai_api_key=api_key) | |
def setup_qdrant_client(url, api_key): | |
"""Set up Qdrant client.""" | |
return QdrantClient(location=url, api_key=api_key) | |
def format_document_metadata(docs): | |
"""Format metadata for each document.""" | |
formatted_docs = [] | |
for doc in docs: | |
metadata_str = ', '.join(f"{key}: {value}" for key, value in doc.metadata.items()) | |
doc_str = f"{doc.page_content}\nMetadata: {metadata_str}" | |
formatted_docs.append(doc_str) | |
return "\n\n".join(formatted_docs) | |
def openai_llm(api_key: str): | |
"""Get a configured OpenAI language model.""" | |
return ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0, openai_api_key=api_key) | |
def delete_collection(collection_name, qdrant_url, qdrant_api_key): | |
"""Delete a Qdrant collection.""" | |
client = setup_qdrant_client(qdrant_url, qdrant_api_key) | |
try: | |
client.delete_collection(collection_name=collection_name) | |
except Exception as e: | |
print("Failed to delete collection:", e) | |
def is_document_embedded(filename): | |
"""Check if a document is already embedded. Actual implementation needed.""" | |
return False |