Skip to main content

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=" ")

Release files for microllama 0.4.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for microllama 0.4.10
File Size Uploaded
microllama-0.4.10.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for microllama 0.4.10
File Interpreter ABI Platform
microllama-0.4.10-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 32.7 kB

Release files / microllama-0.4.10.tar.gz

Download URL microllama-0.4.10.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f1a7edeea78616502209e675533397cf9e75060f4719630b270a35d07db535af
BLAKE2b-256 checksum
How to use checksums
45fcfe068641c2339536dd033b99e330905691bd4d15b7b45e2c6c82980cdf57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release files / microllama-0.4.10-py2.py3-none-any.whl

Download URL microllama-0.4.10-py2.py3-none-any.whl
Size 15.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7ea8dcb2e5b39aebef09e771be694dcc12803b5ff3cb1860053efb53ae001c4d
BLAKE2b-256 checksum
How to use checksums
d993292ea7c7248030ec2188e2420e0d78116b698fa3ee0bbe175a0457973b9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release history Release notifications | RSS feed

This release

0.4.10 This release

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page