Asaad Almutareb
cleaned branch, added final streaming callback handler
fa99d8f
raw
history blame contribute delete
936 Bytes
from fastapi import APIRouter
from app.utils.utils import extract_urls
from app.utils import logger
from app.vector_store import initialize_chroma_db
from app.utils.utils import (
generate_uuid
)
from langchain_community.vectorstores import Chroma
router = APIRouter()
@router.post("/add-document", status_code=201)
async def add_document(conversation):
db = initialize_chroma_db()
all_sources = conversation.sources
documents = conversation.documents
message = conversation.query
sources = extract_urls(all_sources)
src_list = '\n'.join(sources)
current_id = generate_uuid()
db.add(
ids=[current_id],
documents=documents,
metadatas=[
{
"human_message":message,
"sources": 'Internal Knowledge Base From: \n\n' + src_list
}
]
)
return {"message": "Document added successfully", "ids": current_id}