|
6 | 6 | from azure.search.documents.models import VectorizedQuery
|
7 | 7 | from openai.types.chat import ChatCompletion
|
8 | 8 |
|
| 9 | +from approaches.approach import Document |
9 | 10 | from approaches.chatreadretrieveread import ChatReadRetrieveReadApproach
|
10 | 11 | from approaches.promptmanager import PromptyManager
|
11 | 12 | from prepdocslib.embeddings import ImageEmbeddings
|
@@ -255,3 +256,52 @@ async def test_compute_multimodal_embedding_no_client():
|
255 | 256 | # Test that calling compute_multimodal_embedding raises a ValueError
|
256 | 257 | with pytest.raises(ValueError, match="Approach is missing an image embeddings client for multimodal queries"):
|
257 | 258 | await chat_approach.compute_multimodal_embedding("What's in this image?")
|
| 259 | + |
| 260 | + |
| 261 | +@pytest.mark.asyncio |
| 262 | +async def test_chat_prompt_render_with_image_directive(chat_approach): |
| 263 | + """Verify DocFX style :::image directive is sanitized (replaced with [image]) during prompt rendering.""" |
| 264 | + image_directive = ( |
| 265 | + "activator-introduction.md#page=1: Intro text before image. " |
| 266 | + ':::image type="content" source="./media/activator-introduction/activator.png" ' |
| 267 | + 'alt-text="Diagram that shows the architecture of Fabric Activator."::: More text after image.' |
| 268 | + ) |
| 269 | + |
| 270 | + async def build_sources(): |
| 271 | + return await chat_approach.get_sources_content( |
| 272 | + [ |
| 273 | + Document( |
| 274 | + id="doc1", |
| 275 | + content=image_directive.split(": ", 1)[1], |
| 276 | + sourcepage="activator-introduction.md#page=1", |
| 277 | + sourcefile="activator-introduction.md", |
| 278 | + ) |
| 279 | + ], |
| 280 | + use_semantic_captions=False, |
| 281 | + include_text_sources=True, |
| 282 | + download_image_sources=False, |
| 283 | + user_oid=None, |
| 284 | + ) |
| 285 | + |
| 286 | + data_points = await build_sources() |
| 287 | + |
| 288 | + messages = chat_approach.prompt_manager.render_prompt( |
| 289 | + chat_approach.answer_prompt, |
| 290 | + { |
| 291 | + "include_follow_up_questions": False, |
| 292 | + "past_messages": [], |
| 293 | + "user_query": "What is Fabric Activator?", |
| 294 | + "text_sources": data_points.text, |
| 295 | + "image_sources": data_points.images, |
| 296 | + "citations": data_points.citations, |
| 297 | + }, |
| 298 | + ) |
| 299 | + assert messages |
| 300 | + # Find the user message containing Sources and verify placeholder |
| 301 | + combined = "\n".join([m["content"] for m in messages if m["role"] == "user"]) |
| 302 | + # Expect triple colons escaped |
| 303 | + assert ":::image" in combined |
| 304 | + assert "activator-introduction/activator.png" in combined |
| 305 | + assert "Diagram that shows the architecture of Fabric Activator." in combined |
| 306 | + # Original unescaped sequence should be gone |
| 307 | + assert ":::image" not in combined |
0 commit comments