Commit 1d228856

Robert Craigie <robert@craigie.dev>
2024-07-29 16:53:24
chore(runs/create_and_poll): add parallel_tool_calls request param
1 parent 195c05a
Changed files (2)
src
openai
resources
beta
threads
runs
tests
src/openai/resources/beta/threads/runs/runs.py
@@ -822,6 +822,8 @@ class Runs(SyncAPIResource):
             Literal[
                 "gpt-4o",
                 "gpt-4o-2024-05-13",
+                "gpt-4o-mini",
+                "gpt-4o-mini-2024-07-18",
                 "gpt-4-turbo",
                 "gpt-4-turbo-2024-04-09",
                 "gpt-4-0125-preview",
@@ -844,6 +846,7 @@ class Runs(SyncAPIResource):
             None,
         ]
         | NotGiven = NOT_GIVEN,
+        parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
         response_format: Optional[AssistantResponseFormatOptionParam] | NotGiven = NOT_GIVEN,
         temperature: Optional[float] | NotGiven = NOT_GIVEN,
         tool_choice: Optional[AssistantToolChoiceOptionParam] | NotGiven = NOT_GIVEN,
@@ -877,6 +880,7 @@ class Runs(SyncAPIResource):
             response_format=response_format,
             temperature=temperature,
             tool_choice=tool_choice,
+            parallel_tool_calls=parallel_tool_calls,
             # We assume we are not streaming when polling
             stream=False,
             tools=tools,
@@ -2404,6 +2408,8 @@ class AsyncRuns(AsyncAPIResource):
             Literal[
                 "gpt-4o",
                 "gpt-4o-2024-05-13",
+                "gpt-4o-mini",
+                "gpt-4o-mini-2024-07-18",
                 "gpt-4-turbo",
                 "gpt-4-turbo-2024-04-09",
                 "gpt-4-0125-preview",
@@ -2426,6 +2432,7 @@ class AsyncRuns(AsyncAPIResource):
             None,
         ]
         | NotGiven = NOT_GIVEN,
+        parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
         response_format: Optional[AssistantResponseFormatOptionParam] | NotGiven = NOT_GIVEN,
         temperature: Optional[float] | NotGiven = NOT_GIVEN,
         tool_choice: Optional[AssistantToolChoiceOptionParam] | NotGiven = NOT_GIVEN,
@@ -2459,6 +2466,7 @@ class AsyncRuns(AsyncAPIResource):
             response_format=response_format,
             temperature=temperature,
             tool_choice=tool_choice,
+            parallel_tool_calls=parallel_tool_calls,
             # We assume we are not streaming when polling
             stream=False,
             tools=tools,
tests/lib/test_assistants.py
@@ -1,41 +1,9 @@
 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))
+from openai._utils import assert_signatures_in_sync
 
 
 @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"])
@@ -58,3 +26,14 @@ def test_create_and_run_stream_method_definition_in_sync(sync: bool, client: Ope
         checking_client.beta.threads.create_and_run_stream,
         exclude_params={"stream"},
     )
+
+
+@pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"])
+def test_create_and_poll_method_definition_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None:
+    checking_client: OpenAI | AsyncOpenAI = client if sync else async_client
+
+    assert_signatures_in_sync(
+        checking_client.beta.threads.runs.create,
+        checking_client.beta.threads.runs.create_and_poll,
+        exclude_params={"stream"},
+    )