Closed
Description
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
Activity
Programmer-RD-AI commentedon Jan 14, 2025
Hi,
Thanks for bringing up this issue and providing such detailed information! 🙌 After investigating the problem further, I believe I found the root cause and made the following changes to resolve it.
Issue:
The current
FileChunkingStrategyParam
type hint inopenai/types/beta/file_chunking_strategy_param.py
includes:However, as the API error suggests,
StaticFileChunkingStrategyParam
should be encapsulated in aStaticFileChunkingStrategyObject
. This mismatch is why passingStaticFileChunkingStrategyParam
directly results in a400 - Missing required parameter: 'chunking_strategy.type'
error.Fix:
I updated the type hint to use
StaticFileChunkingStrategyObject
instead ofStaticFileChunkingStrategyParam
:This change reflects the correct structure expected by the API and aligns the type hints with actual usage. Additionally, this resolves the error when using
StaticFileChunkingStrategyParam
.Concern:
While this change resolves the immediate issue, I noticed that
AutoFileChunkingStrategyParam
doesn't include astatic
field, whichStaticFileChunkingStrategyObject
does. This inconsistency might cause issues if similar expectations arise for theAutoFileChunkingStrategyParam
in the future. I plan to explore this further to ensure compatibility across the board.Next Steps:
AutoFileChunkingStrategyParam
or its expected structure, I'd love to collaborate further!Thanks again for bringing this up, and I hope this update helps! Let me know if there’s anything else I should explore or test.
RobertCraigie commentedon Jan 14, 2025
Thanks for the report! This will be fixed in the next release
#2013