Skip to main content

A Python package to serve python functions, classes, or .py files on a local server or cloud-based environment.

Project description

About

Okik is a command-line interface (CLI) that allows users to run various inference services such as LLM, RAG(WIP), or anything in between using various frameworks on any *cloud. With Okik, you can easily run these services directly on any cloud without the hassle of managing your own infra.

Installation

Using pip

pip install okik

Or To install Okik, follow these steps:

  1. Clone the repository: git clone https://github.com/okikorg/okik.git
  2. Navigate to the project directory: cd okik
  3. Install Okik using pip: pip install .

Quick Start

To run Okik, simply execute the following command in your terminal: okik

██████  ██   ██ ██ ██   ██
██    ██ ██  ██  ██ ██  ██
██    ██ █████   ██ █████
██    ██ ██  ██  ██ ██  ██
██████  ██   ██ ██ ██   ██



Simplify. Deploy. Scale.
Type 'okik --help' for more commands.

Initialise the project

okik init

Quick Example

Write this in your main.py file:

from okik.endpoints import service, endpoint, app
import asyncio
from typing import Any
from sentence_transformers import SentenceTransformer
import sentence_transformers
from torch.nn.functional import cosine_similarity as cosine
import torch
import random

# your service configuration
@service(
    replicas=1,
    resources={"accelerator": {"type": "A40", "device": "cuda", "count": 1, "memory": 4}},
    backend="okik" # <- provisioning backend is okik
)
class Embedder:
    def __init__(self):
        self.model = SentenceTransformer("paraphrase-MiniLM-L6-v2", cache_folder=".okik/cache")

    @endpoint()
    def embed(self, sentence: str):
        logits = self.model.encode(sentence)
        return logits

    @endpoint()
    def similarity(self, sentence1: str, sentence2: str):
        logits1 = self.model.encode(sentence1, convert_to_tensor=True)
        logits2 = self.model.encode(sentence2, convert_to_tensor=True)
        return cosine(logits1.unsqueeze(0), logits2.unsqueeze(0))

    @endpoint()
    def version(self):
        return sentence_transformers.__version__

    @endpoint(stream=True)
    async def stream_data(self) -> Any:
        async def data_generator():
            for i in range(10):
                yield f"data: {i}\n"
                await asyncio.sleep(1)
        return data_generator()

# Mock LLM Service Example
@service(replicas=1)
class MockLLM:
    def __init__(self):
        pass

    @endpoint(stream=True) # <- streaming response enabled for use cases like chatbot
    async def stream_random_words(self, prompt: str = "Hello"):
        async def word_generator():
            words = ["hello", "world", "fastapi", "stream", "test", "random", "words", "python", "async", "response"]
            for _ in range(10):
                word = random.choice(words)
                yield f"{word}\n"
                await asyncio.sleep(0.4)
        return word_generator()

Verify the routes

# run the okik routes to check all available routes
okik routes
# output should be similar to this
main.py Application Routes
├── <HOST>/health/
│   └── /health | GET
├── <HOST>/embedder/
│   ├── /embedder/embed | POST
│   ├── /embedder/similarity | POST
│   ├── /embedder/stream_data | POST
│   └── /embedder/version | POST
└── <HOST>/mockllm/
    └── /mockllm/stream_random_words | POST

Serving the app

# run the okik run to start the server in production mode
okik server
# or run in dev mode
okik server --dev --reload
#or
okik server -d -r

Test the app

curl -X POST http://0.0.0.0:3000/embedder/version
# or if you like to use httpie then
http POST 0.0.0.0:3000/embedder/version

# or test the stream endpoint
curl -X POST http://0.0.0.0:3000/mockllm/stream_random_words -d '{"prompt": "Hello"}'
# or if you like to use httpie then
http POST 0.0.0.0:3000/mockllm/stream_random_words prompt="hello" --stream

Build the app

okik build -a "your_awesome_app" -t latest

Deploy the app

okik deploy

Monitor the app

# similar to kubectl commands, infact you can use kubectl commands as well
okik get deployments # for deployments
okik get services # for services

Delete the app

okik delete deployment "your_awesome_app"

Status

Okik is currently in development so expect sharp edges and bugs. Feel free to contribute to the project by submitting a pull request.

Roadmap

  • [] Add support for various inference engines such as vLLM, TGI, etc.
  • [] Add support for various cloud providers such as AWS, GCP, Azure, etc.

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

okik-0.0.34b0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

okik-0.0.34b0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file okik-0.0.34b0.tar.gz.

File metadata

  • Download URL: okik-0.0.34b0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Darwin/23.0.0

File hashes

Hashes for okik-0.0.34b0.tar.gz
Algorithm Hash digest
SHA256 b7e07094356897ea001e8c4a789ea82a9308ed66a15f1c22c96197c4834d8aa6
MD5 011d2f1ac80b7e2cae3faa9fec7c8bcd
BLAKE2b-256 27512c3c17bb3e168a63a21c2f9da717d3454babe086c572fd9ddef61fdc4536

See more details on using hashes here.

File details

Details for the file okik-0.0.34b0-py3-none-any.whl.

File metadata

  • Download URL: okik-0.0.34b0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Darwin/23.0.0

File hashes

Hashes for okik-0.0.34b0-py3-none-any.whl
Algorithm Hash digest
SHA256 80e0a7e35267b377d2f5d11f59675d9982cc24504a49acc40d962cfaf17a4aee
MD5 43dfb2cd0ef55cea2df3d28bb203e639
BLAKE2b-256 86355388f7a451b4770473fcf4f68593d1a265b0a3ddfd4d0c15817e44be65dd

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