Skip to content

Summarize Inference

Provides a concise summary of the given input, which can be text, a document, an image, or a web page. This inference type is useful for generating summaries of various content types.

Endpoint

POST /infer

Request Body

Field Type Description
infer_type string Must be set to "summarize" for summarize inference.
infer_params object Parameters for the summarize inference.
stream_type string Specifies the streaming behavior. Options: "disabled", "enabled", "per_value". Default is "enabled".

infer_params object

Field Type Description
data string or object The main data to be summarized. Can be text, a URI, base64 encoded data, or a structured object.
type string Specifies the type of data being sent to ensure correct parsing.
max_length integer (Optional) The maximum length of the summary in tokens or characters.
min_length integer (Optional) The minimum length of the summary in tokens or characters.
focus_on string (Optional) Specific aspect or topic to focus on in the summary.
specialised_model string (Optional) The name of a specialised model to use for summarization.
metadata object (optional) Additional metadata about the content to be summarized.

Possible type values

Type Description Use Case
plain_text Raw text content Articles, blog posts
document_uri URL pointing to the document Web pages, remotely hosted documents
base64 Base64 encoded document data Binary files, images
structured JSON or other structured data API responses, database exports

Usage Examples

Summarize Plain Text

{
  "infer_type": "summarize",
  "infer_params": {
    "data": "Artificial intelligence (AI) is a wide-ranging branch of computer science concerned with building smart machines capable of performing tasks that typically require human intelligence. AI encompasses various subfields, including machine learning, natural language processing, computer vision, and robotics. These technologies are being applied across industries to automate processes, enhance decision-making, and create innovative products and services.",
    "type": "plain_text",
    "max_length": 50,
    "min_length": 20
  },
  "stream_type": "enabled"
}

Summarize a Web Page

{
  "infer_type": "summarize",
  "infer_params": {
    "data": "https://example.com/article/introduction-to-ai",
    "type": "document_uri",
    "focus_on": "key concepts and applications",
    "metadata": {
      "title": "Introduction to Artificial Intelligence",
      "author": "Jane Doe",
      "publication_date": "2024-03-15"
    }
  },
  "stream_type": "enabled"
}

Summarize an Image

{
  "infer_type": "summarize",
  "infer_params": {
    "data": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4Q...",
    "type": "base64",
    "specialised_model": "vision_language_model_v1",
    "metadata": {
      "title": "AI Conference Keynote",
      "description": "Image of a speaker presenting at an AI conference",
      "date": "2024-05-20"
    }
  },
  "stream_type": "disabled"
}

Summarize a PDF Document

{
  "infer_type": "summarize",
  "infer_params": {
    "data": "https://example.com/documents/ai_whitepaper.pdf",
    "type": "document_uri",
    "max_length": 200,
    "focus_on": "main findings and conclusions",
    "metadata": {
      "title": "AI Impact on Industries: A Comprehensive Study",
      "author": "Research Team XYZ",
      "publication_date": "2024-01-10",
      "content_type": "application/pdf"
    }
  },
  "stream_type": "enabled"
}

Response

The response is streamed back to the client based on the stream_type specified in the request.

Stream Types

Stream Type Description Use Case
disabled Returns the entire summary at once When the client can process the entire summary in one go.
enabled Streams the summary in chunks When the summary is too large to be processed at once.
per_value Streams each sentence or paragraph separately When the client needs to process each part of the summary individually.

Response Structure

Field Type Description
key string The key for the streamed data (e.g., "summary").
value string The content of the summary or a chunk of it.
stream_status string Indicates the status of the stream. Can be "stream_running" or "stream_over".

Sample Response

{
  "key": "summary",
  "value": "The AI conference keynote image shows a speaker presenting to a large audience. The speaker is standing on a stage with a large screen behind them displaying AI-related graphics. The audience appears engaged, with many taking notes. This suggests a significant event in the AI community, potentially discussing cutting-edge developments or future trends in artificial intelligence.",
  "stream_status": "stream_over"
}

Error Responses

  • 400 Bad Request: Invalid input data
    • Examples:
      • Missing required parameters
      • Invalid infer_type
      • Invalid stream_type
      • Unsupported data type
      • Invalid document URI
  • 404 Not Found: Specified document or image not found
  • 413 Payload Too Large: Input data exceeds the allowed size limit
  • 500 Internal Server Error: Unexpected error during summarization process

Note: The summarize inference API supports various content types, including text, web pages, images, and documents. For non-text inputs (like images or complex documents), it may use specialized models (e.g., vision language models) to generate appropriate summaries. In a production environment, this would integrate with sophisticated natural language processing and computer vision models tailored for different types of content summarization.