Skip to main content
An interaction is a prompt, completion, and any associated feedback or labels. Adaptive logs interactions automatically when you run inference, creating a record you can browse, filter, and use for training.

Automatic logging

Inference requests are logged automatically:
response = adaptive.chat.create(
    messages=[
        {"role": "user", "content": "Hello!"}
    ],
    labels={"project": "support-bot", "version": "v2"},
)
Use labels to organize interactions. Labels are key-value pairs for filtering and grouping.

Get the completion ID

Extract completion_id from the response to log feedback:
completion_id = response.choices[0].completion_id
Pass this ID to Feedback methods to associate ratings with the interaction.

Manual logging

Log interactions for completions generated outside Adaptive:
adaptive.interactions.create(
    model="model_key",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ],
    completion="Hi there! How can I help you today?",
    labels={"source": "external"},
)
Use manual logging to import historical data or log completions from external models.
Upload large datasets efficiently with async concurrency:
import asyncio
from adaptive_sdk import AsyncAdaptive

async def upload_data(data: list[dict], labels: dict, max_concurrency: int = 30):
    adaptive = AsyncAdaptive(
        base_url=os.environ["ADAPTIVE_URL"],
        api_key=os.environ["ADAPTIVE_API_KEY"],
    )
    adaptive.set_default_use_case("my-use-case")

    semaphore = asyncio.Semaphore(max_concurrency)

    async def upload_one(item):
        async with semaphore:
            await adaptive.interactions.create(
                messages=item["messages"],
                completion=item["completion"],
                labels=labels,
            )

    await asyncio.gather(*[upload_one(item) for item in data])

# Example data format
data = [
    {
        "messages": [{"role": "user", "content": "Hello!"}],
        "completion": "Hi there!"
    }
]
asyncio.run(upload_data(data, labels={"dataset": "training-v1"}))
See SDK Reference for all interaction methods.