Skip to main content

The smallest possible LLM API

Project description

llama-small

MicroLlama

The smallest possible LLM API. Build a question and answer interface to your own content in a few minutes. Uses OpenAI embeddings, gpt-3.5 and Faiss, via Langchain.

Usage

  1. Combine your source documents into a single JSON file called source.json. It should look like this:
[
    {
        "source": "Reference to the source of your content. Typically a title.",
        "url": "URL for your source. This key is optional.",
        "content": "Your content as a single string. If there's a title or summary, put these first, separated by new lines."
    }, 
    ...
]

See example.source.json for an example.

  1. Install MicroLlama into a virtual environment:
pip install microllama
  1. Get an OpenAI API key and add it to the environment, e.g. export OPENAI_API_KEY=sk-etc. Note that indexing and querying require OpenAI credits, which aren't free.

  2. Run your server with microllama. If a vector search index doesn't exist, it'll be created from your source.json, and stored.

  3. Query your documents at /api/ask?your question.

  4. Microllama includes an optional web front-end, which is generated with microllama make-front-end. This command creates a single index.html file which you can edit. It's served at /.

Configuration

Microllama is configured through environment variables, with the following defaults:

  • OPENAI_API_KEY: required
  • FAISS_INDEX_PATH: "faiss_index"
  • SOURCE_JSON: "source.json"
  • MAX_RELATED_DOCUMENTS: "5"
  • EXTRA_CONTEXT: "Answer in no more than three sentences. If the answer is not included in the context, say 'Sorry, this is no answer for this in my sources.'."
  • UVICORN_HOST: "0.0.0.0"
  • UVICORN_PORT: "8080"

Deploying your API

Create a Dockerfile with microllama make-dockerfile. Then:

On Fly.io

Sign up for a Fly.io account and install flyctl. Then:

fly launch # answer no to Postgres, Redis and deploying now 
fly secrets set OPENAI_API_KEY=sk-etc 
fly deploy

On Google Cloud Run

gcloud run deploy --source . --set-env-vars="OPENAI_API_KEY=sk-etc"

For Cloud Run and other serverless platforms you should generate the FAISS index at container build time, to reduce startup time. See the two commented lines in Dockerfile.

You can also generate these commands with microllama deploy.

Based on

TODO

  • Use splitting which generates more meaningful fragments, e.g. text_splitter = SpacyTextSplitter(chunk_size=700, chunk_overlap=200, separator=" ")

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

microllama-0.4.7.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

microllama-0.4.7-py2.py3-none-any.whl (15.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file microllama-0.4.7.tar.gz.

File metadata

  • Download URL: microllama-0.4.7.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for microllama-0.4.7.tar.gz
Algorithm Hash digest
SHA256 e3e5aaf2feb289944e25fc76217b4f726259ae13c0b4f19e8390850f5df67c89
MD5 ca59c7acb1fd56bcaecdf284a6fb9852
BLAKE2b-256 60275d6adc90d21509fe719009ca712beab4fe611d6ab6043f26360b6c3f3730

See more details on using hashes here.

File details

Details for the file microllama-0.4.7-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for microllama-0.4.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 75201dc61d06631b1d0a3fd2a9058cc8813d78a908802fc3d1d895380c18776a
MD5 95db650bbadefbae2c240a1e21f176bd
BLAKE2b-256 a4ddc9eccbf12b552a6d4856edfc89bff27cd8fb82b8fc070da05f9b76432670

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