> ## Documentation Index
> Fetch the complete documentation index at: https://docs.adaptive-ml.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Interactions

> Manage interactions on Adaptive Interaction Store

An interaction is the combination of a prompt, a model's completion, and optionally feedback and metadata (such as labels).

When you make an [inference request](/v0.5/guides/inference) to Adaptive, the resulting interaction is automatically logged to the Adaptive Interaction Store.
You can also log interactions ad-hoc for an existing model that is attached to a use case, which is useful for evaluation or [model tuning](/v0.5/fine-tuning/adapt).

You can log interactions as follows:

<Info>
  [Create](/v0.5/concepts/authentication) an `Adaptive` client first
</Info>

<CodeGroup>
  ```python Adaptive SDK theme={null}
  response = adaptive.interactions.create(
      model="model_key",
      completion="Model's completion",
      messages=[
          {"role": "system", "content": "System prompt"},
          {"role": "user", "content":"User input"}    
      ],
      feedbacks=[
          {"feedback_key": "metric_key_1", "value": 0, "details": "Feedback details 1"},
          {"feedback_key": "metric_key_2", "value": 1, "details": "Feedback details 2"}
      ]
      labels={"label_key": "label_value"}
  )
  ```

  ```python requests theme={null}
  import requests

  headers = {"Authorization": "Bearer ADAPTIVE_API_KEY"}
  payload = { 
      "model_service": "model_key",
      "use_case": "use_case_key",
      "completion": "Model's completion"
      "messages": [
          {"role": "system", "content": "System prompt"},
          {"role": "user", "content":"User input"}    
      ],
      "feedbacks": [
          {"metric": "metric_key_1", "value": 0, "details": "Feedback details 1"},
          {"metric": "metric_key_2", "value": 1, "details": "Feedback details 2"}
      ]
      "labels": {"label_key": "label_value"}
  }

  response = requests.post(
    url="ADAPTIVE_URL/api/v1/interactions",
    json=payload,
    headers=headers
  )
  ```
</CodeGroup>

***

<Accordion title="Load large dataset asynchronously">
  ```python Adaptive SDK theme={null}
      from adaptive_sdk import Adaptive, AsyncAdaptive
      import json
      import asyncio
      from tqdm.asyncio import tqdm_asyncio
      from tqdm import tqdm

      async def upload_data_async(
          adaptive: AsyncAdaptive,
          data: list[dict], 
          labels: dict[str,str],
          max_concurrency: int = 30
      ):
          async def coroutine(semaphore, coroutine):
              async with semaphore:
                  return await coroutine

          semaphore = asyncio.Semaphore(max_concurrency)
          coroutines = []
          for i in data:
              coroutines.append(
                  coroutine(
                      semaphore,
                      adaptive.interactions.create(
                          messages=i["messages"],
                          completion=i["completion"],
                          labels=labels
                      ),
                  )
              )

          print("\nLoading data...")
          results = await tqdm_asyncio.gather(*coroutines)

      if __name__=="__main__":
          url = "REPLACE_ADAPTIVE_URL"
          api_key = "REPLACE_ADAPTIVE_API_KEY"
          use_case_key = "REPLACE_EXISTING_USE_CASE"

          # `data` is assumed to have this format
          data = [
              {
                  "messages": [
                      {"role": "system", "content": "You are a good bot."},
                      {"role": "user", "content": "Hey there!"}
                  ],
                  "completion": "Hey back at you!"
              }
          ]
          labels = {"dataset": "my_custom_dataset"}
          
          adaptive = AsyncAdaptive(base_url=url, api_key=api_key)
          adaptive.set_default_use_case(use_case_key)
          asyncio.run(upload_data_async(adaptive, data, labels))
  ```
</Accordion>

All automatically or manually logged interactions can be explored in the Interactions page of the Adaptive UI.

You can also retrieve interactions programmatically via SDK for ad-hoc analysis. See the [SDK Reference](/v0.5/sdk-reference/reference) for all interaction-related methods.
