Skip to content

Commit

Permalink
feat(vector store): improve chunking strategy type names (#1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stainless Bot authored and stainless-app[bot] committed Sep 6, 2024
1 parent b2f58cb commit f161000
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 321 deletions.
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-1dbac0e95bdb5a89a0dd3d93265475a378214551b7d8c22862928e0d87ace94b.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-85a85e0c08de456441431c0ae4e9c078cc8f9748c29430b9a9058340db6389ee.yml
12 changes: 11 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,17 @@ Methods:
Types:

```python
from openai.types.beta import VectorStore, VectorStoreDeleted
from openai.types.beta import (
AutoFileChunkingStrategyParam,
FileChunkingStrategy,
FileChunkingStrategyParam,
OtherFileChunkingStrategyObject,
StaticFileChunkingStrategy,
StaticFileChunkingStrategyObject,
StaticFileChunkingStrategyParam,
VectorStore,
VectorStoreDeleted,
)
```

Methods:
Expand Down
23 changes: 11 additions & 12 deletions src/openai/resources/beta/vector_stores/file_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
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 import FileChunkingStrategyParam
from ...._base_client import AsyncPaginator, make_request_options
from ....types.beta.vector_stores import file_batch_create_params, file_batch_list_files_params
from ....types.beta.file_chunking_strategy_param import FileChunkingStrategyParam
from ....types.beta.vector_stores.vector_store_file import VectorStoreFile
from ....types.beta.vector_stores.vector_store_file_batch import VectorStoreFileBatch

Expand All @@ -47,7 +46,7 @@ def create(
vector_store_id: str,
*,
file_ids: List[str],
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | 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 @@ -64,7 +63,7 @@ def create(
files.
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
strategy.
strategy. Only applicable if `file_ids` is non-empty.
extra_headers: Send extra headers
Expand Down Expand Up @@ -174,7 +173,7 @@ def create_and_poll(
*,
file_ids: List[str],
poll_interval_ms: int | NotGiven = NOT_GIVEN,
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFileBatch:
"""Create a vector store batch and poll until all files have been processed."""
batch = self.create(
Expand Down Expand Up @@ -308,7 +307,7 @@ def upload_and_poll(
max_concurrency: int = 5,
file_ids: List[str] = [],
poll_interval_ms: int | NotGiven = NOT_GIVEN,
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFileBatch:
"""Uploads the given files concurrently and then creates a vector store file batch.
Expand Down Expand Up @@ -365,7 +364,7 @@ async def create(
vector_store_id: str,
*,
file_ids: List[str],
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | 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 @@ -382,7 +381,7 @@ async def create(
files.
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
strategy.
strategy. Only applicable if `file_ids` is non-empty.
extra_headers: Send extra headers
Expand Down Expand Up @@ -492,7 +491,7 @@ async def create_and_poll(
*,
file_ids: List[str],
poll_interval_ms: int | NotGiven = NOT_GIVEN,
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFileBatch:
"""Create a vector store batch and poll until all files have been processed."""
batch = await self.create(
Expand Down Expand Up @@ -626,7 +625,7 @@ async def upload_and_poll(
max_concurrency: int = 5,
file_ids: List[str] = [],
poll_interval_ms: int | NotGiven = NOT_GIVEN,
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFileBatch:
"""Uploads the given files concurrently and then creates a vector store file batch.
Expand Down
27 changes: 13 additions & 14 deletions src/openai/resources/beta/vector_stores/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
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 import FileChunkingStrategyParam
from ...._base_client import AsyncPaginator, make_request_options
from ....types.beta.vector_stores import file_list_params, file_create_params
from ....types.beta.file_chunking_strategy_param import FileChunkingStrategyParam
from ....types.beta.vector_stores.vector_store_file import VectorStoreFile
from ....types.beta.vector_stores.vector_store_file_deleted import VectorStoreFileDeleted

Expand All @@ -43,7 +42,7 @@ def create(
vector_store_id: str,
*,
file_id: str,
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | 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 @@ -62,7 +61,7 @@ def create(
files.
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
strategy.
strategy. Only applicable if `file_ids` is non-empty.
extra_headers: Send extra headers
Expand Down Expand Up @@ -245,7 +244,7 @@ def create_and_poll(
*,
vector_store_id: str,
poll_interval_ms: int | NotGiven = NOT_GIVEN,
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFile:
"""Attach a file to the given vector store and wait for it to be processed."""
self.create(vector_store_id=vector_store_id, file_id=file_id, chunking_strategy=chunking_strategy)
Expand Down Expand Up @@ -302,7 +301,7 @@ def upload(
*,
vector_store_id: str,
file: FileTypes,
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFile:
"""Upload a file to the `files` API and then attach it to the given vector store.
Expand All @@ -318,7 +317,7 @@ def upload_and_poll(
vector_store_id: str,
file: FileTypes,
poll_interval_ms: int | NotGiven = NOT_GIVEN,
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFile:
"""Add a file to a vector store and poll until processing is complete."""
file_obj = self._client.files.create(file=file, purpose="assistants")
Expand All @@ -344,7 +343,7 @@ async def create(
vector_store_id: str,
*,
file_id: str,
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | 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 @@ -363,7 +362,7 @@ async def create(
files.
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
strategy.
strategy. Only applicable if `file_ids` is non-empty.
extra_headers: Send extra headers
Expand Down Expand Up @@ -546,7 +545,7 @@ async def create_and_poll(
*,
vector_store_id: str,
poll_interval_ms: int | NotGiven = NOT_GIVEN,
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFile:
"""Attach a file to the given vector store and wait for it to be processed."""
await self.create(vector_store_id=vector_store_id, file_id=file_id, chunking_strategy=chunking_strategy)
Expand Down Expand Up @@ -603,7 +602,7 @@ async def upload(
*,
vector_store_id: str,
file: FileTypes,
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFile:
"""Upload a file to the `files` API and then attach it to the given vector store.
Expand All @@ -621,7 +620,7 @@ async def upload_and_poll(
vector_store_id: str,
file: FileTypes,
poll_interval_ms: int | NotGiven = NOT_GIVEN,
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
) -> VectorStoreFile:
"""Add a file to a vector store and poll until processing is complete."""
file_obj = await self._client.files.create(file=file, purpose="assistants")
Expand Down
15 changes: 9 additions & 6 deletions src/openai/resources/beta/vector_stores/vector_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
AsyncFileBatchesWithStreamingResponse,
)
from ....pagination import SyncCursorPage, AsyncCursorPage
from ....types.beta import vector_store_list_params, vector_store_create_params, vector_store_update_params
from ...._base_client import (
AsyncPaginator,
make_request_options,
from ....types.beta import (
FileChunkingStrategyParam,
vector_store_list_params,
vector_store_create_params,
vector_store_update_params,
)
from ...._base_client import AsyncPaginator, make_request_options
from ....types.beta.vector_store import VectorStore
from ....types.beta.vector_store_deleted import VectorStoreDeleted
from ....types.beta.file_chunking_strategy_param import FileChunkingStrategyParam

__all__ = ["VectorStores", "AsyncVectorStores"]

Expand All @@ -64,7 +67,7 @@ def with_streaming_response(self) -> VectorStoresWithStreamingResponse:
def create(
self,
*,
chunking_strategy: vector_store_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
expires_after: vector_store_create_params.ExpiresAfter | NotGiven = NOT_GIVEN,
file_ids: List[str] | NotGiven = NOT_GIVEN,
metadata: Optional[object] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -331,7 +334,7 @@ def with_streaming_response(self) -> AsyncVectorStoresWithStreamingResponse:
async def create(
self,
*,
chunking_strategy: vector_store_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
expires_after: vector_store_create_params.ExpiresAfter | NotGiven = NOT_GIVEN,
file_ids: List[str] | NotGiven = NOT_GIVEN,
metadata: Optional[object] | NotGiven = NOT_GIVEN,
Expand Down
7 changes: 7 additions & 0 deletions src/openai/types/beta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .assistant_tool_choice import AssistantToolChoice as AssistantToolChoice
from .code_interpreter_tool import CodeInterpreterTool as CodeInterpreterTool
from .assistant_stream_event import AssistantStreamEvent as AssistantStreamEvent
from .file_chunking_strategy import FileChunkingStrategy as FileChunkingStrategy
from .file_search_tool_param import FileSearchToolParam as FileSearchToolParam
from .assistant_create_params import AssistantCreateParams as AssistantCreateParams
from .assistant_update_params import AssistantUpdateParams as AssistantUpdateParams
Expand All @@ -28,11 +29,17 @@
from .assistant_tool_choice_param import AssistantToolChoiceParam as AssistantToolChoiceParam
from .code_interpreter_tool_param import CodeInterpreterToolParam as CodeInterpreterToolParam
from .assistant_tool_choice_option import AssistantToolChoiceOption as AssistantToolChoiceOption
from .file_chunking_strategy_param import FileChunkingStrategyParam as FileChunkingStrategyParam
from .thread_create_and_run_params import ThreadCreateAndRunParams as ThreadCreateAndRunParams
from .static_file_chunking_strategy import StaticFileChunkingStrategy as StaticFileChunkingStrategy
from .assistant_tool_choice_function import AssistantToolChoiceFunction as AssistantToolChoiceFunction
from .assistant_response_format_option import AssistantResponseFormatOption as AssistantResponseFormatOption
from .auto_file_chunking_strategy_param import AutoFileChunkingStrategyParam as AutoFileChunkingStrategyParam
from .assistant_tool_choice_option_param import AssistantToolChoiceOptionParam as AssistantToolChoiceOptionParam
from .other_file_chunking_strategy_object import OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject
from .static_file_chunking_strategy_param import StaticFileChunkingStrategyParam as StaticFileChunkingStrategyParam
from .assistant_tool_choice_function_param import AssistantToolChoiceFunctionParam as AssistantToolChoiceFunctionParam
from .static_file_chunking_strategy_object import StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject
from .assistant_response_format_option_param import (
AssistantResponseFormatOptionParam as AssistantResponseFormatOptionParam,
)
44 changes: 5 additions & 39 deletions src/openai/types/beta/assistant_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from __future__ import annotations

from typing import List, Union, Iterable, Optional
from typing_extensions import Literal, Required, TypeAlias, TypedDict
from typing_extensions import Required, TypedDict

from ..chat_model import ChatModel
from .assistant_tool_param import AssistantToolParam
from .file_chunking_strategy_param import FileChunkingStrategyParam
from .assistant_response_format_option_param import AssistantResponseFormatOptionParam

__all__ = [
Expand All @@ -15,10 +16,6 @@
"ToolResourcesCodeInterpreter",
"ToolResourcesFileSearch",
"ToolResourcesFileSearchVectorStore",
"ToolResourcesFileSearchVectorStoreChunkingStrategy",
"ToolResourcesFileSearchVectorStoreChunkingStrategyAuto",
"ToolResourcesFileSearchVectorStoreChunkingStrategyStatic",
"ToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic",
]


Expand Down Expand Up @@ -118,43 +115,12 @@ class ToolResourcesCodeInterpreter(TypedDict, total=False):
"""


class ToolResourcesFileSearchVectorStoreChunkingStrategyAuto(TypedDict, total=False):
type: Required[Literal["auto"]]
"""Always `auto`."""


class ToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic(TypedDict, total=False):
chunk_overlap_tokens: Required[int]
"""The number of tokens that overlap between chunks. The default value is `400`.
Note that the overlap must not exceed half of `max_chunk_size_tokens`.
"""

max_chunk_size_tokens: Required[int]
"""The maximum number of tokens in each chunk.
The default value is `800`. The minimum value is `100` and the maximum value is
`4096`.
"""


class ToolResourcesFileSearchVectorStoreChunkingStrategyStatic(TypedDict, total=False):
static: Required[ToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic]

type: Required[Literal["static"]]
"""Always `static`."""


ToolResourcesFileSearchVectorStoreChunkingStrategy: TypeAlias = Union[
ToolResourcesFileSearchVectorStoreChunkingStrategyAuto, ToolResourcesFileSearchVectorStoreChunkingStrategyStatic
]


class ToolResourcesFileSearchVectorStore(TypedDict, total=False):
chunking_strategy: ToolResourcesFileSearchVectorStoreChunkingStrategy
chunking_strategy: FileChunkingStrategyParam
"""The chunking strategy used to chunk the file(s).
If not set, will use the `auto` strategy.
If not set, will use the `auto` strategy. Only applicable if `file_ids` is
non-empty.
"""

file_ids: List[str]
Expand Down
12 changes: 12 additions & 0 deletions src/openai/types/beta/auto_file_chunking_strategy_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Literal, Required, TypedDict

__all__ = ["AutoFileChunkingStrategyParam"]


class AutoFileChunkingStrategyParam(TypedDict, total=False):
type: Required[Literal["auto"]]
"""Always `auto`."""
14 changes: 14 additions & 0 deletions src/openai/types/beta/file_chunking_strategy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Union
from typing_extensions import Annotated, TypeAlias

from ..._utils import PropertyInfo
from .other_file_chunking_strategy_object import OtherFileChunkingStrategyObject
from .static_file_chunking_strategy_object import StaticFileChunkingStrategyObject

__all__ = ["FileChunkingStrategy"]

FileChunkingStrategy: TypeAlias = Annotated[
Union[StaticFileChunkingStrategyObject, OtherFileChunkingStrategyObject], PropertyInfo(discriminator="type")
]
13 changes: 13 additions & 0 deletions src/openai/types/beta/file_chunking_strategy_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import Union
from typing_extensions import TypeAlias

from .auto_file_chunking_strategy_param import AutoFileChunkingStrategyParam
from .static_file_chunking_strategy_param import StaticFileChunkingStrategyParam

__all__ = ["FileChunkingStrategyParam"]

FileChunkingStrategyParam: TypeAlias = Union[AutoFileChunkingStrategyParam, StaticFileChunkingStrategyParam]
Loading

0 comments on commit f161000

Please sign in to comment.