Skip to main content

Create a question answering over docs bot with one line of code.

Project description

QnA Bot

Tests

Here is an example of what you build with this library: Demo

Create a question answering over docs bot with one line of code:

pip install qnabot
from qnabot import QnABot
import os

os.environ["OPENAI_API_KEY"] = "my key"

# Create a bot 👉 with one line of code
bot = QnABot(directory="./mydata")

# Ask a question
answer = bot.ask("How do I use this bot?")

# Save the index to save costs (GPT is used to create the index)
bot.save_index("index.pickle")

# Load the index from a previous run
bot = QnABot(directory="./mydata", index="index.pickle")

You can also create a FastAPI app that will expose the bot as an API using the create_app function. Assuming you file is called main.py run uvicorn main:app --reload to run the API locally. You should then be able to visit http://localhost:8000/docs to see the API documentation.

from qnabot import QnABot, create_app

app = create_app(QnABot("./mydata"))

You can expose a gradio UI for the bot using create_interface function. Assuming your file is called ui.py run gradio qnabot/ui.py to run the UI locally. You should then be able to visit http://127.0.0.1:7860 to see the API documentation.

from qnabot import QnABot, create_interface

demo = create_interface(QnABot("./mydata"))

Features

  • Create a question answering bot over your documents with one line of code using GPT
  • Save / load index to reduce costs (Open AI embedings are used to create the index)
  • Local data source (directory of documents) or S3 data source
  • FAISS for storing vectors / index
  • Expose bot over API using FastAPI
  • Gradio UI
  • Integration with guardrails
  • Integration with GPTCache
  • Support for other vector databases (e.g. Weaviate, Pinecone)
  • Customise prompt
  • Support for LLaMA model

Here's how it works

Large language models (LLMs) are powerful, but they can't answer questions about documents they haven't seen. If you want to use an LLM to answer questions about documents it was not trained on, you have to give it information about those documents. To solve this, we use "retrieval augmented generation."

In simple terms, when you have a question, you first search for relevant documents. Then, you give the documents and the question to the language model to generate an answer. To make this work, you need your documents in a searchable format (an index). This process involves two main steps: (1) preparing your documents for easy querying, and (2) using the retrieval augmented generation method.

QnABot uses FAISS to create an index of documents and GPT to generate answers.

sequenceDiagram
    actor User
    participant API
    participant LLM
    participant Vectorstore
    participant IngestionEngine
    participant DataLake
    autonumber

    Note over API, DataLake: Ingestion phase
    loop Every X time
    IngestionEngine ->> DataLake: Load documents
    DataLake -->> IngestionEngine: Return data
    IngestionEngine -->> IngestionEngine: Split documents and Create embeddings
    IngestionEngine ->> Vectorstore: Store documents and embeddings
    end

    Note over API, DataLake: Generation phase

    User ->> API: Receive user question
    API ->> Vectorstore: Lookup documents in the index relevant to the question
    API ->> API: Construct a prompt from the question and any relevant documents
    API ->> LLM: Pass the prompt to the model
    LLM -->> API: Get response from model
    API -->> User: Return response

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

megabots-0.0.6.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

megabots-0.0.6-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file megabots-0.0.6.tar.gz.

File metadata

  • Download URL: megabots-0.0.6.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for megabots-0.0.6.tar.gz
Algorithm Hash digest
SHA256 0b8fa479bd61748889f35cab4de945fbcf72f5def7de00b8ff3de4b2dea59376
MD5 c6b816ace3f7de3393b82016c797751b
BLAKE2b-256 11d60a530b0debbf7340b07169b9ed773b42201e2ab647eda22bfc377b4506e6

See more details on using hashes here.

File details

Details for the file megabots-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: megabots-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for megabots-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 13c91338fd77c13bd847359ac9a2c9695f36606756adffaa28fef627b0a289d7
MD5 43d7331a70abc6cdb6cd6deedc0531b5
BLAKE2b-256 d8fafbf1dd56c20339d21ee3ba246ce8cdaca3d5df6bb665f120b733acc410b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page