Skip to main content

🎭🦙 llama-api-server

Code style: black Release PyPI version

This project is under active deployment. Breaking changes could be made any time.

Llama as a Service! This project try to build a REST-ful API server compatible to OpenAI API using open source backends like llama/llama2.

With this project, many common GPT tools/framework can compatible with your own model.

🚀Get started

Prepare model

llama.cpp

If you you don't have quantized llama.cpp, you need to follow instruction to prepare model.

pyllama

If you you don't have quantize pyllama, you need to follow instruction to prepare model.

Install

Use following script to download package from PyPI and generates model config file config.yml and security token file tokens.txt.

pip install llama-api-server

# to run wth pyllama
pip install llama-api-server[pyllama]

cat > config.yml << EOF
models:
  completions:
    # completions and chat_completions use same model
    text-ada-002:
      type: llama_cpp
      params:
        path: /absolute/path/to/your/7B/ggml-model-q4_0.bin
    text-davinci-002:
      type: pyllama_quant
      params:
        path: /absolute/path/to/your/pyllama-7B4b.pt
    text-davinci-003:
      type: pyllama
      params:
        ckpt_dir: /absolute/path/to/your/7B/
        tokenizer_path: /absolute/path/to/your/tokenizer.model
      # keep to 1 instance to speed up loading of model
  embeddings:
    text-embedding-davinci-002:
      type: pyllama_quant
      params:
        path: /absolute/path/to/your/pyllama-7B4b.pt
      min_instance: 1
      max_instance: 1
      idle_timeout: 3600
    text-embedding-ada-002:
      type: llama_cpp
      params:
        path: /absolute/path/to/your/7B/ggml-model-q4_0.bin
EOF

echo "SOME_TOKEN" > tokens.txt

# start web server
python -m llama_api_server
# or visible across the network
python -m llama_api_server --host=0.0.0.0

Call with openai-python

export OPENAI_API_KEY=SOME_TOKEN
export OPENAI_API_BASE=http://127.0.0.1:5000/v1

openai api completions.create -e text-ada-002 -p "hello?"
# or using chat
openai api chat_completions.create -e text-ada-002 -g user "hello?"
# or calling embedding
curl -X POST http://127.0.0.1:5000/v1/embeddings -H 'Content-Type: application/json' -d '{"model":"text-embedding-ada-002", "input":"It is good."}'  -H "Authorization: Bearer SOME_TOKEN"

🛣️Roadmap

Tested with

Supported APIs

  • Completions
    • set temperature, top_p, and top_k
    • set max_tokens
    • set echo
    • set stop
    • set stream
    • set n
    • set presence_penalty and frequency_penalty
    • set logit_bias
  • Embeddings
    • batch process
  • Chat
    • Prefix cache for chat
  • List model

Supported backends

Others

  • Performance parameters like n_batch and n_thread
  • Token auth
  • Documents
  • Intergration tests
  • A tool to download/prepare pretrain model
  • Make config.ini and token file configable

Metadata

Release files for llama-api-server 0.3.5

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

Source distribution (sdist)

Source distribution for llama-api-server 0.3.5
File Size Uploaded Provenance
llama_api_server-0.3.5.tar.gz 11.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llama-api-server 0.3.5
File Interpreter ABI Platform
llama_api_server-0.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 23.9 kB

Release files / llama_api_server-0.3.5.tar.gz

Download URL llama_api_server-0.3.5.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
65bf6d5f96b7e7bae0a9968b00d25ffcbc61e6d94b8807c9e1ebbf84ffe0f3b3
BLAKE2b-256 checksum
How to use checksums
0c4b4f44cb9919cf14c3abb780bcb6d56f94b6e8ac0de82b92681f2eb7eac57e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / llama_api_server-0.3.5-py3-none-any.whl

Download URL llama_api_server-0.3.5-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
455b6b61935335546030af3e13f235bb3bcba0137c2dfeaa84b9b9560962187b
BLAKE2b-256 checksum
How to use checksums
341aea94c309c34cbd86b0843d1d76912f15494aa11bd08720a809824bb1b20f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for llama-api-server 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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