AI Personal Learning
and practical guidance

FastAPI DocGPT: FastAPI-based PDF document processing and Q&A system

General Introduction

FastAPI DocGPT is a FastAPI-based document quiz system that allows users to upload PDF files and quiz them based on the document content. The system uses OpenAI's embedding technology to embed document content into a vector database, Qdrant, to realize the intelligent Q&A function. Users can upload documents and ask questions through the API interface, and the system will return intelligent answers based on the document content.

 

Function List

  • PDF Upload: Users can upload PDF files, which are processed and stored in the vector database.
  • question and answer system: Users can ask questions based on the uploaded PDF content and the system will return intelligent answers.
  • API Documentation: Provides auto-generated API documentation through Swagger for developers' convenience.
  • Cross-domain resource sharing: Supports CORS, allowing front-end requests from different domains.

 

Using Help

Installation and Setup

  1. clone warehouse
    git clone https://github.com/shaheryaryousaf/fastapi-docgpt
    cd fastapi-docgpt
    
  2. Setting up a virtual environment
    python3 -m venv venv
    source venv/bin/activate # Windows: venv\Scripts\activate
    
  3. Installation of dependencies
    pip install -r requirements.txt
    
  4. Configuring Environment Variables In the project root directory, create the .env file and add API keys for OpenAI and Qdrant:
    OPENAI_API_KEY=your-openai-api-key
    QDRANT_URL=your-qdrant-url
    QDRANT_API_KEY=your-qdrant-api-key
    

Guidelines for use

  1. Launching the FastAPI application
    uvicorn app:app --reload
    

    This will start the FastAPI application with the http://127.0.0.1:8000 Provision of services.

  2. Upload PDF files pass (a bill or inspection etc) /upload-pdf/ Endpoints upload PDF files:
    curl -X POST "http://127.0.0.1:8000/upload-pdf/" -F "file=@yourfile.pdf"
    

    The system processes the PDF file and embeds its contents into the vector database.

  3. put pass (a bill or inspection etc) /ask-question/ Endpoints raise questions:
    curl -X POST "http://127.0.0.1:8000/ask-question/" -H "Content-Type: application/json" -d '{"question": "your question"}'
    

    The system returns intelligent answers based on the content of the document.

Project structure

  • app.py: The main FastAPI application file containing the API endpoints for the PDF upload and Q&A system.
  • utils.py: Contains utility functions for processing PDF files, sending embeddings to vector databases, and retrieving answers from embeddings.
  • .env File: Manages API keys for OpenAI and Qdrant.

dependency library (computing)

  • FastAPI: Used to build Web APIs.
  • Qdrant Client: Used to store and retrieve document embeds.
  • LangChain: For processing PDF and embedding.
  • OpenAI: for generating embeddings and AI model responses.
  • PyPDFLoader: Used to extract text from PDF files.
  • CORS Middleware: Handles cross-domain resource sharing (CORS), allowing front-end requests from different domains.
  • dotenv: Manage environment variables (such as API keys).

AI Easy Learning

The layman's guide to getting started with AI

Help you learn how to utilize AI tools at a low cost and from a zero base.AI, like office software, is an essential skill for everyone. Mastering AI will give you an edge in your job search and half the effort in your future work and studies.

View Details>
May not be reproduced without permission:Chief AI Sharing Circle " FastAPI DocGPT: FastAPI-based PDF document processing and Q&A system

Chief AI Sharing Circle

Chief AI Sharing Circle specializes in AI learning, providing comprehensive AI learning content, AI tools and hands-on guidance. Our goal is to help users master AI technology and explore the unlimited potential of AI together through high-quality content and practical experience sharing. Whether you are an AI beginner or a senior expert, this is the ideal place for you to gain knowledge, improve your skills and realize innovation.

Contact Us
en_USEnglish