{"id":21457810,"url":"https://github.com/rjjha/chatpdf--backend","last_synced_at":"2026-05-16T17:05:09.418Z","repository":{"id":263246116,"uuid":"889765504","full_name":"Rjjha/ChatPdf--Backend","owner":"Rjjha","description":"A full-stack app for querying and uploading PDFs using OpenAI's RAG system. Built with React, FastAPI, and MongoDB, it ensures seamless interaction and intelligent PDF-based responses.","archived":false,"fork":false,"pushed_at":"2024-11-17T10:00:27.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T04:59:34.113Z","etag":null,"topics":["fastapi","gemini-api","python3"],"latest_commit_sha":null,"homepage":"https://chatpdf-backend-dxuh.onrender.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rjjha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-17T07:02:28.000Z","updated_at":"2024-11-17T10:00:30.000Z","dependencies_parsed_at":"2024-11-17T09:29:10.174Z","dependency_job_id":"e9b35634-08cf-439f-81bd-86004b98ad67","html_url":"https://github.com/Rjjha/ChatPdf--Backend","commit_stats":null,"previous_names":["rjjha/chatpdf--backend"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Rjjha/ChatPdf--Backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rjjha%2FChatPdf--Backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rjjha%2FChatPdf--Backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rjjha%2FChatPdf--Backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rjjha%2FChatPdf--Backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rjjha","download_url":"https://codeload.github.com/Rjjha/ChatPdf--Backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rjjha%2FChatPdf--Backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33111497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","gemini-api","python3"],"created_at":"2024-11-23T06:07:11.418Z","updated_at":"2026-05-16T17:05:09.380Z","avatar_url":"https://github.com/Rjjha.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# ChatPdf\n**PDF Query Assistant**  \nA full-stack application enabling users to query and upload PDF files, leveraging a Retrieval-Augmented Generation (RAG) system with OpenAI’s API. Built with a React frontend, FastAPI backend, and MongoDB for query history storage, it provides seamless interaction and intelligent responses based on PDF content.\n\n## Features\n---\n1. **Upload PDF**: Users can upload a PDF file through an intuitive interface to enable the system to process its content.\n\n2. **Input Query**: Users can type in their questions related to the uploaded PDF directly in the query box on the frontend.\n\n3. **Receive Responses**: The application retrieves relevant information from the PDF using the RAG system and OpenAI’s API, providing accurate and contextual answers.\n\n4. **Query History**: Users can view past queries and responses stored in MongoDB for reference, ensuring continuity and easy access to previously searched information.\n\n----\n\n# Backend Setup Guide\n\nFollow these steps to set up and run the backend for your project.\n\n## Prerequisites\n\n- Python 3.7+ installed\n- pip (Python package installer)\n\n---\n\n## Steps to Start\n\n1. **Install `virtualenv`**  \n   ```bash\n   pip install virtualenv\n   ```\n\n2. **Create a Virtual Environment**  \n   ```bash\n   python3 -m venv venv\n   ```\n\n3. **Activate the Virtual Environment**  \n   - **Linux/macOS**:  \n     ```bash\n     source venv/bin/activate\n     ```\n   - **Windows**:  \n     ```bash\n     venv\\Scripts\\activate\n     ```\n\n4. **Install Dependencies**  \n   ```bash\n   pip install -r requirements.txt\n   ```\n\n5. **Run the Backend Server**  \n   ```bash\n   uvicorn app.main:app --reload\n   ```\n\n---\n\n## Access the Application\n\n- Open your browser and go to:  \n  `http://127.0.0.1:8000`\n\n---\n\n## Notes\n\n- Use `CTRL+C` to stop the server.\n- To deactivate the virtual environment, run:  \n  ```bash\n  deactivate\n  ```\n\n# API Documentation\n\n## 1. Root Endpoint\n\n### GET `/`\n\n**Description**:  \nRoot endpoint to check the status of the service.\n\n### Responses:\n- **200 OK**  \n  Returns the root status.\n\n---\n\n## 2. Upload PDF\n\n### POST `/api/v1/upload_pdf`\n\n**Description**:  \nUploads a PDF to the server and processes it.\n\n### Parameters:\n- **None**  \n\n### Request Body:\n- **Content-Type**: `multipart/form-data`\n- **File**: \n  - **Field Name**: `file`\n  - **Type**: `string($binary)`\n  - **Example File**: `Abhisahar Article - Open Src.pdf`\n\n### Example cURL Request:\n```bash\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/api/v1/upload_pdf' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: multipart/form-data' \\\n  -F 'file=@Abhisahar Article - Open Src.pdf;type=application/pdf'\n```\n\n### Responses:\n\n#### 200 OK\n- **Description**: PDF uploaded and processed successfully.\n- **Response Body**:\n```json\n{\n  \"status\": \"success\",\n  \"message\": \"PDF 'Abhisahar Article - Open Src.pdf' uploaded and processed successfully.\",\n  \"data\": {\n    \"pdf_id\": \"67385818c013d1176861687e\",\n    \"pdf_metadata\": {\n      \"id\": \"67385818c013d1176861687e\",\n      \"filename\": \"Abhisahar Article - Open Src.pdf\",\n      \"cloudinary_url\": \"https://res.cloudinary.com/dnu3aojdm/raw/upload/v1731745816/mxvdhu1nxgxtynjdecbw\",\n      \"cloudinary_public_id\": \"mxvdhu1nxgxtynjdecbw\",\n      \"file_size\": 64475,\n      \"created_at\": \"2024-11-16T08:30:16\",\n      \"format\": \"pdf\"\n    }\n  }\n}\n```\n\n#### 422 Unprocessable Entity\n- **Description**: Validation error, typically due to missing or invalid parameters.\n- **Response Body**:\n```json\n{\n  \"detail\": [\n    {\n      \"loc\": [\"body\", \"file\"],\n      \"msg\": \"Field required\",\n      \"type\": \"value_error.missing\"\n    }\n  ]\n}\n```\n\n---\n\n## 3. List Uploaded PDFs\n\n### GET `/api/v1/pdfs`\n\n**Description**:  \nRetrieves a list of uploaded PDFs with pagination support.\n\n### Parameters:\n- **skip**: `integer` (query) - Offset for pagination (default: 0).\n- **limit**: `integer` (query) - Number of records to fetch (default: 10).\n\n### Example cURL Request:\n```bash\ncurl -X 'GET' \\\n  'http://127.0.0.1:8000/api/v1/pdfs?skip=0\u0026limit=10' \\\n  -H 'accept: application/json'\n```\n\n### Responses:\n\n#### 200 OK\n- **Description**: Successfully retrieves the list of PDFs.\n- **Response Body**:\n```json\n[\n  {\n    \"id\": \"67385818c013d1176861687e\",\n    \"filename\": \"Abhisahar Article - Open Src.pdf\",\n    \"cloudinary_url\": \"https://res.cloudinary.com/dnu3aojdm/raw/upload/v1731745816/mxvdhu1nxgxtynjdecbw\",\n    \"cloudinary_public_id\": \"mxvdhu1nxgxtynjdecbw\",\n    \"file_size\": 64475,\n    \"created_at\": \"2024-11-16T08:30:16\",\n    \"format\": \"pdf\"\n  },\n  ...\n]\n```\n\n#### 422 Unprocessable Entity\n- **Description**: Validation error for request parameters.\n- **Response Body**:\n```json\n{\n  \"detail\": [\n    {\n      \"loc\": [\"query\", \"limit\"],\n      \"msg\": \"Value is too large\",\n      \"type\": \"value_error.max_size\"\n    }\n  ]\n}\n```\n\n---\n\n## 4. Delete PDF\n\n### DELETE `/api/v1/pdfs/{pdf_id}`\n\n**Description**:  \nDeletes a PDF from both Cloudinary and the database.\n\n### Parameters:\n- **pdf_id**: `string` (path) - The unique identifier of the PDF to be deleted.\n\n### Example cURL Request:\n```bash\ncurl -X 'DELETE' \\\n  'http://127.0.0.1:8000/api/v1/pdfs/673793c2fcf059dc08dcc4d2' \\\n  -H 'accept: application/json'\n```\n\n### Responses:\n\n#### 200 OK\n- **Description**: Successfully deleted the PDF.\n- **Response Body**:\n```json\n{\n  \"status\": \"success\",\n  \"message\": \"PDF deleted successfully\",\n  \"pdf_id\": \"673793c2fcf059dc08dcc4d2\"\n}\n```\n\n#### 422 Unprocessable Entity\n- **Description**: Validation error, typically due to an invalid `pdf_id`.\n- **Response Body**:\n```json\n{\n  \"detail\": [\n    {\n      \"loc\": [\"path\", \"pdf_id\"],\n      \"msg\": \"Invalid PDF ID\",\n      \"type\": \"value_error\"\n    }\n  ]\n}\n```\n\n---\n\n## 5. Query PDF\n\n### POST `/api/v1/query`\n\n**Description**:  \nQueries a PDF with a specific question.\n\n### Parameters:\n- **pdf_id**: `string` (body) - The ID of the PDF to query.\n- **query**: `string` (body) - The question to ask the PDF.\n\n### Request Body:\n```json\n{\n  \"pdf_id\": \"67385818c013d1176861687e\",\n  \"query\": \"what is the topic?\"\n}\n```\n\n### Example cURL Request:\n```bash\ncurl -X 'POST' \\\n  'http://127.0.0.1:8000/api/v1/query' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"pdf_id\": \"67385818c013d1176861687e\",\n    \"query\": \"what is the topic?\"\n  }'\n```\n\n### Responses:\n\n#### 200 OK\n- **Description**: Successfully queries the PDF.\n- **Response Body**:\n```json\n{\n  \"id\": \"6738587ac013d1176861687f\",\n  \"pdf_id\": \"67385818c013d1176861687e\",\n  \"query\": \"what is the topic?\",\n  \"response\": \"Open source software development\",\n  \"created_at\": \"2024-11-16T08:31:54.333289\"\n}\n```\n\n#### 422 Unprocessable Entity\n- **Description**: Validation error for request parameters.\n- **Response Body**:\n```json\n{\n  \"detail\": [\n    {\n      \"loc\": [\"body\", \"query\"],\n      \"msg\": \"Query is required\",\n      \"type\": \"value_error.missing\"\n    }\n  ]\n}\n```\n### 6. Query History\n\n**GET** `/api/v1/history/{pdf_id}`\n\n**Description:**  \nRetrieves the query history for a specific PDF.\n\n**Parameters:**  \n- `pdf_id` (string, path) - The ID of the PDF.  \n- `skip` (integer, query) - Offset for pagination (default: 0).  \n- `limit` (integer, query) - Number of records to fetch (default: 10).  \n\n**Responses:**  \n- **200 OK:**  \n  - **Description:** Successfully retrieves the query history.  \n  - **Response Body:**  \n    ```json\n    [\n      {\n        \"id\": \"6738587ac013d1176861687f\",\n        \"pdf_id\": \"67385818c013d1176861687e\",\n        \"query\": \"what is the topic?\",\n        \"response\": \"Open source software development\",\n        \"created_at\": \"2024-11-16T08:31:54.333289\"\n      },\n      {\n        \"id\": \"67375818c013d1176861688a\",\n        \"pdf_id\": \"67385818c013d1176861687e\",\n        \"query\": \"Who contributed to the document?\",\n        \"response\": \"John Doe and Jane Smith\",\n        \"created_at\": \"2024-11-16T09:10:23.123456\"\n      }\n    ]\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjjha%2Fchatpdf--backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjjha%2Fchatpdf--backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjjha%2Fchatpdf--backend/lists"}