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
Dumping a completion response from a request with logprobs
set raises this warning:
python3.11/site-packages/pydantic/main.py:308: UserWarning: Pydantic serializer warnings:
Expected `int` but got `float` - serialized value may not be as expected
Expected `int` but got `float` - serialized value may not be as expected
Expected `int` but got `float` - serialized value may not be as expected
return self.__pydantic_serializer__.to_python(
I confirmed that changing this type annotation to
top_logprobs: Optional[List[Dict[str, float]]] = None
removes the warnings.
To Reproduce
- Install
openai>=1.0.0
- In a
completions
API call, setlogprobs>=1
- Dump the response using
.model_dump()
, as advised in the migration guide
Code snippets
import openai
client = openai.OpenAI()
# Set logprobs >= 1
response = client.completions.create(
model="curie", prompt="test", max_tokens=3, logprobs=1
)
response_as_dict = response.model_dump()
# raises a UserWarning
To ignore the warnings, the user currently has to do this:
import warnings
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
category=UserWarning,
message="Pydantic serializer warnings",
)
response_as_dict = response.model_dump()
OS
macOS
Python version
Python v3.11.5
Library version
openai v1.1.2