Git Product home page Git Product logo

davizucon / basaran Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hyperonym/basaran

0.0 0.0 0.0 2.93 MB

Basaran is an open-source alternative to the OpenAI text completion API. It provides a compatible streaming API for your Hugging Face Transformers-based text generation models.

License: MIT License

JavaScript 19.39% Python 60.99% CSS 11.17% Makefile 2.36% HTML 2.52% Dockerfile 3.57%

basaran's Introduction

Basaran

Python codecov Status

Basaran is an open-source alternative to the OpenAI text completion API. It provides a compatible streaming API for your Hugging Face Transformers-based text generation models.

The open source community will eventually witness the Stable Diffusion moment for large language models (LLMs), and Basaran is committed to becoming the Stable Diffusion web UI for LLMs. Basaran allows you to replace OpenAI's service with the latest open-source model to power your application without modifying a single line of code.

The key features of Basaran are:

  • Stream generation using various decoding strategies.
  • Support both decoder-only and encoder-decoder models.
  • Detokenizer that handles surrogates and whitespace.
  • Multi-GPU support with optional 8-bit quantization.
  • Real-time partial progress using server-sent events.
  • Compatible with OpenAI API and client libraries.
  • Comes with a fancy web-based playground!

Quick Start

TL;DR

Replace user/repo with the selected model (e.g. bigscience/bloomz-560m) and X.Y.Z with the latest version, then run:

docker run -p 80:80 -e MODEL=user/repo hyperonym/basaran:X.Y.Z

And you're good to go! ๐Ÿš€

Playground: http://127.0.0.1/
API:        http://127.0.0.1/v1/completions

Installation

Docker images are available on Docker Hub and GitHub Packages.

For GPU acceleration, you also need to install the NVIDIA Driver and NVIDIA Container Runtime. Basaran's image already comes with related libraries such as CUDA and cuDNN, so there is no need to install them manually.

Basaran's image can be used in three ways:

  • Run directly: By specifying the MODEL="user/repo" environment variable, the corresponding model can be downloaded from Hugging Face Hub during the first startup.
  • Pre-packaging: Create a new Dockerfile to preload a public model or bundle a private model.
  • Bind mount: Mount a model from the local file system into the container and point the MODEL environment variable to the corresponding path.

Basic Usage

cURL

Basaran's HTTP request and response formats are consistent with the OpenAI API.

Taking text completion as an example:

curl http://127.0.0.1/v1/completions \
    -H 'Content-Type: application/json' \
    -d '{ "prompt": "once upon a time,", "echo": true }'
Example response
{
    "id": "cmpl-e08c701b4ba032c09ef080e1",
    "object": "text_completion",
    "created": 1678003509,
    "model": "bigscience/bloomz-560m",
    "choices": [
        {
            "text": "once upon a time, the human being faces a complicated situation and he needs to find a new life.",
            "index": 0,
            "logprobs": null,
            "finish_reason": "length"
        }
    ],
    "usage": {
        "prompt_tokens": 5,
        "completion_tokens": 21,
        "total_tokens": 26
    }
}

OpenAI Client Library

If your application uses client libraries provided by OpenAI, you only need to modify the OPENAI_API_BASE environment variable to Basaran's corresponding endpoint:

OPENAI_API_BASE="http://127.0.0.1/v1" python your_app.py

The examples directory contains examples of using the Python library.

Compatibility

Basaran's API format is consistent with OpenAI's, with compatibility differences mainly in parameter support and response fields. The following sections provide detailed information on the compatibility of each endpoint.

Models

Each Basaran process serves only one model, so the result will only contain this model.

Completions

Although Basaran does not support the model parameter, the OpenAI client library requires this parameter to be present. Therefore, you can fill in any model name you want.

Parameter Basaran OpenAI Default Value Maximum Value
model โ—‹ โ— - -
prompt โ— โ— "" COMPLETION_MAX_PROMPT
suffix โ—‹ โ— - -
min_tokens โ— โ—‹ 0 COMPLETION_MAX_TOKENS
max_tokens โ— โ— 16 COMPLETION_MAX_TOKENS
temperature โ— โ— 1.0 -
top_p โ— โ— 1.0 -
n โ— โ— 1 COMPLETION_MAX_N
stream โ— โ— false -
logprobs โ— โ— 0 COMPLETION_MAX_LOGPROBS
echo โ— โ— false -
stop โ—‹ โ— - -
presence_penalty โ—‹ โ— - -
frequency_penalty โ—‹ โ— - -
best_of โ—‹ โ— - -
logit_bias โ—‹ โ— - -
user โ—‹ โ— - -

Roadmap

  • API
    • Models
      • List models
      • Retrieve model
    • Completions
      • Create completion
    • Chat
      • Create chat completion
  • Model
    • Architectures
      • Encoder-decoder
      • Decoder-only
    • Decoding strategies
      • Random sampling with temperature
      • Nucleus-sampling (top-p)
      • Contrastive search

See the open issues for a full list of proposed features.

Contributing

This project is open-source. If you have any ideas or questions, please feel free to reach out by creating an issue!

Contributions are greatly appreciated, please refer to CONTRIBUTING.md for more information.

License

Basaran is available under the MIT License.


ยฉ 2023 Hyperonym

basaran's People

Contributors

dependabot[bot] avatar fardeon avatar peakji avatar

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.