mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Fix broken samples for GitHub Copilot, declarative, and Responses API (#4915)
* Python: Fix broken samples for GitHub Copilot, declarative, and Responses API - Add missing on_permission_request handler to github_copilot_basic and github_copilot_with_session samples (required by copilot SDK) - Increase timeout for remote MCP query in github_copilot_with_mcp sample - Soften session isolation claim in github_copilot_with_session sample - Fix inline_yaml sample: pass project_endpoint via client_kwargs instead of relying on YAML connection block (AzureAIClient expects project_endpoint, not endpoint) - Handle raw JSON schemas in Responses client _convert_response_format so declarative outputSchema works with the Responses API Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Improve raw JSON schema detection heuristic and add tests - Broaden raw schema detection to handle anyOf, oneOf, allOf, $ref, $defs keywords and JSON Schema primitive types, not just 'properties' - Apply same raw schema handling to azure-ai _shared.py for consistency - Add unit tests for both openai and azure-ai response_format conversion Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
cc0cfaaac8
commit
6b47cdbf52
@@ -1713,6 +1713,71 @@ def test_response_format_json_schema_missing_schema() -> None:
|
||||
client._prepare_response_and_text_format(response_format=response_format, text_config=None)
|
||||
|
||||
|
||||
def test_response_format_raw_json_schema_with_properties() -> None:
|
||||
"""Test raw JSON schema with properties is wrapped in json_schema envelope."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
|
||||
response_format = {"type": "object", "properties": {"x": {"type": "string"}}, "title": "MyOutput"}
|
||||
|
||||
_, text_config = client._prepare_response_and_text_format(response_format=response_format, text_config=None)
|
||||
|
||||
assert text_config is not None
|
||||
fmt = text_config["format"]
|
||||
assert fmt["type"] == "json_schema"
|
||||
assert fmt["name"] == "MyOutput"
|
||||
assert fmt["strict"] is True
|
||||
assert fmt["schema"]["additionalProperties"] is False
|
||||
assert "title" not in fmt["schema"]
|
||||
|
||||
|
||||
def test_response_format_raw_json_schema_no_title() -> None:
|
||||
"""Test raw JSON schema without title defaults name to 'response'."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
|
||||
response_format = {"type": "object", "properties": {"x": {"type": "string"}}}
|
||||
|
||||
_, text_config = client._prepare_response_and_text_format(response_format=response_format, text_config=None)
|
||||
|
||||
assert text_config is not None
|
||||
assert text_config["format"]["name"] == "response"
|
||||
|
||||
|
||||
def test_response_format_raw_json_schema_preserves_additional_properties() -> None:
|
||||
"""Test raw JSON schema preserves existing additionalProperties."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
|
||||
response_format = {"type": "object", "properties": {"x": {"type": "string"}}, "additionalProperties": True}
|
||||
|
||||
_, text_config = client._prepare_response_and_text_format(response_format=response_format, text_config=None)
|
||||
|
||||
assert text_config is not None
|
||||
assert text_config["format"]["schema"]["additionalProperties"] is True
|
||||
|
||||
|
||||
def test_response_format_raw_json_schema_non_object_type() -> None:
|
||||
"""Test raw JSON schema with non-object type does not inject additionalProperties."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
|
||||
response_format = {"type": "array", "items": {"type": "string"}}
|
||||
|
||||
_, text_config = client._prepare_response_and_text_format(response_format=response_format, text_config=None)
|
||||
|
||||
assert text_config is not None
|
||||
assert "additionalProperties" not in text_config["format"]["schema"]
|
||||
|
||||
|
||||
def test_response_format_raw_json_schema_with_anyof() -> None:
|
||||
"""Test raw JSON schema with anyOf keyword is detected."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
|
||||
response_format = {"anyOf": [{"type": "string"}, {"type": "number"}]}
|
||||
|
||||
_, text_config = client._prepare_response_and_text_format(response_format=response_format, text_config=None)
|
||||
|
||||
assert text_config is not None
|
||||
assert text_config["format"]["type"] == "json_schema"
|
||||
|
||||
|
||||
def test_response_format_unsupported_type() -> None:
|
||||
"""Test unsupported response_format type raises error."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
|
||||
Reference in New Issue
Block a user