Git Product home page Git Product logo

llama-api-server's Introduction

🎭🦙 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

Try it online!

Follow instruction in this collab notebook to play it online. Thanks anythingbutme for building it!

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

llama-api-server's People

Contributors

dependabot[bot] avatar iaalm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

llama-api-server's Issues

[FEATURE] Upgrade llama-cpp-python to latest version

The version of llama-cpp-python this project uses is quite old. Therefore I get a lot of errors regarding versions of GGML models. It also doesn't support GGUF models.

I would suggest to up the version of llama-cpp-python to the latest one.

GGUF models are the future anyway it would seem.
Perhaps we could work on something that allows chosing ?

is there a standardised way to interact with LLMs

Hi.

has anyone come up with a unified, standard API to talk to all LLMs? (LLaMA, Bard, OpenAI etc)? if not, it would be helpful to start defining that as a community and build the compatibility layers for that. keen to hear your thoughts.

instantiation failed: unknown import, Code: 0x62

Here is my commnad:
wasmedge --dir .:. --nn-preload default:GGML:AUTO:qwen1_5-14b-chat-q5_k_m.gguf llama-api-server.wasm -p chatml

[2024-03-21 22:59:10.566] [error] instantiation failed: unknown import, Code: 0x62
[2024-03-21 22:59:10.566] [error] When linking module: "rustls_client" , function name: "new_codec"
[2024-03-21 22:59:10.566] [error] At AST node: import description
[2024-03-21 22:59:10.566] [error] At AST node: import section
[2024-03-21 22:59:10.566] [error] At AST node: module

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.