### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
1. Why is this change required?
2. What problem does it solve?
3. What scenario does it contribute to?
4. If it fixes an open issue, please link to the issue here.
-->
Small update to the reasoning samples, that leverages the latest updates
to those api's.
Fixed typing issue in filters.
### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
### 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 😄
### Motivation and Context
Currently, the OpenAI O1 model introduces a new role "developer".
However, passing the conventional "system" role results in an error. To
address this issue, the following changes are proposed.
### Description
1. **Add a Method to the `ChatHistory` Class**
- Implement a method to handle role conversion or substitution logic for
compatibility with the O1 model.
2. **Expand the `AuthorRole` Enum**
- Add `"developer"` as a new value to the `AuthorRole` enum.
3. **Improve Developer Experience (UX)**
- If the `"system"` role is mistakenly passed, the logic should
internally convert it to `"developer"` for better UX.
- However, since all models other than O1 still use `"system"`, simply
adding support for the `"developer"` role seems to be the most optimal
solution at this point.
- Closes: #10032
### Background
- The O1 model no longer supports the `"system"` role, causing errors
when it is passed.
- The introduction of the `"developer"` role must be integrated in a way
that preserves compatibility with other models.
### Usage
```python
import asyncio
from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior
from semantic_kernel.connectors.ai.open_ai.prompt_execution_settings.azure_chat_prompt_execution_settings import (
AzureChatPromptExecutionSettings,
)
from semantic_kernel.connectors.ai.open_ai.services.azure_chat_completion import AzureChatCompletion
from semantic_kernel.contents.chat_history import ChatHistory
from semantic_kernel.kernel import Kernel
async def main():
kernel = Kernel()
service_id = "azure-openai"
kernel.add_service(
service=AzureChatCompletion(
service_id=service_id,
api_key=*********,
endpoint=*********,
deployment_name="o1",
api_version="2024-12-01-preview",
)
)
settings = kernel.get_prompt_execution_settings_from_service_id(service_id=service_id)
if isinstance(settings, AzureChatPromptExecutionSettings):
settings.function_choice_behavior = FunctionChoiceBehavior.Auto(auto_invoke=True)
service = kernel.get_service(service_id=service_id)
if not isinstance(service, AzureChatCompletion):
raise Exception("Invalid Value")
history = ChatHistory()
history.add_developer_message("You are a helpful assistant.")
history.add_user_message("hello")
result = await service.get_chat_message_contents(chat_history=history, settings=settings, kernel=kernel)
if not result:
raise Exception("result is None")
print(result[0].content)
if __name__ == "__main__":
asyncio.run(main())
```
### 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: Tao Chen <[email protected]>
Co-authored-by: Evan Mattson <[email protected]>