RedaktAIDocs
Auto-Generated

Format Helpers

Provider-agnostic SSE content extraction and manipulation

Utility functions for extracting and setting text content in provider-specific SSE event formats and full response bodies.

from rdakt_ai import extract_sse_content, set_sse_content, extract_response_content

extract_sse_content

Extract text content from a parsed SSE event data dict.

def extract_sse_content(data: dict) -> str | None

Handles all three provider formats:

ProviderPath
OpenAIchoices[0].delta.content
Anthropicdelta.text (for content_block_delta events)
Geminicandidates[0].content.parts[0].text

Returns None if no text content is found.

set_sse_content

Set text content in a parsed SSE event data dict.

def set_sse_content(data: dict, content: str) -> dict

Modifies the dict in-place and returns it. Detects the provider format automatically.

extract_response_content

Extract text content from a full (non-streaming) response body.

def extract_response_content(body: dict) -> str | None

Handles:

  • OpenAI: choices[0].message.content
  • Anthropic: content[0].text
  • Gemini: candidates[0].content.parts[0].text

On this page