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.34.tar.gz (11.9 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.34-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: orign-0.1.34.tar.gz
  • Upload date:
  • Size: 11.9 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.34.tar.gz
Algorithm Hash digest
SHA256 7777df4bfe5f30af385ab453e4fa453beb7946f49c04624170c8143bc28dadcd
MD5 a41eb452c877361092d729b50694e7a3
BLAKE2b-256 34461b74a6fbb2f0a170435d6ec4ac49405d63030e3f07f09498800dd1c753b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: orign-0.1.34-py3-none-any.whl
  • Upload date:
  • Size: 18.7 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.34-py3-none-any.whl
Algorithm Hash digest
SHA256 68162149df27ff85e6c641e0f0b33fa20b78485667aaa056a05b64a1b9cd7ee7
MD5 186644deec276d9ce6143a27a4f60290
BLAKE2b-256 fc8cdc363314a59fd30d29436067f28a244dd8c3e3cdcffe9b9a63d1c10d480b

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