private-gpt
Interact with your documents using the power of GPT, 100% privately, no data leaks
Top Related Projects
Interact with your documents using the power of GPT, 100% privately, no data leaks
Chat with your documents on your local device using GPT models. No data leaves your device and 100% private.
MII makes low-latency and high-throughput inference possible, powered by DeepSpeed.
A Gradio web UI for Large Language Models.
Python bindings for llama.cpp
:robot: The free, Open Source alternative to OpenAI, Claude and others. Self-hosted and local-first. Drop-in replacement for OpenAI, running on consumer-grade hardware. No GPU required. Runs gguf, transformers, diffusers and many more models architectures. Features: Generate Text, Audio, Video, Images, Voice Cloning, Distributed inference
Quick Overview
Private-GPT is an open-source project that allows users to interact with their personal documents using natural language, powered by GPT models. It prioritizes privacy by processing all data locally on the user's machine, without sending any information to external servers.
Pros
- Ensures data privacy by keeping all processing local
- Supports various document formats (PDF, TXT, etc.)
- Customizable and extensible for different use cases
- Leverages powerful language models for document interaction
Cons
- Requires significant local computing resources
- May have slower processing times compared to cloud-based solutions
- Limited to the capabilities of locally-run models
- Requires technical knowledge for setup and customization
Code Examples
# Initialize the PrivateGPT instance
from private_gpt import PrivateGPT
pgpt = PrivateGPT()
# Ingest a document
pgpt.ingest_document("path/to/document.pdf")
# Query the ingested documents
response = pgpt.query("What is the main topic of the document?")
print(response)
# Customize embedding model
from private_gpt import PrivateGPT
from langchain.embeddings import HuggingFaceEmbeddings
custom_embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
pgpt = PrivateGPT(embeddings_model=custom_embeddings)
# Use a different LLM
from private_gpt import PrivateGPT
from langchain.llms import LlamaCpp
custom_llm = LlamaCpp(model_path="path/to/llama/model.bin")
pgpt = PrivateGPT(llm=custom_llm)
Getting Started
-
Clone the repository:
git clone https://github.com/zylon-ai/private-gpt.git cd private-gpt
-
Install dependencies:
pip install -r requirements.txt
-
Download required models:
python scripts/setup.py
-
Run the application:
python private_gpt/main.py
-
Access the web interface at
http://localhost:8001
or use the CLI for interactions.
Competitor Comparisons
Interact with your documents using the power of GPT, 100% privately, no data leaks
Pros of private-gpt
- Identical functionality and features as both repositories are the same project
- Consistent user experience across both versions
Cons of private-gpt
- No unique advantages or disadvantages compared to the other repository
- Identical limitations and potential issues
Code Comparison
Both repositories contain the same codebase, so there are no differences to highlight. Here's a sample from the main.py file, which would be identical in both:
def main():
# Load the index
index = load_index()
# Create a prompt helper
prompt_helper = PromptHelper(
max_input_size=4096,
num_output=256,
max_chunk_overlap=20,
chunk_size_limit=600,
)
# Create a service context
service_context = ServiceContext.from_defaults(
llm=OpenAI(temperature=0, model_name="gpt-3.5-turbo", max_tokens=256),
prompt_helper=prompt_helper
)
Note: The comparison between zylon-ai/private-gpt and zylon-ai/private-gpt> appears to be referring to the same repository. As a result, there are no meaningful differences to compare. The pros, cons, and code samples would be identical for both repositories.
Chat with your documents on your local device using GPT models. No data leaves your device and 100% private.
Pros of localGPT
- Supports multiple document types (PDF, TXT, etc.) for ingestion
- Utilizes Sentence Transformers for improved embedding quality
- Offers a user-friendly web interface for interactions
Cons of localGPT
- Limited to CPU-based inference, potentially slower for large datasets
- Requires more manual setup and configuration
- Less extensive documentation compared to private-gpt
Code Comparison
private-gpt:
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import Chroma
from langchain.llms import GPT4All
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
db = Chroma(persist_directory=persist_directory, embedding_function=embeddings)
llm = GPT4All(model=model_path, n_ctx=model_n_ctx, backend='gptj')
localGPT:
from langchain.embeddings import HuggingFaceInstructEmbeddings
from langchain.vectorstores import FAISS
from langchain.llms import LlamaCpp
embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
db = FAISS.from_documents(documents, embeddings)
llm = LlamaCpp(model_path=model_path, n_ctx=model_n_ctx, n_batch=8)
Both projects use LangChain for embeddings and vector stores, but localGPT opts for more advanced models and FAISS for vector storage, while private-gpt uses simpler models and Chroma for persistence.
MII makes low-latency and high-throughput inference possible, powered by DeepSpeed.
Pros of DeepSpeed-MII
- Offers advanced optimization techniques for large language models
- Provides seamless integration with popular deep learning frameworks
- Supports a wide range of model architectures and deployment scenarios
Cons of DeepSpeed-MII
- Requires more setup and configuration compared to Private-GPT
- May have a steeper learning curve for users new to deep learning optimization
Code Comparison
DeepSpeed-MII:
import deepspeed
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("gpt2")
engine = deepspeed.init_inference(model)
Private-GPT:
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import Chroma
from langchain.llms import GPT4All
embeddings = HuggingFaceEmbeddings()
db = Chroma(persist_directory="db", embedding_function=embeddings)
llm = GPT4All(model="./models/gpt4all-model.bin", n_ctx=1000, n_threads=8)
DeepSpeed-MII focuses on optimizing large language models for inference, while Private-GPT emphasizes privacy-preserving local deployment of language models. DeepSpeed-MII offers more advanced optimization techniques but requires more setup, whereas Private-GPT provides a simpler approach for local, offline use of language models.
A Gradio web UI for Large Language Models.
Pros of text-generation-webui
- Supports a wider range of models and architectures
- Offers a more comprehensive web interface with additional features
- Provides extensive customization options for model parameters and generation settings
Cons of text-generation-webui
- May require more technical knowledge to set up and configure
- Potentially higher resource requirements due to its broader feature set
- Less focused on privacy and local deployment compared to private-gpt
Code Comparison
text-generation-webui:
def generate_reply(
question, chat_instruct_command=None, loading_message=DEFAULT_LOADING_MESSAGE
):
# Complex generation logic with multiple options and parameters
# ...
private-gpt:
def get_answer(question: str) -> str:
# Simplified question-answering logic
# ...
The code comparison shows that text-generation-webui offers more complex and flexible generation options, while private-gpt focuses on a streamlined question-answering approach. This reflects the broader scope of text-generation-webui and the more targeted functionality of private-gpt.
Python bindings for llama.cpp
Pros of llama-cpp-python
- Focused on providing Python bindings for llama.cpp, offering more flexibility for integration into various Python projects
- Supports multiple architectures and platforms, including ARM64 and x86_64
- Regularly updated with the latest llama.cpp improvements and features
Cons of llama-cpp-python
- Lacks built-in document processing and retrieval capabilities
- Requires more setup and configuration for use in a complete question-answering system
- Does not provide a ready-to-use chat interface or API out of the box
Code Comparison
llama-cpp-python:
from llama_cpp import Llama
llm = Llama(model_path="./models/7B/ggml-model.bin")
output = llm("Q: Name the planets in the solar system? A: ", max_tokens=32, stop=["Q:", "\n"], echo=True)
print(output)
private-gpt:
from langchain.chains import RetrievalQA
from langchain.llms import GPT4All
qa = RetrievalQA.from_chain_type(llm=GPT4All(), chain_type="stuff", retriever=vectorstore.as_retriever())
response = qa({"query": "Name the planets in the solar system?"})
print(response)
The code snippets demonstrate the different approaches: llama-cpp-python provides direct access to the language model, while private-gpt uses a higher-level abstraction with document retrieval capabilities.
:robot: The free, Open Source alternative to OpenAI, Claude and others. Self-hosted and local-first. Drop-in replacement for OpenAI, running on consumer-grade hardware. No GPU required. Runs gguf, transformers, diffusers and many more models architectures. Features: Generate Text, Audio, Video, Images, Voice Cloning, Distributed inference
Pros of LocalAI
- Supports multiple AI models and APIs, offering greater flexibility
- Provides a REST API for easier integration with various applications
- Includes features like text-to-speech and speech-to-text
Cons of LocalAI
- May require more setup and configuration due to its broader scope
- Potentially higher resource requirements to run multiple models
Code Comparison
LocalAI example (API request):
import requests
response = requests.post(
"http://localhost:8080/v1/completions",
json={"prompt": "Hello, how are you?", "model": "gpt-3.5-turbo"}
)
print(response.json())
private-GPT example (using the library):
from private_gpt import PrivateGPT
pgpt = PrivateGPT()
response = pgpt.chat("Hello, how are you?")
print(response)
Summary
LocalAI offers a more versatile solution with support for multiple models and APIs, while private-GPT focuses specifically on providing a privacy-centric GPT experience. LocalAI's REST API makes it easier to integrate with various applications, but it may require more setup and resources. private-GPT, on the other hand, provides a simpler, more focused solution for those primarily interested in a private GPT implementation.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ð PrivateGPT ð
PrivateGPT is a production-ready AI project that allows you to ask questions about your documents using the power of Large Language Models (LLMs), even in scenarios without an Internet connection. 100% private, no data leaves your execution environment at any point.
[!TIP] If you are looking for an enterprise-ready, fully private AI workspace check out Zylon's website or request a demo. Crafted by the team behind PrivateGPT, Zylon is a best-in-class AI collaborative workspace that can be easily deployed on-premise (data center, bare metal...) or in your private cloud (AWS, GCP, Azure...).
The project provides an API offering all the primitives required to build private, context-aware AI applications. It follows and extends the OpenAI API standard, and supports both normal and streaming responses.
The API is divided into two logical blocks:
High-level API, which abstracts all the complexity of a RAG (Retrieval Augmented Generation) pipeline implementation:
- Ingestion of documents: internally managing document parsing, splitting, metadata extraction, embedding generation and storage.
- Chat & Completions using context from ingested documents: abstracting the retrieval of context, the prompt engineering and the response generation.
Low-level API, which allows advanced users to implement their own complex pipelines:
- Embeddings generation: based on a piece of text.
- Contextual chunks retrieval: given a query, returns the most relevant chunks of text from the ingested documents.
In addition to this, a working Gradio UI client is provided to test the API, together with a set of useful tools such as bulk model download script, ingestion script, documents folder watch, etc.
ðï¸ Overview
[!WARNING] This README is not updated as frequently as the documentation. Please check it out for the latest updates!
Motivation behind PrivateGPT
Generative AI is a game changer for our society, but adoption in companies of all sizes and data-sensitive domains like healthcare or legal is limited by a clear concern: privacy. Not being able to ensure that your data is fully under your control when using third-party AI tools is a risk those industries cannot take.
Primordial version
The first version of PrivateGPT was launched in May 2023 as a novel approach to address the privacy concerns by using LLMs in a complete offline way.
That version, which rapidly became a go-to project for privacy-sensitive setups and served as the seed for thousands of local-focused generative AI projects, was the foundation of what PrivateGPT is becoming nowadays; thus a simpler and more educational implementation to understand the basic concepts required to build a fully local -and therefore, private- chatGPT-like tool.
If you want to keep experimenting with it, we have saved it in the primordial branch of the project.
It is strongly recommended to do a clean clone and install of this new version of PrivateGPT if you come from the previous, primordial version.
Present and Future of PrivateGPT
PrivateGPT is now evolving towards becoming a gateway to generative AI models and primitives, including completions, document ingestion, RAG pipelines and other low-level building blocks. We want to make it easier for any developer to build AI applications and experiences, as well as provide a suitable extensive architecture for the community to keep contributing.
Stay tuned to our releases to check out all the new features and changes included.
ð Documentation
Full documentation on installation, dependencies, configuration, running the server, deployment options, ingesting local documents, API details and UI features can be found here: https://docs.privategpt.dev/
𧩠Architecture
Conceptually, PrivateGPT is an API that wraps a RAG pipeline and exposes its primitives.
- The API is built using FastAPI and follows OpenAI's API scheme.
- The RAG pipeline is based on LlamaIndex.
The design of PrivateGPT allows to easily extend and adapt both the API and the RAG implementation. Some key architectural decisions are:
- Dependency Injection, decoupling the different components and layers.
- Usage of LlamaIndex abstractions such as
LLM
,BaseEmbedding
orVectorStore
, making it immediate to change the actual implementations of those abstractions. - Simplicity, adding as few layers and new abstractions as possible.
- Ready to use, providing a full implementation of the API and RAG pipeline.
Main building blocks:
- APIs are defined in
private_gpt:server:<api>
. Each package contains an<api>_router.py
(FastAPI layer) and an<api>_service.py
(the service implementation). Each Service uses LlamaIndex base abstractions instead of specific implementations, decoupling the actual implementation from its usage. - Components are placed in
private_gpt:components:<component>
. Each Component is in charge of providing actual implementations to the base abstractions used in the Services - for exampleLLMComponent
is in charge of providing an actual implementation of anLLM
(for exampleLlamaCPP
orOpenAI
).
ð¡ Contributing
Contributions are welcomed! To ensure code quality we have enabled several format and
typing checks, just run make check
before committing to make sure your code is ok.
Remember to test your code! You'll find a tests folder with helpers, and you can run
tests using make test
command.
Don't know what to contribute? Here is the public Project Board with several ideas.
Head over to Discord #contributors channel and ask for write permissions on that GitHub project.
ð¬ Community
Join the conversation around PrivateGPT on our:
ð Citation
If you use PrivateGPT in a paper, check out the Citation file for the correct citation.
You can also use the "Cite this repository" button in this repo to get the citation in different formats.
Here are a couple of examples:
BibTeX
@software{Zylon_PrivateGPT_2023,
author = {Zylon by PrivateGPT},
license = {Apache-2.0},
month = may,
title = {{PrivateGPT}},
url = {https://github.com/zylon-ai/private-gpt},
year = {2023}
}
APA
Zylon by PrivateGPT (2023). PrivateGPT [Computer software]. https://github.com/zylon-ai/private-gpt
ð¤ Partners & Supporters
PrivateGPT is actively supported by the teams behind:
- Qdrant, providing the default vector database
- Fern, providing Documentation and SDKs
- LlamaIndex, providing the base RAG framework and abstractions
This project has been strongly influenced and supported by other amazing projects like LangChain, GPT4All, LlamaCpp, Chroma and SentenceTransformers.
Top Related Projects
Interact with your documents using the power of GPT, 100% privately, no data leaks
Chat with your documents on your local device using GPT models. No data leaves your device and 100% private.
MII makes low-latency and high-throughput inference possible, powered by DeepSpeed.
A Gradio web UI for Large Language Models.
Python bindings for llama.cpp
:robot: The free, Open Source alternative to OpenAI, Claude and others. Self-hosted and local-first. Drop-in replacement for OpenAI, running on consumer-grade hardware. No GPU required. Runs gguf, transformers, diffusers and many more models architectures. Features: Generate Text, Audio, Video, Images, Voice Cloning, Distributed inference
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot