Context.ai
  • What is Context.ai?
  • List of Trackable Metrics
  • Product Analytics
    • Overview
    • Topic Categorisation
      • LLM Topics
    • User Engagement Tracking
    • Foreign Language Support
    • PII Filtering
    • Custom Metadata Filtering
    • Backfill Analytics Data
    • Custom Events
    • API Ingestion Methods
      • Log Conversation
      • [deprecated] Upsert Conversation
      • Thread Conversation
      • Patch Thread Message
      • API Resources
        • Chat Message
        • [deprecated] Tool Message
        • Custom Event
        • Metadata
        • Conversation
        • Thread
    • Embedded API
      • Multi-Tenancy
      • Conversations
        • Series Data
  • Integrations
    • Getting Started
    • Python SDK
    • Javascript SDK
    • LangChain Plugin
    • Haystack Plugin
    • Authorization
Powered by GitBook
On this page
  • Log a thread conversation
  • Example Request
  • Example Response

Was this helpful?

  1. Product Analytics
  2. API Ingestion Methods

Thread Conversation

Previous[deprecated] Upsert ConversationNextPatch Thread Message

Last updated 10 months ago

Was this helpful?

Unlike , with thread conversation, you do not need to send us the entire transcript each time that you have new messages in your LLM conversations. As the conversation progresses, you only need to send us the new messages alongside the thread conversation identifier and we will append these messages to the corresponding conversation transcript in Context.ai.

The semantics of thread conversation are: If a conversation request is received without the id property, a new thread conversation is created and the corresponding identifier is returned. For all subsequent appends to this thread conversation, the user is expected to send this identifier in the request. If a conversation request has the id property, the messages are appended to the conversation matching that id.

To use thread conversation, you must:

  1. Always use the same id when appending messages to an existing thread conversation.

  2. Always include the same metadata on each thread conversation log request.

Log a thread conversation

POST https://api.context.ai/api/v1/log/conversation/thread

Records a thread conversation in Context.ai.

Request Body

Name
Type
Description

thread*

Object

A Thread object.

{ 
    "status": "ok",
    "data": {
        "id": "custom_id"
        "appended_messages": [
            {
                "id": "e_aeglcefpnoqeumu",
                "role": "assistant",
                "message": "Can I help you with something?",
                "rating": "neutral"
            }
        ]
    }
}

{
    "status": "failed",
    "error": "Metadata for thread with id:<id> does not match this conversation."
}

Example Request

{
  "conversation": {
    "id": "custom_id"
    "messages": [
      {
        "role": "system",
        "message": "You are a LLM providing information about a local football club.",
        "event_timestamp": "2020-02-20T20:20:23Z"
      },
      {
        "role": "user",
        "message": "What time does the team arrive?",
        "event_timestamp": "2020-02-20T20:21:34Z"
      },
      {
        "role": "assistant",
        "message": "I'm not sure what time the team arrives.",
        "event_timestamp": "2020-02-20T23:20:40Z",
        "rating": -1
      }
    ],
    "metadata": {
      "model": "gpt-3.5-turbo-16k",
      "user_id": "2947451"
    }
  }
}

Example Response

{
    "status": "ok",
    "data": {
        "id": "c_djncroenvory"
        "provided_id": "custom_id",
        "appended_messages": [
            {
                "id": "e_aeglcefpnoqeumu",
                "role": "system",
                "message": "You are a LLM providing information about a local football club.",
                "rating": "neutral"
            },
            {
                "id": "e_alkdmnvllmvqcmu",
                "role": "user",
                "message": "What time does the team arrive?",
                "rating": "neutral"
            },
            {
                "id": "e_aubsjdiehysxop",
                "role": "assistant",
                "message": "I'm not sure what time the team arrives.",
                "rating": "thumbs_down"
            },
        ]
    }
}

Upsert Conversation