Skip to main content
The ChatEntity represents a structured data object used in chat completions to encapsulate specific information extracted from user inputs or external sources. It is designed to facilitate the processing and understanding of complex data within conversational AI applications.

Definition

Below is the interface definition for the ChatEntity:
ChatEntity
interface ChatEntity {
  messages: Array<{
    role: 'user' | 'assistant' | 'system';
    content: string;
  }>;
  output: Record<string, any>;
}
PropertyTypeDescription
messagesArrayAn array of message objects representing the conversation history. Each message includes a role and content.
outputRecordOptional JSON Schema (Draft 7) that defines the expected structure of the response.
messages Property:
PropertyTypeDescription
roleuser, assistant, systemThe role of the message sender. Can be user for user messages, assistant for AI responses, or system for system-level messages.
contentstringThe actual text content of the message.
Currently only the user role is allowed.
output Property: The output property is an optional JSON Schema that defines the expected structure of the response generated by the chat completion. It enables developers to specify the format and constraints of the output data, ensuring that responses adhere to a predefined schema. Below are some useful resources to help you get started with structured output:

Examples

Below are several practical examples demonstrating how to use the ChatEntity in different scenarios.

Basic Example

This example demonstrates a simple chat interaction using the ChatEntity without any structured output.
{
  "messages": [
    {
      "role": "user",
      "content": "What is search volume for telefonbox in Germany?"
    }
  ]
}

Structured Output Example

This example demonstrates how to use the ChatEntity with a structured output defined by a JSON Schema.
{
  "messages": [
    {
      "role": "user",
      "content": "Extract the full name, bio, position, email address, and LinkedIn profile URL from the following webpage: https://www.evergreen.media/team/adnan-ali/"
    }
  ],
  "output": {
    "type": "object",
    "properties": {
      "name": { "type": "string" },
      "bio": { "type": "string" },
      "position": { "type": "string" },
      "email": { "type": "string" },
      "linkedin": { "type": "string" }
    },
    "required": ["name", "bio", "position", "email", "linkedin"]
  }
}

Use Case Examples

We will now explore several practical use cases demonstrating how to leverage the ChatEntity for various data extraction scenarios.

Get Search Volume

Retrieve the search volume for a specific keyword in a given country.
{
  "messages": [
    {
      "role": "user",
      "content": "What is search volume for the keyword 'Telefonbox' in Germany?"
    }
  ],
  "output": {
    "type": "object",
    "properties": {
      "searchVolume": {
        "type": "number"
      }
    },
    "required": ["searchVolume"]
  }
}

Get Reddit Comments

Extract two comments from the Reddit article sorted by the best rating.
{
  "messages": [
    {
      "role": "user",
      "content": "Please provide two comments from the Reddit article https://www.reddit.com/r/Ratschlag/comments/1n9sgt8/geld_für_die_kinder_anlegen/ sorted by the 'best' rating."
    }
  ],
  "output": {
    "type": "object",
    "properties": {
      "comments": {
        "type": "array",
        "items": {
          "type": "object",
          "description": "reddit comment",
          "properties": {
            "author": { "type": "string"  },
            "text": { "type": "string"  }
          },
          "required": ["author", "text"]
        }
      }
    },
    "required": ["comments"]
  }
}
Perform a web search for a specific keyword and return structured search results using Tedi completions with structured output.
{
  "messages": [
    {
      "role": "user",
      "content": "give me serp data for keyword 'Evergreen Media Ar GmbH' in Austria"
    }
  ],
  "output": {
    "type": "object",
    "properties": {
      "results": {
        "type": "array",
        "items": {
          "type": "object",
          "description": "search result",
          "properties": {
            "title": { "type": "string" },
            "description": { "type": "string" },
            "url": { "type": "string" }
          },
          "required": ["title", "description", "url"]
        }
      }
    },
    "required": [
      "results"
    ]
  }
}

Deep Research

Conduct in-depth research on a specific topic by visiting multiple web pages and extracting structured data using Tedi completions with structured output.
{
  "messages": [
    {
      "role": "user",
      "content": "Besuch meine Website https://evergreen.media und sag mir alle team namen, rollen und kontaktinformationen"
    }
  ],
  "output": {
    "type": "object",
    "properties": {
      "team": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "name": { "type": "string" },
            "role": { "type": "string"},
            "email": { "type": "string" },
            "linkedin": { "type": "string" }
          },
          "required": ["name", "role", "email", "linkedin"]
        }
      }
    },
    "required": ["team"]
  }
}

Without Structured Output

Use standard chat completions without structured output.
{
  "messages": [
    {
      "role": "user",
      "content": "What is search volume for keyword telefonbox in Germany?"
    }
  ]
}

Using Cache with ChatEntity

Enable caching for completions to speed up responses and reduce costs for repeated requests.
{
  "cache": {
    "enabled": true,
    "ttl": 180 // 3 minutes, max is 1 day (86400 seconds)
  },
  "messages": [
    {
      "role": "user",
      "content": "What is CPC for keyword telefonbox in Germany?"
    }
  ]
}

Conclusion

The ChatEntity is a powerful tool for structuring chat interactions and extracting specific information in a controlled manner. By leveraging the capabilities of structured output, developers can create more efficient and effective conversational AI applications. Tedi is specifically designed to perform SEO and market research tasks using structured data extraction techniques. Tedi is not a general-purpose model and may not perform well outside of its intended use cases.