Skip to content

Commit

Permalink
Python: fix: Remove wrong response_format override in `AzureChatPro…
Browse files Browse the repository at this point in the history
…mptExecutionSettings` class (microsoft#6424)

### Motivation and Context

This change is required to fix microsoft#5997 


### Description

The change is removing the wrong `response_format` override in
`AzureChatPromptExecutionSettings` class. The PR is also adding a unit
test covering the case where `response format` is defined.

The changes were successfully tested against an `Azure OpenAI` instance
with a `gpt-4o` deployment by specifying an
`AzureChatPromptExecutionSettings` like follows:

```python 
execution_settings =  AzureChatPromptExecutionSettings(
        service_id=service_id,
        ai_model_id=ai_model_id,
        max_tokens=1000,
        temperature=0.2,
        response_format={"type": "json_object"},
    )
```

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

Co-authored-by: Evan Mattson <[email protected]>
  • Loading branch information
danigian and moonbox3 authored May 29, 2024
1 parent e03b3fa commit 5d25f6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ def __getitem__(self, item):
class AzureChatPromptExecutionSettings(OpenAIChatPromptExecutionSettings):
"""Specific settings for the Azure OpenAI Chat Completion endpoint."""

response_format: str | None = None
extra_body: dict[str, Any] | ExtraBody | None = None
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,10 @@ def test_azure_open_ai_chat_prompt_execution_settings_with_aisearch_data_sources
}
settings = AzureChatPromptExecutionSettings.model_validate(input_dict, strict=True, from_attributes=True)
assert settings.extra_body["dataSources"][0]["type"] == "AzureCognitiveSearch"


def test_azure_open_ai_chat_prompt_execution_settings_with_response_format_json():
response_format = {"type": "json_object"}
settings = AzureChatPromptExecutionSettings(response_format=response_format)
options = settings.prepare_settings_dict()
assert options["response_format"] == response_format

0 comments on commit 5d25f6a

Please sign in to comment.