🔍 Code Extractor

class GraphicPlaceholder

Maturity: 44

A dataclass that represents a placeholder for graphics (charts, diagrams, etc.) embedded within text responses, storing metadata about the graphic's type, description, parameters, and position.

File:
/tf/active/vicechatdev/e-ink-llm/hybrid_response_handler.py
Lines:
23 - 29
Complexity:
simple

Purpose

GraphicPlaceholder serves as a data container for tracking where graphics should be inserted in text-based responses. It stores all necessary information to identify, describe, and generate a graphic at a specific location, including a unique identifier, the type of graphic, descriptive text, generation parameters, and a position marker for text replacement. This class is typically used in document generation workflows where text and graphics need to be coordinated.

Source Code

class GraphicPlaceholder:
    """Represents a graphic placeholder in the text response"""
    id: str
    graphic_type: str
    description: str
    parameters: Dict[str, Any]
    position_marker: str

Parameters

Name Type Default Kind
bases - -

Parameter Details

id: A unique string identifier for this graphic placeholder, used to reference and track the specific graphic instance throughout the document generation process

graphic_type: A string specifying the type of graphic to be generated (e.g., 'chart', 'diagram', 'graph'). This determines which generation method will be used

description: A human-readable string describing what the graphic represents or displays, useful for documentation and accessibility purposes

parameters: A dictionary containing key-value pairs of configuration parameters needed to generate the specific graphic. The structure depends on the graphic_type and may include data, styling options, dimensions, etc.

position_marker: A string marker that indicates where in the text this graphic should be inserted or replaced, typically a unique placeholder string like '[GRAPHIC_1]'

Return Value

Instantiating GraphicPlaceholder returns an instance of the class with all five attributes (id, graphic_type, description, parameters, position_marker) set to the provided values. As a dataclass, it automatically generates __init__, __repr__, and __eq__ methods.

Class Interface

Methods

__init__(self, id: str, graphic_type: str, description: str, parameters: Dict[str, Any], position_marker: str) -> None

Purpose: Initializes a new GraphicPlaceholder instance with all required attributes. Auto-generated by the dataclass decorator.

Parameters:

  • id: Unique identifier for the graphic
  • graphic_type: Type of graphic to generate
  • description: Human-readable description of the graphic
  • parameters: Dictionary of generation parameters
  • position_marker: Text marker indicating insertion position

Returns: None (constructor)

__repr__(self) -> str

Purpose: Returns a string representation of the GraphicPlaceholder instance showing all attributes. Auto-generated by the dataclass decorator.

Returns: String representation in the format 'GraphicPlaceholder(id=..., graphic_type=..., ...)'

__eq__(self, other: object) -> bool

Purpose: Compares two GraphicPlaceholder instances for equality based on all attributes. Auto-generated by the dataclass decorator.

Parameters:

  • other: Another object to compare with

Returns: True if all attributes are equal, False otherwise

Attributes

Name Type Description Scope
id str Unique identifier for this graphic placeholder instance instance
graphic_type str Type of graphic to be generated (e.g., 'chart', 'diagram', 'graph') instance
description str Human-readable description of what the graphic represents instance
parameters Dict[str, Any] Dictionary containing all parameters needed to generate the graphic instance
position_marker str Unique marker string indicating where in the text this graphic should be inserted instance

Dependencies

  • dataclasses

Required Imports

from dataclasses import dataclass
from typing import Dict, Any

Usage Example

from dataclasses import dataclass
from typing import Dict, Any

@dataclass
class GraphicPlaceholder:
    id: str
    graphic_type: str
    description: str
    parameters: Dict[str, Any]
    position_marker: str

# Create a placeholder for a bar chart
placeholder = GraphicPlaceholder(
    id="chart_001",
    graphic_type="bar_chart",
    description="Sales data by quarter",
    parameters={
        "data": [100, 150, 200, 175],
        "labels": ["Q1", "Q2", "Q3", "Q4"],
        "title": "Quarterly Sales",
        "width": 800,
        "height": 600
    },
    position_marker="[GRAPHIC_chart_001]"
)

# Access attributes
print(placeholder.id)  # "chart_001"
print(placeholder.graphic_type)  # "bar_chart"
print(placeholder.parameters["title"])  # "Quarterly Sales"

# Dataclass provides automatic equality checking
placeholder2 = GraphicPlaceholder(
    id="chart_001",
    graphic_type="bar_chart",
    description="Sales data by quarter",
    parameters={"data": [100, 150, 200, 175], "labels": ["Q1", "Q2", "Q3", "Q4"], "title": "Quarterly Sales", "width": 800, "height": 600},
    position_marker="[GRAPHIC_chart_001]"
)
print(placeholder == placeholder2)  # True

Best Practices

  • Use unique and descriptive IDs to avoid conflicts when multiple graphics are present in the same document
  • Ensure the graphic_type matches the types supported by your graphics generation system (GraphicsGenerator in this codebase)
  • The position_marker should be a unique string that won't accidentally match regular text content
  • Store all necessary generation parameters in the parameters dictionary to enable complete graphic recreation
  • Keep the description field meaningful for accessibility and documentation purposes
  • Since this is a dataclass, all attributes are required at instantiation unless default values are provided
  • The parameters dictionary should be JSON-serializable if you need to persist or transmit placeholders
  • Consider validating the parameters dictionary structure based on graphic_type to catch errors early
  • This class is immutable by default (dataclass without frozen=True), but attributes can be modified after creation if needed

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class HybridResponse 68.7% similar

    A dataclass that encapsulates a complete hybrid response containing both text content and graphical elements with their placeholders and metadata.

    From: /tf/active/vicechatdev/e-ink-llm/hybrid_response_handler.py
  • function demo_placeholder_parsing 68.5% similar

    Demonstrates the parsing of graphics placeholders embedded in text by extracting and displaying placeholder metadata including type, description, ID, and parameters.

    From: /tf/active/vicechatdev/e-ink-llm/demo_hybrid_mode.py
  • class GraphicSpec 59.3% similar

    A dataclass that defines the specification for a graphic to be generated, including its type, description, parameters, style preferences, and optional image data.

    From: /tf/active/vicechatdev/e-ink-llm/graphics_generator.py
  • class HybridPromptEnhancer 58.7% similar

    A utility class that enhances LLM prompts by adding instructions and formatting guidelines to encourage hybrid text+graphics responses with embedded graphic placeholders.

    From: /tf/active/vicechatdev/e-ink-llm/hybrid_response_handler.py
  • function test_placeholder_parsing 57.9% similar

    A unit test function that validates the placeholder parsing functionality of the HybridResponseHandler class by testing its ability to extract and parse graphic placeholders from formatted text.

    From: /tf/active/vicechatdev/e-ink-llm/test_hybrid_mode.py
← Back to Browse