|
| 1 | +# docGPT |
| 2 | + |
| 3 | +[English](./README.md) | [中文版](./README.zh-TW.md) |
| 4 | + |
| 5 | +- Table of Contents |
| 6 | + - [Introduction](#introduction) |
| 7 | + - [What's LangChain?](#whats-langchain) |
| 8 | + - [How to Use docGPT?](#how-to-use-docgpt) |
| 9 | + - [How to Develop a docGPT with Streamlit?](#how-to-develop-a-docgpt-with-streamlit) |
| 10 | + |
| 11 | + |
| 12 | +* Main Development Software and Packages: |
| 13 | + * `Python 3.8.6` |
| 14 | + * `Langchain 0.0.218` |
| 15 | + * `Streamlit 1.22.0` |
| 16 | + |
| 17 | +* Using this tool requires at least the `openai_api_key`. You can visit the [link](https://platform.openai.com/) to learn how to obtain the key. |
| 18 | + |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | + |
| 23 | +### Introduction |
| 24 | + |
| 25 | +* Easily build an AI model using Langchain and Streamlit. |
| 26 | + |
| 27 | +* This project consists of three main components: |
| 28 | + * [`DataConnection`](../model/data_connection.py): Allows LLM to communicate with external data, i.e., read PDF files and perform text segmentation for large PDFs to avoid exceeding OPENAI's 4000-token limit. |
| 29 | + * [`docGPT`](../docGPT/): This component enables the model to understand the content of PDFs. It includes embedding PDF text and building a retrievalQA model using Langchain. For more details, please refer to the [documentation](https://python.langchain.com/docs/modules/chains/popular/vector_db_qa). |
| 30 | + * [`agent`](../agent/agent.py): Responsible for managing the tools used by the model and automatically determining which tool to use based on the user's question. The tools include: |
| 31 | + * `SerpAI`: Used for "**current questions**" by performing a **Google search**. |
| 32 | + * `llm_math_chain`: Used for "**mathematical calculations**" by performing mathematical computations. |
| 33 | + * `docGPT`: Used for answering questions about the content of PDF documents. (This tool is built using retrievalQA) |
| 34 | + |
| 35 | + |
| 36 | +* `docGPT` is developed based on **Langchain** and **Streamlit**. |
| 37 | + * `Langchain`: LangChain is a framework for **developing applications supported by language models**. It supports the following applications: |
| 38 | + 1. Connecting LLM models with external data sources. |
| 39 | + 2. Allowing interaction with LLM models. |
| 40 | + * `Streamlit`: Streamlit enables fast and free deployment of Python applications. |
| 41 | + |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +### What's LangChain? |
| 46 | + |
| 47 | +For an introduction to LangChain, it is recommended to refer to the official documentation or the GitHub [repository](https://github.com/hwchase17/langchain). |
| 48 | + |
| 49 | +**Questions that ChatGPT cannot answer can be handled by Langchain!** |
| 50 | + |
| 51 | +Here, the author briefly introduces the differences between Langchain and ChatGPT. You will be amazed by this open-source project called Langchain through the following example! |
| 52 | + |
| 53 | +> Imagine a scenario where ChatGPT cannot answer mathematical questions or questions about events beyond 2020 (e.g., "Who will be the president in 2023?"). |
| 54 | +> |
| 55 | +> * For mathematical questions: In addition to the OpenAI model, there is a specialized tool called math-llm that handles mathematical questions. |
| 56 | +> * For current questions: We can use Google search. |
| 57 | +> |
| 58 | +> Therefore, to design a powerful and versatile AI model, we need to include three tools: "chatgpt", "math-llm", and "Google search". |
| 59 | +> |
| 60 | +> If the user's question involves mathematical calculations, we use the math-llm tool to handle and answer it. |
| 61 | +> |
| 62 | +> In the non-AI era, we would use `if...else...` to decide which tool to use based on the user's question. However, Langchain provides a more flexible and powerful way to handle this. |
| 63 | +> In the AI era, we want users to directly ask their questions without having to pre-select the question type! In Langchain, there is a concept called "agent" that allows us to: |
| 64 | +
|
| 65 | +* Provide tools for the agent to manage, such as `tools = ['chatgpt', 'math-llm', 'google-search']`. |
| 66 | +* Include chains designed using Langchain, such as using the `retrievalQA chain` to create a question-answering model based on document content, and append this chain to the tools managed by the agent. |
| 67 | +* **Allow the agent to determine which tool to use based on the user's question** (fully automated and AI-driven). |
| 68 | + |
| 69 | +With Langchain, we can create our own ChatGPT model that can be general-purpose or tailored for specific industries and commercial use! |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### How to Use docGPT? |
| 74 | + |
| 75 | +* Visit the [application](https://docgpt-app.streamlit.app/). |
| 76 | + |
| 77 | +* Enter your API keys: |
| 78 | + * `OpenAI API Key`: Required. |
| 79 | + * `SERPAPI API Key`: Optional. If you want to ask questions about content not appearing in the PDF document, you need this key. |
| 80 | + |
| 81 | +* Upload a PDF file from your local machine. |
| 82 | +* Start asking questions! |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +### How to Develop a docGPT with Streamlit? |
| 89 | + |
| 90 | +A step-by-step tutorial to quickly build your own chatGPT! |
| 91 | + |
| 92 | +First, clone the repository using `git clone https://github.com/Lin-jun-xiang/docGPT-streamlit.git`. |
| 93 | + |
| 94 | +There are two methods: |
| 95 | + |
| 96 | +* Local development: |
| 97 | + * `pip install -r requirements.txt`: Download the required packages for development. |
| 98 | + * `streamlit run ./app.py`: Start the service in the project's root directory. |
| 99 | + * Start exploring! |
| 100 | + |
| 101 | +* Use Streamlit Community Cloud for free deployment, management, and sharing of applications: |
| 102 | + * Put your application in a public GitHub repository (make sure it has a `requirements.txt`!). |
| 103 | + * Log in to [share.streamlit.io](https://share.streamlit.io/). |
| 104 | + * Click "Deploy an App" and paste your GitHub URL. |
| 105 | + * Complete the deployment of your [application](https://docgpt-app.streamlit.app/). |
| 106 | + |
| 107 | +<a href="#top">Back to top</a> |
0 commit comments