@@ -31,12 +31,13 @@ class ChatMessageExtension(Extension):
3131 """
3232 A Jinja2 extension for creating structured chat messages with mixed content types.
3333
34- This extension provides a custom {% message %} tag that allows creating chat messages
34+ This extension provides a custom ` {% message %}` tag that allows creating chat messages
3535 with different attributes (role, name, meta) and mixed content types (text, images, etc.).
3636
3737 Inspired by [Banks](https://github.com/masci/banks).
3838
3939 Example:
40+ ```
4041 {% message role="system" %}
4142 You are a helpful assistant. You like to talk with {{user_name}}.
4243 {% endmessage %}
@@ -47,9 +48,10 @@ class ChatMessageExtension(Extension):
4748 {{ image | templatize_part }}
4849 {% endfor %}
4950 {% endmessage %}
51+ ```
5052
5153 ### How it works
52- 1. The {% message %} tag is used to define a chat message.
54+ 1. The ` {% message %}` tag is used to define a chat message.
5355 2. The message can contain text and other structured content parts.
5456 3. To include a structured content part in the message, the `| templatize_part` filter is used.
5557 The filter serializes the content part into a JSON string and wraps it in a `<haystack_content_part>` tag.
@@ -121,7 +123,7 @@ def _build_chat_message_json(self, role: str, name: Optional[str], meta: dict, c
121123 """
122124 Build a ChatMessage object from template content and serialize it to a JSON string.
123125
124- This method is called by Jinja2 when processing a {% message %} tag.
126+ This method is called by Jinja2 when processing a ` {% message %}` tag.
125127 It takes the rendered content from the template, converts XML blocks into ChatMessageContentT objects,
126128 creates a ChatMessage object and serializes it to a JSON string.
127129
@@ -151,12 +153,12 @@ def _parse_content_parts(content: str) -> List[ChatMessageContentT]:
151153
152154 This method handles:
153155 - Plain text content, converted to TextContent objects
154- - Structured content parts wrapped in <haystack_content_part> tags, converted to ChatMessageContentT objects
156+ - Structured content parts wrapped in ` <haystack_content_part>` tags, converted to ChatMessageContentT objects
155157
156158 :param content: Input string containing mixed text and content parts
157159 :return: A list of ChatMessageContentT objects
158160 :raises ValueError: If the content is empty or contains only whitespace characters or if a
159- <haystack_content_part> tag is found without a matching closing tag.
161+ ` <haystack_content_part>` tag is found without a matching closing tag.
160162 """
161163 if not content .strip ():
162164 raise ValueError (
0 commit comments