-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add support for 'presence_penalty' param to Responses API #4830
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -472,6 +472,7 @@ async def create_openai_response( | |
| reasoning: OpenAIResponseReasoning | None = None, | ||
| max_output_tokens: int | None = None, | ||
| metadata: dict[str, str] | None = None, | ||
| presence_penalty: float | None = None, | ||
| ): | ||
| stream = bool(stream) | ||
| text = OpenAIResponseText(format=OpenAIResponseTextFormat(type="text")) if text is None else text | ||
|
|
@@ -528,6 +529,7 @@ async def create_openai_response( | |
| max_output_tokens=max_output_tokens, | ||
| metadata=metadata, | ||
| include=include, | ||
| presence_penalty=presence_penalty, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems also need to be propagated to chat completion api.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
|
|
||
| if stream: | ||
|
|
@@ -585,6 +587,7 @@ async def _create_streaming_response( | |
| max_output_tokens: int | None = None, | ||
| metadata: dict[str, str] | None = None, | ||
| include: list[ResponseItemInclude] | None = None, | ||
| presence_penalty: float | None = None, | ||
| ) -> AsyncIterator[OpenAIResponseObjectStream]: | ||
| # These should never be None when called from create_openai_response (which sets defaults) | ||
| # but we assert here to help mypy understand the types | ||
|
|
@@ -651,6 +654,7 @@ async def _create_streaming_response( | |
| metadata=metadata, | ||
| include=include, | ||
| store=store, | ||
| presence_penalty=presence_penalty, | ||
| ) | ||
|
|
||
| final_response = None | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,6 +146,7 @@ def __init__( | |
| metadata: dict[str, str] | None = None, | ||
| include: list[ResponseItemInclude] | None = None, | ||
| store: bool | None = True, | ||
| presence_penalty: float | None = None, | ||
| ): | ||
| self.inference_api = inference_api | ||
| self.ctx = ctx | ||
|
|
@@ -171,6 +172,7 @@ def __init__( | |
| self.store = store | ||
| self.include = include | ||
| self.store = bool(store) if store is not None else True | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tiny nit: Not blocking, but worth cleaning up while we’re in here. |
||
| self.presence_penalty = presence_penalty | ||
| self.sequence_number = 0 | ||
| # Store MCP tool mapping that gets built during tool processing | ||
| self.mcp_tool_to_server: dict[str, OpenAIResponseInputToolMCP] = ( | ||
|
|
@@ -209,6 +211,7 @@ async def _create_refusal_response(self, violation_message: str) -> OpenAIRespon | |
| output=[OpenAIResponseMessage(role="assistant", content=[refusal_content], type="message")], | ||
| max_output_tokens=self.max_output_tokens, | ||
| metadata=self.metadata, | ||
| presence_penalty=self.presence_penalty, | ||
| store=self.store, | ||
| ) | ||
|
|
||
|
|
@@ -251,6 +254,7 @@ def _snapshot_response( | |
| reasoning=self.reasoning, | ||
| max_output_tokens=self.max_output_tokens, | ||
| metadata=self.metadata, | ||
| presence_penalty=self.presence_penalty, | ||
| store=self.store, | ||
| ) | ||
|
|
||
|
|
@@ -371,6 +375,7 @@ async def create_response(self) -> AsyncIterator[OpenAIResponseObjectStream]: | |
| parallel_tool_calls=effective_parallel_tool_calls, | ||
| reasoning_effort=self.reasoning.effort if self.reasoning else None, | ||
| max_completion_tokens=remaining_output_tokens, | ||
| presence_penalty=self.presence_penalty, | ||
| ) | ||
| completion_result = await self.inference_api.openai_chat_completion(params) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call is using a long positional-arg list. With the recent addition of presence_penalty, it looks like
reasoningandmax_output_tokensare now swapped due to parameter order. Can we switch this call to keyword arguments (at least for the tail params)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I was trying to fix the order issue at #4825 (review)