Logging Data Formats for Conversations

This section details the various logging formats that can be used within the library. It includes descriptions of each formats and how to use them effectively

When logging data for conversations, there are three possible formats: Chat History, Chat History with Conversation ID, and Chat Graph. Each format has specific keys and structures to capture different levels of detail and context. Below is a detailed explanation of each format:

Logging Data individually

1. By Chat History

The chat_history format is a straightforward way to log a sequence of messages exchanged between participants in a conversation. It captures the role and content of each message, with an optional context for additional information.

Structure:

chat_history: A list of dictionaries, each representing a message.

role: The role of the participant (e.g., “user”, “assistant”). Must be a string.

content: The content of the message. Must be a string.

context (Optional): The context of the message. Must be a list of pairs of strings in the format [["", ""]...].

{
  "chat_history": [
    {"role": "user", "content": "How do I implement a neural network in Python?"},
    {"role": "assistant", "content": "To implement a neural network in Python, you can use libraries like TensorFlow or PyTorch. Here’s a simple example using PyTorch..."}
  ]
}

Description:

Role: Indicates who sent the message (e.g., user or assistant).

Content: The actual message sent.

Context: (Optional) Additional information that may provide background or supporting data for the message.

2. By Chat History with Conversation ID

This format adds a conversation_id to the chat_history, allowing for the identification of specific conversations.

Structure:

conversation_id: The ID of the conversation. Must be a string.

chat_history: A list of dictionaries, each representing a message.

role: The role of the participant (e.g., “user”, “assistant”). Must be a string.

content: The actual message sent.

context (Optional): The context of the message. Must be a list of pairs of strings in the format [["", ""]...].

{
  "conversation_id": "123456",
  "chat_history": [
    {"role": "user", "content": "How do I implement a neural network in Python?"},
    {"role": "assistant", "content": "To implement a neural network in Python, you can use libraries like TensorFlow or PyTorch. Here’s a simple example using PyTorch..."}
  ],
  "context": [ [str ,str] ] #format [ ["",""] , ["",""]]
}

Description:

Conversation ID: Unique identifier for the conversation, allowing for easy retrieval and association of messages.

Role: Indicates who sent the message.

Content: The message content, which can include text and images.

Context: (Optional) Additional information providing background or supporting data for the message.

3. By Chat History with Conversation ID For Multimodel AI

This format adds a conversation_id to the chat_history, allowing for the identification of specific conversations. It also supports a richer content structure, including text and image URLs.

Structure:

conversation_id: The ID of the conversation. Must be a string.

chat_history: A list of dictionaries, each representing a message.

role: The role of the participant (e.g., “user”, “assistant”). Must be a string.

content: The content of the message. Can be a list of dictionaries with different content types (e.g., text, image_url).

{
  "conversation_id": "123456",
  "chat_history": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "How do I implement a neural network in Python?"},
        {"type": "image_url", "image_url": {"url": "source_img_url"}}
      ]
    },
    {
      "role": "assistant",
      "content": [
        {"type": "text", "text": "To implement a neural network in Python, you can use libraries like TensorFlow or PyTorch. Here’s a simple example using PyTorch..."}
      ]
    }
  ]
}

Description:

Conversation ID: Unique identifier for the conversation, allowing for easy retrieval and association of messages.

Role: Indicates who sent the message.

Content: The message content, which can include text and images.

Logging Data All At Once

1. By Chat Graph

The chat_graph format captures the hierarchical structure of a conversation, showing the relationships between messages. Each message is a node in the graph, with links to parent nodes, providing a detailed view of the conversation flow.

Structure:

conversation_id: The ID of the conversation. Must be a string.

nodes: A list of nodes, each representing a message in the conversation graph.

node_id: The ID of the node. Must be a string.

parent_id: The ID of the parent node. Must be a string (or null for root nodes).

timestamp: The timestamp of the node. Must be an integer.

message: A dictionary with the message details.

id: The ID of the message. Must be a string.

author: Information about the message author.

role: The role of the author (e.g., “user”, “assistant”). Must be a string.

metadata: Additional metadata about the author.

content: The content of the message.

content_type: The type of content (e.g., “text”).

parts: A list of content parts (e.g., text segments).

context: (Optional) The context of the message. Must be a list of pairs of strings in the format [["", ""]...].

{
  "conversation_id": "123456",
  "nodes": [
    {
      "node_id": "node-1",
      "parent_id": null,
      "timestamp": 1625216400,
      "message": {
        "id": "message-1",
        "author": {
          "role": "user",
          "metadata": {}
        },
        "content": {
          "content_type": "text",
          "parts": ["How do I implement a neural network in Python?"]
        },
        "context": [["", ""]]
      }
    },
    {
      "node_id": "node-2",
      "parent_id": "node-1",
      "timestamp": 1625216460,
      "message": {
        "id": "message-2",
        "author": {
          "role": "assistant",
          "metadata": {}
        },
        "content": {
          "content_type": "text",
          "parts": ["To implement a neural network in Python, you can use libraries like TensorFlow or PyTorch. Here’s a simple example using PyTorch..."]
        },
        "context": [["", ""]]
      }
    }
  ]
}

Description:

Conversation ID: Unique identifier for the conversation.

Nodes: List of messages in the conversation, structured as nodes in a graph.

Node ID: Unique identifier for each node.

Parent ID: Indicates the parent node, establishing the hierarchy. Root nodes have null as the parent ID.

Timestamp: Time when the message was created.

Message: Contains details of the message, including the author, content, and optional context.

Each format serves different purposes, from simple sequential logging to detailed hierarchical representation, enabling you to choose the best structure for your needs.

Last updated