Skip to content
Intura

Use a model

Async

AsyncIntura for an asyncio program: the download is awaited, the prediction is the same CPU-bound LocalModel.

AsyncIntura

python
from intura_ai import AsyncIntura

async with AsyncIntura() as client:
    model = await client.models.load("chat-commerce-intent-id")

model.predict("ongkirnya berapa?")

AsyncIntura takes the same arguments as Intura and has the same two resources: client.models (load, list, links, download) and client.library (list). Every one of those is awaited.

Only the API calls and the download are awaited. Reading the model from disk happens once and is synchronous, and predict is the same CPU-bound LocalModel method as in the sync client. That is why the model above is used after the async with block: it holds no connection, so closing the client doesn't affect it.

Large batches in an event loop

predict runs on the CPU and blocks while it does. Inside an event loop, hand a large batch to a thread:

python
import asyncio

results = await asyncio.to_thread(model.predict_batch, texts)

Closing the client

async with closes the client's connection pool for you. Without it, call await client.aclose() when you are done. A client you pass your own httpx.AsyncClient to never closes it; see Configuration.