Skip to content

Commit

Permalink
python: add developer role and o1 properties (max_completion_tokens, …
Browse files Browse the repository at this point in the history
…reasoning_effort) for OpenAI
  • Loading branch information
ymuichiro committed Jan 7, 2025
1 parent 7bfda00 commit afb791d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ class OpenAIChatPromptExecutionSettings(OpenAIPromptExecutionSettings):
dict[str, Any] | None,
Field(description="Additional options to pass when streaming is used. Do not set this manually."),
] = None
max_completion_tokens: Annotated[
int | None,
Field(
gt=0,
description="A maximum limit on total tokens for completion, including both output and reasoning tokens.",
),
] = None
reasoning_effort: Annotated[
Literal["low", "medium", "high"] | None,
Field(
description="Adjusts reasoning effort (low/medium/high). Lower values reduce response time and token usage."
),
] = None

@field_validator("functions", "function_call", mode="after")
@classmethod
Expand Down
15 changes: 15 additions & 0 deletions python/semantic_kernel/contents/chat_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ def add_system_message_list(self, content: list[KernelContent], **kwargs: Any) -
"""Add a system message to the chat history."""
self.add_message(message=self._prepare_for_add(role=AuthorRole.SYSTEM, items=content, **kwargs))

@singledispatchmethod
def add_developer_message(self, content: str | list[KernelContent], **kwargs) -> None:
"""Add a system message to the chat history."""
raise NotImplementedError

@add_developer_message.register
def add_developer_message_str(self, content: str, **kwargs: Any) -> None:
"""Add a system message to the chat history."""
self.add_message(message=self._prepare_for_add(role=AuthorRole.DEVELOPER, content=content, **kwargs))

@add_developer_message.register(list)
def add_developer_message_list(self, content: list[KernelContent], **kwargs: Any) -> None:
"""Add a system message to the chat history."""
self.add_message(message=self._prepare_for_add(role=AuthorRole.DEVELOPER, items=content, **kwargs))

@singledispatchmethod
def add_user_message(self, content: str | list[KernelContent], **kwargs: Any) -> None:
"""Add a user message to the chat history."""
Expand Down
1 change: 1 addition & 0 deletions python/semantic_kernel/contents/utils/author_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ class AuthorRole(str, Enum):
USER = "user"
ASSISTANT = "assistant"
TOOL = "tool"
DEVELOPER = "developer"

0 comments on commit afb791d

Please sign in to comment.