-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Add max_output_tokens as argument to Response API #3699
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 |
---|---|---|
|
@@ -204,6 +204,7 @@ async def create_openai_response( | |
store: bool | None = True, | ||
stream: bool | None = False, | ||
temperature: float | None = None, | ||
max_output_tokens: int | None = None, | ||
text: OpenAIResponseText | None = None, | ||
tools: list[OpenAIResponseInputTool] | None = None, | ||
include: list[str] | None = None, | ||
|
@@ -224,6 +225,7 @@ async def create_openai_response( | |
previous_response_id=previous_response_id, | ||
store=store, | ||
temperature=temperature, | ||
max_output_tokens=max_output_tokens, | ||
text=text, | ||
tools=tools, | ||
max_infer_iters=max_infer_iters, | ||
|
@@ -252,6 +254,7 @@ async def _create_streaming_response( | |
previous_response_id: str | None = None, | ||
store: bool | None = True, | ||
temperature: float | None = None, | ||
max_output_tokens: int | None = None, | ||
text: OpenAIResponseText | None = None, | ||
tools: list[OpenAIResponseInputTool] | None = None, | ||
max_infer_iters: int | None = 10, | ||
|
@@ -268,6 +271,7 @@ async def _create_streaming_response( | |
messages=messages, | ||
response_tools=tools, | ||
temperature=temperature, | ||
max_tokens=max_output_tokens, | ||
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. why did you change the name to max_tokens here? keep the same thing? |
||
response_format=response_format, | ||
inputs=input, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,3 +297,38 @@ def test_function_call_output_response_with_none_arguments(openai_client, client | |
assert response.output[0].type == "function_call" | ||
assert response.output[0].arguments == "{}" | ||
_ = response.output[0].call_id | ||
|
||
|
||
def test_response_with_max_output_tokens(compat_client, text_model_id): | ||
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. before testing, maybe keep PRs in draft state? you have not implemented the functionality. |
||
"""Test that the `max_output_tokens` parameter is used.""" | ||
if not isinstance(compat_client, OpenAI): | ||
pytest.skip("This test requires the OpenAI client.") | ||
|
||
response = compat_client.responses.create( | ||
model=text_model_id, | ||
input=[ | ||
{ | ||
"role": "user", | ||
"content": "what's the current time? You MUST call the `get_current_time` function to find out.", | ||
} | ||
], | ||
max_output_tokens=15, | ||
stream=False, | ||
) | ||
|
||
assert response.id is not None | ||
assert response.model == text_model_id | ||
|
||
assert hasattr(response, "max_output_tokens") | ||
assert response.max_output_tokens == 15 | ||
|
||
output_text = "" | ||
for item in response.output: | ||
if item.type == "message" and item.role == "assistant": | ||
if item.content and item.content.type == "text": | ||
output_text = item.content.text | ||
break | ||
|
||
assert output_text, "Assistant response content should not be empty" | ||
|
||
assert len(output_text.split()) < 30 |
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.
looks like your pre-commit setup is not correct. it needs python3.12 and pre-commit==4.3.0