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.43.tar.gz (12.6 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.43-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: orign-0.1.43.tar.gz
  • Upload date:
  • Size: 12.6 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.43.tar.gz
Algorithm Hash digest
SHA256 b8e054622ca6e6e116912e6228711492a048a30dbbcf9bb1e7941b8e70bd1a9d
MD5 7092640b49db433a53c0f0803c5ba4a7
BLAKE2b-256 a2f353bf70df3f12a6d4d5839b6aa7cb6d7081339eaabed3b51c683f7c79f400

See more details on using hashes here.

File details

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

File metadata

  • Download URL: orign-0.1.43-py3-none-any.whl
  • Upload date:
  • Size: 19.4 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.43-py3-none-any.whl
Algorithm Hash digest
SHA256 0c000375e4556130d19632a8e8c3067a288f2299192e18eee0f0bfb0893f6953
MD5 562f9f740d72eba5659812baf85520d7
BLAKE2b-256 52c165afecafb3845ab2b732e0d12bc267bd9d6e2dd09d1a45c66e859102ad33

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