-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: New Feature: Add Support for "developer" Role for OpenAI o1 model #10032
Labels
python
Pull requests for the Python Semantic Kernel
Comments
markwallace-microsoft
added
python
Pull requests for the Python Semantic Kernel
triage
labels
Dec 24, 2024
@ymuichiro - thanks for doing a PR! |
4 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
Jan 15, 2025
### 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]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.Proposal
Add a Method to the
ChatHistory
ClassExpand the
AuthorRole
Enum"developer"
as a new value to theAuthorRole
enum.Improve Developer Experience (UX)
"system"
role is mistakenly passed, the logic should internally convert it to"developer"
for better UX."system"
, simply adding support for the"developer"
role seems to be the most optimal solution at this point.Background
"system"
role, causing errors when it is passed."developer"
role must be integrated in a way that preserves compatibility with other models.Platform
The text was updated successfully, but these errors were encountered: