Skip to content

feat(api): add file search result details to run steps #1681

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

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 68
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-8e569a23f15a599dd4aee8a53431962bcba4985ab6cfb66c53c1434b99026b37.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-1dbac0e95bdb5a89a0dd3d93265475a378214551b7d8c22862928e0d87ace94b.yml
3 changes: 2 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ from openai.types.beta.threads.runs import (
RunStepDelta,
RunStepDeltaEvent,
RunStepDeltaMessageDelta,
RunStepInclude,
ToolCall,
ToolCallDelta,
ToolCallDeltaObject,
Expand All @@ -358,7 +359,7 @@ from openai.types.beta.threads.runs import (

Methods:

- <code title="get /threads/{thread_id}/runs/{run_id}/steps/{step_id}">client.beta.threads.runs.steps.<a href="./src/openai/resources/beta/threads/runs/steps.py">retrieve</a>(step_id, \*, thread_id, run_id) -> <a href="./src/openai/types/beta/threads/runs/run_step.py">RunStep</a></code>
- <code title="get /threads/{thread_id}/runs/{run_id}/steps/{step_id}">client.beta.threads.runs.steps.<a href="./src/openai/resources/beta/threads/runs/steps.py">retrieve</a>(step_id, \*, thread_id, run_id, \*\*<a href="src/openai/types/beta/threads/runs/step_retrieve_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/runs/run_step.py">RunStep</a></code>
- <code title="get /threads/{thread_id}/runs/{run_id}/steps">client.beta.threads.runs.steps.<a href="./src/openai/resources/beta/threads/runs/steps.py">list</a>(run_id, \*, thread_id, \*\*<a href="src/openai/types/beta/threads/runs/step_list_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/runs/run_step.py">SyncCursorPage[RunStep]</a></code>

### Messages
Expand Down
71 changes: 68 additions & 3 deletions src/openai/resources/beta/threads/runs/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Union, Iterable, Optional, overload
from typing import List, Union, Iterable, Optional, overload
from typing_extensions import Literal

import httpx
Expand Down Expand Up @@ -38,6 +38,7 @@
from .....types.beta.threads.run import Run
from .....types.beta.assistant_tool_param import AssistantToolParam
from .....types.beta.assistant_stream_event import AssistantStreamEvent
from .....types.beta.threads.runs.run_step_include import RunStepInclude
from .....types.beta.assistant_tool_choice_option_param import AssistantToolChoiceOptionParam
from .....types.beta.assistant_response_format_option_param import AssistantResponseFormatOptionParam

Expand All @@ -63,6 +64,7 @@ def create(
thread_id: str,
*,
assistant_id: str,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
instructions: Optional[str] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -93,6 +95,14 @@ def create(
[assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
execute this run.

include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

additional_instructions: Appends additional instructions at the end of the instructions for the run. This
is useful for modifying the behavior on a per-run basis without overriding other
instructions.
Expand Down Expand Up @@ -195,6 +205,7 @@ def create(
*,
assistant_id: str,
stream: Literal[True],
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
instructions: Optional[str] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -228,6 +239,14 @@ def create(
events, terminating when the Run enters a terminal state with a `data: [DONE]`
message.

include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

additional_instructions: Appends additional instructions at the end of the instructions for the run. This
is useful for modifying the behavior on a per-run basis without overriding other
instructions.
Expand Down Expand Up @@ -326,6 +345,7 @@ def create(
*,
assistant_id: str,
stream: bool,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
instructions: Optional[str] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -359,6 +379,14 @@ def create(
events, terminating when the Run enters a terminal state with a `data: [DONE]`
message.

include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

additional_instructions: Appends additional instructions at the end of the instructions for the run. This
is useful for modifying the behavior on a per-run basis without overriding other
instructions.
Expand Down Expand Up @@ -456,6 +484,7 @@ def create(
thread_id: str,
*,
assistant_id: str,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
instructions: Optional[str] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -505,7 +534,11 @@ def create(
run_create_params.RunCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform({"include": include}, run_create_params.RunCreateParams),
),
cast_to=Run,
stream=stream or False,
Expand Down Expand Up @@ -868,6 +901,7 @@ async def create(
thread_id: str,
*,
assistant_id: str,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
instructions: Optional[str] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -898,6 +932,14 @@ async def create(
[assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
execute this run.

include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

additional_instructions: Appends additional instructions at the end of the instructions for the run. This
is useful for modifying the behavior on a per-run basis without overriding other
instructions.
Expand Down Expand Up @@ -1000,6 +1042,7 @@ async def create(
*,
assistant_id: str,
stream: Literal[True],
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
instructions: Optional[str] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1033,6 +1076,14 @@ async def create(
events, terminating when the Run enters a terminal state with a `data: [DONE]`
message.

include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

additional_instructions: Appends additional instructions at the end of the instructions for the run. This
is useful for modifying the behavior on a per-run basis without overriding other
instructions.
Expand Down Expand Up @@ -1131,6 +1182,7 @@ async def create(
*,
assistant_id: str,
stream: bool,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
instructions: Optional[str] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1164,6 +1216,14 @@ async def create(
events, terminating when the Run enters a terminal state with a `data: [DONE]`
message.

include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

additional_instructions: Appends additional instructions at the end of the instructions for the run. This
is useful for modifying the behavior on a per-run basis without overriding other
instructions.
Expand Down Expand Up @@ -1261,6 +1321,7 @@ async def create(
thread_id: str,
*,
assistant_id: str,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
additional_messages: Optional[Iterable[run_create_params.AdditionalMessage]] | NotGiven = NOT_GIVEN,
instructions: Optional[str] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1310,7 +1371,11 @@ async def create(
run_create_params.RunCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=await async_maybe_transform({"include": include}, run_create_params.RunCreateParams),
),
cast_to=Run,
stream=stream or False,
Expand Down
59 changes: 55 additions & 4 deletions src/openai/resources/beta/threads/runs/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

from __future__ import annotations

from typing import List
from typing_extensions import Literal

import httpx

from ..... import _legacy_response
from ....._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ....._utils import maybe_transform
from ....._utils import (
maybe_transform,
async_maybe_transform,
)
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncCursorPage, AsyncCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.beta.threads.runs import step_list_params
from .....types.beta.threads.runs import step_list_params, step_retrieve_params
from .....types.beta.threads.runs.run_step import RunStep
from .....types.beta.threads.runs.run_step_include import RunStepInclude

__all__ = ["Steps", "AsyncSteps"]

Expand All @@ -35,6 +40,7 @@ def retrieve(
*,
thread_id: str,
run_id: str,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand All @@ -46,6 +52,14 @@ def retrieve(
Retrieves a run step.

Args:
include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request
Expand All @@ -64,7 +78,11 @@ def retrieve(
return self._get(
f"/threads/{thread_id}/runs/{run_id}/steps/{step_id}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform({"include": include}, step_retrieve_params.StepRetrieveParams),
),
cast_to=RunStep,
)
Expand All @@ -76,6 +94,7 @@ def list(
thread_id: str,
after: str | NotGiven = NOT_GIVEN,
before: str | NotGiven = NOT_GIVEN,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
limit: int | NotGiven = NOT_GIVEN,
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand All @@ -99,6 +118,14 @@ def list(
ending with obj_foo, your subsequent call can include before=obj_foo in order to
fetch the previous page of the list.

include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.

Expand Down Expand Up @@ -130,6 +157,7 @@ def list(
{
"after": after,
"before": before,
"include": include,
"limit": limit,
"order": order,
},
Expand All @@ -155,6 +183,7 @@ async def retrieve(
*,
thread_id: str,
run_id: str,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand All @@ -166,6 +195,14 @@ async def retrieve(
Retrieves a run step.

Args:
include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request
Expand All @@ -184,7 +221,11 @@ async def retrieve(
return await self._get(
f"/threads/{thread_id}/runs/{run_id}/steps/{step_id}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=await async_maybe_transform({"include": include}, step_retrieve_params.StepRetrieveParams),
),
cast_to=RunStep,
)
Expand All @@ -196,6 +237,7 @@ def list(
thread_id: str,
after: str | NotGiven = NOT_GIVEN,
before: str | NotGiven = NOT_GIVEN,
include: List[RunStepInclude] | NotGiven = NOT_GIVEN,
limit: int | NotGiven = NOT_GIVEN,
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand All @@ -219,6 +261,14 @@ def list(
ending with obj_foo, your subsequent call can include before=obj_foo in order to
fetch the previous page of the list.

include: A list of additional fields to include in the response. Currently the only
supported value is `step_details.tool_calls[*].file_search.results[*].content`
to fetch the file search result content.

See the
[file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
for more information.

limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.

Expand Down Expand Up @@ -250,6 +300,7 @@ def list(
{
"after": after,
"before": before,
"include": include,
"limit": limit,
"order": order,
},
Expand Down
Loading