Python: fix: keep citation get_url metadata#6037
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for carrying a get_url field from streaming url_citation annotations into Annotation.additional_properties, with a corresponding test update.
Changes:
- Include
get_url(when present) inAnnotation.additional_propertiesfor citation annotations. - Extend the streaming annotation test fixture and assertions to cover
get_url.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| python/packages/openai/agent_framework_openai/_chat_client.py | Propagates get_url from the raw annotation into additional_properties. |
| python/packages/openai/tests/openai/test_openai_chat_client.py | Adds test coverage asserting get_url is preserved in additional_properties. |
| additional_properties: dict[str, Any] = {"annotation_index": event.annotation_index} | ||
| if ann_get_url := _get_ann_value("get_url"): | ||
| additional_properties["get_url"] = ann_get_url | ||
| annotation_obj = Annotation( | ||
| type="citation", | ||
| title=_get_ann_value("title") or "", | ||
| url=str(ann_url), | ||
| additional_properties={"annotation_index": event.annotation_index}, | ||
| additional_properties=additional_properties, |
| mock_event.annotation = { | ||
| "type": "url_citation", | ||
| "url": "https://example.sharepoint.com/sites/my-site/doc.pdf", | ||
| "get_url": "https://example.search.windows.net/indexes/docs/documents/doc-123?api-version=2024-07-01", | ||
| "title": "doc.pdf", | ||
| "start_index": 100, | ||
| "end_index": 112, |
| assert ( | ||
| annotation["additional_properties"]["get_url"] | ||
| == "https://example.search.windows.net/indexes/docs/documents/doc-123?api-version=2024-07-01" | ||
| ) |
07df113 to
1b34ea4
Compare
|
Rebased onto current main; no code changes beyond the rebase.\n\nValidation on Windows:\n- .\.venv\Scripts\python.exe -m pytest packages\openai\tests\openai\test_openai_chat_client.py::test_streaming_annotation_added_with_url_citation -q -> 1 passed, 2 existing experimental warnings\n- .\.venv\Scripts\python.exe -m ruff check packages\openai\agent_framework_openai\_chat_client.py packages\openai\tests\openai\test_openai_chat_client.py\n- .\.venv\Scripts\python.exe -m py_compile packages\openai\agent_framework_openai\_chat_client.py packages\openai\tests\openai\test_openai_chat_client.py\n- git diff --check upstream/main..HEAD\n\nI also tried the full OpenAI chat client test file locally, but that includes integration tests and is blocked in this Windows environment by local OpenAI model/API-key configuration. |
Summary
get_urlfrom streamingurl_citationannotationsAnnotation.additional_propertiesFixes #5995
To verify
python/.venv/Scripts/python.exe -m pytest python/packages/openai/tests/openai/test_openai_chat_client.py::test_streaming_annotation_added_with_url_citation -qpython/.venv/Scripts/python.exe -m pytest python/packages/openai/tests/openai/test_openai_chat_client.py -q -k "streaming_annotation_added"python/.venv/Scripts/python.exe -m ruff check python/packages/openai/agent_framework_openai/_chat_client.py python/packages/openai/tests/openai/test_openai_chat_client.pygit diff --check