Skip to main content

A Python client for Orign

Project description

orign-py

A Python client for Orign

Installation

pip install orign

Install the Orign CLI

curl -fsSL -H "Cache-Control: no-cache" https://storage.googleapis.com/orign/releases/install.sh | bash

Login to Orign

$ orign login

Usage

Get a list of available models

$ orign get models

Chat

Define which model we would like to use

from orign import ChatModel

model = ChatModel(model="allenai/Molmo-7B-D-0924", provider="vllm")

Open a socket connection to the model

model.connect()

Chat with the model

model.chat(msg="What's in this image?", image="https://tinyurl.com/2fz6ms35")

Stream tokens from the model

for response in model.chat(msg="What is the capital of France?", stream_tokens=True):
    print(response)

Send a thread of messages to the model

model.chat(prompt=[
    {"role": "user", "content": "What is the capital of France?"},
    {"role": "assistant", "content": "Paris"},
    {"role": "user", "content": "When was it built?"}
])

Send a batch of threads to the model

model.chat(batch=[
    [{"role": "user", "content": "What is the capital of France?"}, {"role": "assistant", "content": "Paris"}, {"role": "user", "content": "When was it built?"}],
    [{"role": "user", "content": "What is the capital of Spain?"}, {"role": "assistant", "content": "Madrid"}, {"role": "user", "content": "When was it built?"}]
]):

Use the async API

from orign import AsyncChatModel

model = AsyncChatModel(model="allenai/Molmo-7B-D-0924", provider="vllm")
await model.connect()

async for response in model.chat(
    msg="What is the capital of france?", stream_tokens=True
):
    print(response)

Embeddings

Define which model we would like to use

from orign import EmbeddingModel

model = EmbeddingModel(provider="sentence-tf", model="clip-ViT-B-32")

Embed a text

model.embed(text="What is the capital of France?")

Embed an image

model.embed(image="https://example.com/image.jpg")

Embed text and image

model.embed(text="What is the capital of France?", image="https://example.com/image.jpg")

Use the async API

from orign import AsyncEmbeddingModel

model = AsyncEmbeddingModel(provider="sentence-tf", model="clip-ViT-B-32")
await model.connect()

await model.embed(text="What is the capital of France?")

OCR

Define which model we would like to use

from orign import OCRModel

model = OCRModel(provider="easyocr")

Detect text in an image

model.detect(image="https://example.com/image.jpg")

Use the async API

from orign import AsyncOCRModel

model = AsyncOCRModel(provider="doctr")
await model.connect()

await model.detect(image="https://example.com/image.jpg")

Replay Buffer

Replay buffers offer a means of training models in an online fashion.

from orign import ReplayBuffer, V1MSSwiftBufferParams

params = V1MSSwiftBufferParams(
    model="Qwen/Qwen2-VL-7B-Instruct",
    model_type="qwen2_vl",
    train_type="lora",
    deepspeed="zero3",
    torch_dtype="bfloat16",
    max_length=16384,
    val_split_ratio=0.95,
    num_train_epochs=3,
    eval_strategy="epoch",
    save_strategy="epoch",
    save_total_limit=3,
    lora_rank=64,
    lora_alpha=128,
    size_factor=28,
    max_pixels=1025000,
    freeze_vit=True,
)

buffer = ReplayBuffer(
    name="sql-adapter",
    vram_request="40Gi",
    dtype="bfloat16",
    train_every=50,
    sample_n=100,
    sample_strategy="Random",
    ms_swift_params=params,
)

Then send examples to the buffer

buffer.send(
    [
        {
            "messages": [
                {"role": "user", "content": "what's in this image <image>"},
                {"role": "assistant", "content": "Well its a penguin of course"},
            ],
            "images": [
                "https://cdn.britannica.com/77/81277-050-2A6A35B2/Adelie-penguin.jpg"
            ],
        },
    ]
)

Examples

See the examples directory for more usage examples.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orign-0.1.29.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orign-0.1.29-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file orign-0.1.29.tar.gz.

File metadata

  • Download URL: orign-0.1.29.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Darwin/23.4.0

File hashes

Hashes for orign-0.1.29.tar.gz
Algorithm Hash digest
SHA256 3ace0674e963b6b3b638a755108ff73df6d9e52cefb5229a3bb98937b4e5f14f
MD5 c9bb3b3f0f04295c9f63585c71b589e1
BLAKE2b-256 5e38b46aa234dae6f2d66f2c0ad5c0226c15dad0c48141dd7666997ea975ff90

See more details on using hashes here.

File details

Details for the file orign-0.1.29-py3-none-any.whl.

File metadata

  • Download URL: orign-0.1.29-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Darwin/23.4.0

File hashes

Hashes for orign-0.1.29-py3-none-any.whl
Algorithm Hash digest
SHA256 50c305fce4ed1a5eab4d6a864fabee6ce5911d62227ac20bbd73e01d0d68cdc5
MD5 19c9b5840b72e4653411898787ca4b0c
BLAKE2b-256 528198e9d5fecd57d0af303866408a6a58720a336fbfb86ae30c83bec7a3ba38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page