Code Monkey home page Code Monkey logo

freestate / chat_with_your_docs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jorge-armando-navarro-flores/chat_with_your_docs

0.0 0.0 0.0 10.31 MB

Discover and converse with advanced AI models like Mistral, LLAMA2, and GPT-3.5 from leading sources like OLLAMA, Hugging Face, and OpenAI. Easily extract insights from PDFs, web pages, and YouTube videos with our intuitive interface. Unlock the power of knowledge with seamless chat interactions.

License: MIT License

Python 100.00%

chat_with_your_docs's Introduction

Chat With Your Docs

Introduction


The ChatWithYourDocs Chat App is a Python application that allows you to chat with multiple Docs formats like PDF, WEB pages and YouTube videos. You can ask questions about the PDFs using natural language, and the application will provide relevant responses based on the content of the documents. This app utilizes a language model to generate accurate answers to your queries. Please note that the app will only respond to questions related to the loaded Docs.

How It Works


ChatWithYourDocs Chat App Diagram

The application follows these steps to provide responses to your questions:

  1. Doc Loading: The app reads multiple PDF Docs types and extracts their text content.

  2. Text Chunking: The extracted text is divided into smaller chunks that can be processed effectively.

  3. Language Model: The application utilizes a language model to generate vector representations (embeddings) of the text chunks.

  4. Similarity Matching: When you ask a question, the app compares it with the text chunks and identifies the most semantically similar ones.

  5. Response Generation: The selected chunks are passed to the language model, which generates a response based on the relevant content of the PDFs.

Dependencies and Installation


To install the Chat With PDF App, please follow these steps:

  1. Download Ollama library

    curl https://ollama.ai/install.sh | sh
    
  2. pull the chat models we will use, in this case we will use LLAMA2, MISTRAL and GEMMA

    ollama pull llama2
    
    ollama pull mistral
    
    ollama pull gemma
    
  3. Create new environment with python 3.9 and activate it, in this case we will use conda

    conda create -n cwp python=3.9
    
    conda activate cwp
    
  4. Clone the repository to your local machine.

    git clone https://github.com/jorge-armando-navarro-flores/chat_with_your_docs.git
    
    cd chat_with_your_docs
    
  5. Install the required dependencies by running the following command:

    pip install -r requirements.txt
    

Usage


To use the Chat With Your Docs app, follow these steps:

  1. Run the main.py file using the Streamlit CLI. Execute the following command:

    python3 main.py
    
  2. The application will launch in your default web browser, displaying the user interface. ChatWithYourDocs Interface

Architecture

ChatWithYourDocs Interface

Classes:

  • LLM: This abstract class serves as a blueprint for different LLM implementations. It has subclasses like OllamaModel, OpenAIModel, and HFModel that handle specific LLM providers (Ollama, OpenAI, and Hugging Face).
  • Docs: This class manages document loading from various sources like PDFs, web pages, and YouTube videos.
  • VectorStore: This class creates a vector representation of the documents using LLM embeddings for efficient retrieval.
  • Chain: This class defines the processing pipeline for the chatbot. It can be a simple chain for basic question answering or a retrieval chain that searches documents based on the conversation history.
  • ChatBot: This class handles user interaction, maintains conversation history, and calls the appropriate chain method to generate responses.
  • ChatBotController: This class is the main interface for the user. It allows setting the LLM model, document source, and retrieval options. It also handles user queries and interacts with the ChatBot instance.

Functionality:

  1. Setting Up:

    • The user selects the LLM provider (Ollama, OpenAI, or HuggingFace) and model from a dropdown menu. Optionally, an API key might be needed for certain providers.
    • The user can choose to add documents (PDF, web page URL, or YouTube video URL) for retrieval tasks.
  2. Processing:

    • Based on the chosen LLM and documents (if any), the controller configures the processing chain.
    • A simple chain is used for basic question answering without document retrieval.
    • A retrieval chain involves:
      • Creating a vector representation of the documents using the LLM's embeddings.
      • Defining prompts to generate search queries based on the conversation history.
      • Retrieving relevant documents based on the generated queries.
      • Using the retrieved documents to answer the user's question.
  3. Interaction:

    • The user types their questions in the chat interface.
    • The controller calls the predict method of the ChatBot, passing the user's query and conversation history (if retrieval is enabled).
    • The ChatBot retrieves the appropriate response based on the chosen chain configuration.

Additional Features:

  • The interface includes buttons for "Undo" and "Clear" conversation history.

Overall, this code demonstrates a well-structured architecture for a chatbot that can leverage different LLMs and incorporate document retrieval for enhanced capabilities.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.