-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): add missing parallel_tool_calls arguments
- Loading branch information
1 parent
e005a84
commit 4041e4f
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import annotations | ||
|
||
import inspect | ||
from typing import Any, Callable | ||
|
||
import pytest | ||
|
||
from openai import OpenAI, AsyncOpenAI | ||
|
||
|
||
def assert_signatures_in_sync( | ||
source_func: Callable[..., Any], | ||
check_func: Callable[..., Any], | ||
*, | ||
exclude_params: set[str] = set(), | ||
) -> None: | ||
check_sig = inspect.signature(check_func) | ||
source_sig = inspect.signature(source_func) | ||
|
||
errors: list[str] = [] | ||
|
||
for name, generated_param in source_sig.parameters.items(): | ||
if name in exclude_params: | ||
continue | ||
|
||
custom_param = check_sig.parameters.get(name) | ||
if not custom_param: | ||
errors.append(f"the `{name}` param is missing") | ||
continue | ||
|
||
if custom_param.annotation != generated_param.annotation: | ||
errors.append( | ||
f"types for the `{name}` param are do not match; generated={repr(generated_param.annotation)} custom={repr(generated_param.annotation)}" | ||
) | ||
continue | ||
|
||
if errors: | ||
raise AssertionError(f"{len(errors)} errors encountered when comparing signatures:\n\n" + "\n\n".join(errors)) | ||
|
||
|
||
@pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) | ||
def test_create_and_run_poll_method_definition_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None: | ||
checking_client = client if sync else async_client | ||
|
||
assert_signatures_in_sync( | ||
checking_client.beta.threads.create_and_run, | ||
checking_client.beta.threads.create_and_run_poll, | ||
exclude_params={"stream"}, | ||
) | ||
|
||
@pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) | ||
def test_create_and_run_stream_method_definition_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None: | ||
checking_client = client if sync else async_client | ||
|
||
assert_signatures_in_sync( | ||
checking_client.beta.threads.create_and_run, | ||
checking_client.beta.threads.create_and_run_stream, | ||
exclude_params={"stream"}, | ||
) |
4041e4f
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.
Today, I learned about the parallel_tool_calls API parameter and was eager to try it out. However, my outdated client (version 1.14.3) didn't support it, so I decided it was the perfect time to upgrade. I installed newest version (1.35.1), but before I could test it, I had to pick up my kid. When I finally sat down to check, I discovered that 1.35.1 still didn't support parallel_tool_calls.
Feeling a bit disappointed, I read through the changelog from 1.14.3 to 1.35.1, only to confirm it wasn’t there. Just as I was about to give up, my IDE notified me of a new version. I was like "But I just installed a new version, right?". Still, I checked the changelog again, and there actually was a newer version and it included support for parallel_tool_calls.
What a day to be alive.