Files
Changjian Wang f59d5c67d8 Python: Adopt azure-ai-contentunderstanding to_llm_input in CU context provider (#5796)
* Refactor DocumentEntry model and update result handling

- Changed the type of `result` in DocumentEntry from dict to str to store LLM-ready text.
- Introduced `search_payload` in DocumentEntry for optional alternate rendering.
- Updated FileSearchConfig to include `include_fields` option for vector store uploads.
- Modified tests to reflect changes in DocumentEntry and FileSearchConfig.
- Adjusted integration tests to validate new result structure and rendering.
- Removed legacy format_result tests as rendering is now handled by the SDK.

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Add test to ensure page markers are preserved in LLM input

Co-authored-by: Copilot <copilot@github.com>

* fix(cu-context-provider): scope LLMStats telemetry filter to rai_warnings block

Address PR #5796 review comment: the previous defensive scrubber ran a global regex substitution over the full rendered string, so any markdown body bullet shaped like '- LLMStats: ...' would also be silently deleted.

Add a _strip_rai_telemetry helper that confines the substitution to the front-matter rai_warnings: YAML sub-block, leaving the body verbatim. Cover the new behavior with three tests (scoped strip, body preservation, and no-op branches).

* Sync uv.lock with azure-ai-contentunderstanding>=1.2.0b1 dependency bump

* Python: Drop search_payload/include_fields, single to_llm_input rendering (CU context provider)

Address PR #5796 review: remove the redundant search_payload field and _render_search_payload helper, drop the include_fields opt-in (already covered by output_sections), rename _resolve_pending_tokens -> _resolve_pending_analysis, and have _upload_to_vector_store read entry['result'] directly.

* Python: Adopt SDK 1.2.0b2 LLMStats filtering, drop local workaround (CU context provider)

azure-ai-contentunderstanding 1.2.0b2 filters LLMStats telemetry from rai_warnings and emits InputPageNumber page markers in to_llm_input, so the provider's local defense is redundant.

- Bump dependency to azure-ai-contentunderstanding>=1.2.0b2 (re-lock uv.lock)

- Remove _strip_rai_telemetry and its two regexes; _render_for_llm now returns to_llm_input(...) directly

- Delete 4 workaround unit tests for the removed helper

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: changjian-wang <v-changjwang@microsoft.com>
Co-authored-by: aluneth <wangchangjian1130@163.com>
2026-06-18 01:57:41 +00:00

69 lines
2.6 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
from __future__ import annotations
from unittest.mock import AsyncMock
from agent_framework_azure_contentunderstanding._models import (
DocumentEntry,
DocumentStatus,
FileSearchConfig,
)
class TestDocumentEntry:
def test_construction(self) -> None:
entry: DocumentEntry = {
"status": DocumentStatus.READY,
"filename": "invoice.pdf",
"media_type": "application/pdf",
"analyzer_id": "prebuilt-documentSearch",
"analyzed_at": "2026-01-01T00:00:00+00:00",
"analysis_duration_s": 1.23,
"upload_duration_s": None,
"result": "---\nsource: invoice.pdf\n---\n# Title",
"error": None,
}
assert entry["status"] == DocumentStatus.READY
assert entry["filename"] == "invoice.pdf"
assert entry["analyzer_id"] == "prebuilt-documentSearch"
assert entry["analysis_duration_s"] == 1.23
assert entry["upload_duration_s"] is None
assert isinstance(entry["result"], str)
def test_failed_entry(self) -> None:
entry: DocumentEntry = {
"status": DocumentStatus.FAILED,
"filename": "bad.pdf",
"media_type": "application/pdf",
"analyzer_id": "prebuilt-documentSearch",
"analyzed_at": "2026-01-01T00:00:00+00:00",
"analysis_duration_s": 0.5,
"upload_duration_s": None,
"result": None,
"error": "Service unavailable",
}
assert entry["status"] == DocumentStatus.FAILED
assert entry["error"] == "Service unavailable"
assert entry["result"] is None
class TestFileSearchConfig:
def test_required_fields(self) -> None:
backend = AsyncMock()
tool = {"type": "file_search", "vector_store_ids": ["vs_123"]}
config = FileSearchConfig(backend=backend, vector_store_id="vs_123", file_search_tool=tool)
assert config.backend is backend
assert config.vector_store_id == "vs_123"
assert config.file_search_tool is tool
def test_from_openai_factory(self) -> None:
from agent_framework_azure_contentunderstanding._file_search import OpenAIFileSearchBackend
client = AsyncMock()
tool = {"type": "file_search", "vector_store_ids": ["vs_abc"]}
config = FileSearchConfig.from_openai(client, vector_store_id="vs_abc", file_search_tool=tool)
assert isinstance(config.backend, OpenAIFileSearchBackend)
assert config.vector_store_id == "vs_abc"
assert config.file_search_tool is tool