Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Incorrect type hint for chunking_strategy params on File class methods #2005

Copy link
Copy link

Description

@evangriffiths
Issue body actions

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

If I pass in a StaticFileChunkingStrategyParam to OpenAI.beta.vector_stores.create I get:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Missing required parameter: 'chunking_strategy.type'.", 'type': 'invalid_request_error', 'param': 'chunking_strategy.type', 'code': 'missing_required_parameter'}}

To Reproduce

Run this repro:

import tempfile

from openai import OpenAI
from openai.types.beta.static_file_chunking_strategy_object import (
    StaticFileChunkingStrategyObject,
)
from openai.types.beta.static_file_chunking_strategy_param import (
    StaticFileChunkingStrategyParam,
)

client = OpenAI()
with tempfile.NamedTemporaryFile(suffix=".txt", mode="w+b") as temp_file:
    temp_file.write(b"foo bar")
    temp_file.flush()
    temp_file.seek(0)
    file = client.files.create(file=temp_file.file, purpose="assistants")

vector_store = client.beta.vector_stores.create(name="foo")
client.beta.vector_stores.files.create(
    vector_store_id=vector_store.id,
    file_id=file.id,
    chunking_strategy=StaticFileChunkingStrategyParam(
        max_chunk_size_tokens=250,
        chunk_overlap_tokens=10,
    ),
)

Based on type hints I'd expect this to work, but I get the above api error.

It works instead with:

from openai.types.beta.static_file_chunking_strategy_object import (
    StaticFileChunkingStrategyObject,
)
...
client.beta.vector_stores.files.create(
    vector_store_id=vector_store.id,
    file_id=file.id,
    chunking_strategy=StaticFileChunkingStrategyObject(
        type="static",
        static=StaticFileChunkingStrategyParam(
            max_chunk_size_tokens=250,
            chunk_overlap_tokens=10,
        ),
    ),
)

i.e. looks the type hint should be changed to FileChunkingStrategy. Note there are many such methods with this param in Files (e.g. create_and_poll, upload, ...). I haven't tested these, but this change may apply to them too.

Code snippets

No response

OS

macos 14.3.1

Python version

Python 3.10.14

Library version

openai==1.59.6

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.