megabots / README.md
momegas's picture
🧹 Minor changes
6a8232f
|
raw
history blame
4.31 kB

πŸ€– Megabots

Tests

πŸ€– Megabots provides State-of-the-art, production ready bots made mega-easy, so you don't have to build them from scratch 🀯 Create a bot, now 🫡

The Megabots library can be used to create bots that:

  • ⌚️ are production ready bots in minutes
  • πŸ—‚οΈ can answer questions over documents
  • πŸ§‘β€βš•οΈ can act personal assistants and use agents and tools (Coming soon)
  • πŸ—£οΈ can accept voice (Coming soon)
  • πŸ‘ validate and correct the outputs of large language models (Coming soon)
  • πŸ’° semanticly cache LLM Queries and reduce your LLM API Costs by 10x (Coming soon)
  • πŸ‹οΈ are mega-easily to train (Coming soon)

πŸ€– Megabots is backed by some of the most famous tools for productionalising AI. It uses LangChain for managing LLM chains, FastAPI to create a production ready API, Gradio to create a UI. At the moment it uses OpenAI to generate answers, but we plan to support other LLMs in the future.

Note: This is a work in progress. The API might change.

pip install megabots
from megabots import bot
import os

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

# Create a bot πŸ‘‰ with one line of code. Automatically loads your data from ./index or index.pkl.
qnabot = bot("qna-over-docs")

# 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.pkl")

# Load the index from a previous run
qnabot = bot("qna-over-docs", index="./index.pkl")

# Or create the index from a directory of documents
qnabot = bot("qna-over-docs", index="./index")

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 megabots import bot, create_api

app = create_app(bot("qna-over-docs"))

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 megabots import bot, create_interface

demo = create_interface(QnABot("qna-over-docs"))

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