Metadata-Version: 2.1
Name: omai
Version: 1.0.5
Summary: Python SDK for Omai OD, OVD, OmChat and VLX APIs
Home-page: UNKNOWN
Author: Omai
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# omai-client Python SDK

The Omai Python SDK currently provides interfaces for OD, OVD, OmChat, and VLX:

- `od`: Object Detection
- `ovd`: Open-Vocabulary Object Detection
- `om_chat`: Synchronous multimodal OmChat requests
- `vlx_seek`: Synchronous multimodal VLX-Seek requests
- `vlx_flow_stream`: Create VLX streaming tasks and consume raw SSE events
- `vlx_flow_stream_message`: Create VLX streaming tasks and consume business messages
- `vlx_flow_stream_raw`: Return the raw streaming response
- `vlx_flow_stop`: Stop a VLX streaming task
- `vlx_flow_update_config`: Update the configuration of a VLX streaming task
- `vlx_vr_stream`: Create a VLX-VR stream and consume raw SSE events
- `vlx_vr_stream_message`: Create a VLX-VR stream and consume structured Chunk events
- `vlx_vr_stream_raw`: Return the raw VLX-VR streaming response
- `vlx_vr_stop`: Stop a VLX-VR video analysis task

## Install from tar.gz

```bash
pip install ./dist/omai-1.0.5.tar.gz
```

## Single-File Verification

For temporary verification, copy `dist_single/vlx_api_client.py` directly into your application project:

```python
from vlx_api_client import VlxApiClient, VlxSeekRequest, VlxSeekMessage, VlxSeekContent
```

The single-file and package versions share the same core code. Real HTTP requests require `requests`:

```bash
pip install requests
```

## Environment Variables

The Python SDK is configured through environment variables:

```bash
export VLX_API_ENABLED=true
export VLX_API_ENDPOINT=http://linker-gateway-service:31003/
export VLX_API_KEY=aaas_xxx
export VLX_API_CONNECT_TIMEOUT_MS=60000
export VLX_API_READ_TIMEOUT_MS=60000
export VLX_API_WRITE_TIMEOUT_MS=60000
export VLX_API_STREAM_READ_TIMEOUT_MS=0
export VLX_API_CLIENT_NUM=2048
```

`VLX_API_STREAM_READ_TIMEOUT_MS=0` disables the read timeout for streaming interfaces and is suitable for 12- or 24-hour SSE connections.

## Object Detection Example

```python
from omai_client import OdRequest, OdSubItem, VlxApiClient

client = VlxApiClient.from_env()

response = client.od(
    OdRequest(
        subList=[
            OdSubItem(
                model="OD210_021_002111_008",
                configCode="1646130545656070144",
            )
        ],
        input="https://example.com/demo.jpg",
        inputType="image_url",
        videoCode="videoCode_demo",
    )
)

for result in response.data:
    print(result.model, result.bboxList)
```

## Open-Vocabulary Object Detection Example

```python
from omai_client import OvdRequest, OvdTask, VlxApiClient

client = VlxApiClient.from_env()

response = client.ovd(
    OvdRequest(
        model="OD004_021_000035_002",
        input="https://example.com/demo.png",
        inputType="image_url",
        tasks=[
            OvdTask(
                prompt="Detect people in the image",
                label="person",
                uniqueId="0",
                conf=0.6,
            )
        ],
    )
)

for result in response.data:
    print(result.uniqueId, result.ovdResult.bboxList)
```

## OmChat Example

```python
from omai_client import (
    OmChatContent,
    OmChatImageUrl,
    OmChatMessage,
    OmChatRequest,
    VlxApiClient,
)

client = VlxApiClient.from_env()

response = client.om_chat(
    OmChatRequest(
        model="OmChat",
        messages=[
            OmChatMessage(
                role="user",
                content=[
                    OmChatContent(type="text", text="Describe the image content"),
                    OmChatContent(
                        type="image_url",
                        image_url=OmChatImageUrl(url="https://example.com/demo.jpg"),
                    ),
                ],
            )
        ],
        max_tokens=512,
        temperature=0.2,
    )
)

print(response.choices[0].message.content)
```

## VLX-Seek Example

```python
from omai_client import (
    VlxApiClient,
    VlxSeekContent,
    VlxSeekImageUrl,
    VlxSeekMessage,
    VlxSeekRequest,
)

client = VlxApiClient.from_env()

request = VlxSeekRequest(
    model="VLX-Seek",
    messages=[
        VlxSeekMessage(
            role="user",
            content=[
                VlxSeekContent(type="text", text="Describe the image content"),
                VlxSeekContent(
                    type="image_url",
                    image_url=VlxSeekImageUrl(url="https://example.com/a.jpg"),
                ),
            ],
        )
    ],
    max_tokens=512,
    temperature=0.2,
)

response = client.vlx_seek(request)
print(response.choices[0].message.content)
```

## Streaming Message Example

```python
from omai_client import VlxApiClient, VlxFlowSource, VlxFlowStreamRequest


class Handler:
    def on_event(self, message):
        print(message.event, message.content)

    def on_error(self, throwable):
        print("error:", throwable)

    def on_closed(self):
        print("closed")


client = VlxApiClient.from_env()
call = client.vlx_flow_stream_message(
    VlxFlowStreamRequest(
        source=VlxFlowSource(path="rtsp://camera", type=1),
        prompt="Identify abnormal situations in the scene",
        frame_preempt="qa",
        model="VLX-Stream",
    ),
    Handler(),
)

# Call this when the local SSE connection needs to be stopped.
# call.cancel()
```

## VLX-VR Streaming Example

```python
from omai_client import (
    VlxApiClient,
    VlxVrContent,
    VlxVrMessage,
    VlxVrStopRequest,
    VlxVrStreamEventMessageHandler,
    VlxVrStreamRequest,
    VlxVrVideoUrl,
)


class VrHandler(VlxVrStreamEventMessageHandler):
    def __init__(self, stop_id_ref):
        self.stop_id_ref = stop_id_ref

    def on_event(self, message):
        if message.done:
            print("VR stream done")
            return

        chunk = message.chunk
        if chunk is None:
            return

        # conversationCreated and later delta events use the same chatcmpl-* id.
        if message.event == "conversationCreated":
            self.stop_id_ref["value"] = chunk.id
            print("conversationId:", self.stop_id_ref["value"])
        if message.event == "delta" and chunk.choices:
            delta = chunk.choices[0].delta
            if delta:
                print(delta.reasoning_content or delta.content or "")

    def on_error(self, throwable):
        print("error:", throwable)

    def on_closed(self):
        print("closed")


client = VlxApiClient.from_env()
request = VlxVrStreamRequest(
    model="vlx-vr",
    messages=[
        VlxVrMessage(
            role="user",
            content=[
                VlxVrContent(type="text", text="Which ball sport is shown in the video?"),
                VlxVrContent(
                    type="video_url",
                    video_url=VlxVrVideoUrl(url="https://example.com/tennis.mp4"),
                ),
            ],
        )
    ],
    stream=True,
    thinking=True,
    reasoning_effort="medium",
    temperature=0.7,
)

stop_id_ref = {"value": None}
handler = VrHandler(stop_id_ref)
call = client.vlx_vr_stream_message(request, handler)
call.join()

# Stop the server-side task with the chatcmpl-* id from conversationCreated.
if stop_id_ref["value"]:
    client.vlx_vr_stop(VlxVrStopRequest(conversationId=stop_id_ref["value"]))
```

`message.chunk` represents the normalized `chat.completion.chunk` response, and `message.done` is true for `data: [DONE]`. Use `vlx_vr_stream` when raw SSE envelope fields are needed, or `vlx_vr_stream_raw` to consume the response body yourself.


