Skip to content

feat(vector store): improve chunking strategy type names #1690

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
Sep 5, 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-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 @@ -221,7 +221,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
10 changes: 6 additions & 4 deletions src/openai/resources/beta/vector_stores/file_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ....pagination import SyncCursorPage, AsyncCursorPage
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 @@ -39,7 +41,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 @@ -56,7 +58,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 @@ -249,7 +251,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 @@ -266,7 +268,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
10 changes: 6 additions & 4 deletions src/openai/resources/beta/vector_stores/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ....pagination import SyncCursorPage, AsyncCursorPage
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 @@ -38,7 +40,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 @@ -57,7 +59,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 @@ -249,7 +251,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 @@ -268,7 +270,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
12 changes: 9 additions & 3 deletions src/openai/resources/beta/vector_stores/vector_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +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 ....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 @@ -61,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 @@ -328,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]
12 changes: 12 additions & 0 deletions src/openai/types/beta/other_file_chunking_strategy_object.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 typing_extensions import Literal

from ..._models import BaseModel

__all__ = ["OtherFileChunkingStrategyObject"]


class OtherFileChunkingStrategyObject(BaseModel):
type: Literal["other"]
"""Always `other`."""
22 changes: 22 additions & 0 deletions src/openai/types/beta/static_file_chunking_strategy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.



from ..._models import BaseModel

__all__ = ["StaticFileChunkingStrategy"]


class StaticFileChunkingStrategy(BaseModel):
chunk_overlap_tokens: 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: 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`.
"""
15 changes: 15 additions & 0 deletions src/openai/types/beta/static_file_chunking_strategy_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing_extensions import Literal

from ..._models import BaseModel
from .static_file_chunking_strategy import StaticFileChunkingStrategy

__all__ = ["StaticFileChunkingStrategyObject"]


class StaticFileChunkingStrategyObject(BaseModel):
static: StaticFileChunkingStrategy

type: Literal["static"]
"""Always `static`."""
22 changes: 22 additions & 0 deletions src/openai/types/beta/static_file_chunking_strategy_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import Required, TypedDict

__all__ = ["StaticFileChunkingStrategyParam"]


class StaticFileChunkingStrategyParam(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`.
"""
Loading