class GraphicPlaceholder
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.
/tf/active/vicechatdev/e-ink-llm/hybrid_response_handler.py
23 - 29
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 graphicgraphic_type: Type of graphic to generatedescription: Human-readable description of the graphicparameters: Dictionary of generation parametersposition_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
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class HybridResponse 68.7% similar
-
function demo_placeholder_parsing 68.5% similar
-
class GraphicSpec 59.3% similar
-
class HybridPromptEnhancer 58.7% similar
-
function test_placeholder_parsing 57.9% similar