diff --git a/local_setup/quickstart_ingestion_server.py b/local_setup/quickstart_ingestion_server.py index 592294dc..dfda2d6a 100644 --- a/local_setup/quickstart_ingestion_server.py +++ b/local_setup/quickstart_ingestion_server.py @@ -66,4 +66,50 @@ async def rag_retrive(query: str, rag_id: str, index: str) -> list: """ docs = await rag_factory.retrieve_query(rag_name=rag_id, index=index, query=query) send_filter = [{"text": node.text, "score": node.score} for node in docs] - return send_filter \ No newline at end of file + return send_filter + +@app.post("/make-rag") +async def make_rag( + file: UploadFile = File(...), + config: str = Form(...) +) -> Dict[str, Any]: + """ + Create a RAG configuration, return its ID, and ingest the uploaded file. + + Args: + file (UploadFile): The file to upload and ingest. + config (str): The RAG configuration as a JSON string. + + Returns: + Dict[str, Any]: A dictionary containing the created RAG ID, upload status, and index. + """ + try: + # Parse the JSON string into a RAGConfig object + rag_config = RAGConfig.parse_raw(config) + + # Create RAG configuration + rag_id = rag_factory.make_rag(rag_config) + + # Ingest the file + task = await rag_factory.file_ingest(rag_name=rag_id, file=file) + + return { + "rag_id": rag_id, + "index": task._index, + "status": task._status, + "message": "RAG created and file ingested successfully" + } + except json.JSONDecodeError: + return { + "rag_id": None, + "index": None, + "status": "ERROR", + "message": "Invalid JSON in config parameter" + } + except Exception as e: + return { + "rag_id": None, + "index": None, + "status": "ERROR", + "message": f"Error creating RAG or ingesting file: {str(e)}" + } \ No newline at end of file