Skip to content
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

Make finish_reason nullable in CreateCompletionResponse #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidmigloz
Copy link
Contributor

Currently, the completion object is used for both streamed and non-streamed modes. However, there's a subtle difference between the two modes: when using streaming finish_reason is null until the last emission.

Example:

curl https://api.openai.com/v1/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {api_key}" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Say this is a test",
    "temperature": 0,
    "stream": true
  }'
data: {"id":"cmpl-8DRxiREy3SiZNrgxq9DScOdNBxwRJ","object":"text_completion","created":1698216442,"choices":[{"text":"\n\n","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}

data: {"id":"cmpl-8DRxiREy3SiZNrgxq9DScOdNBxwRJ","object":"text_completion","created":1698216442,"choices":[{"text":"This","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}

data: {"id":"cmpl-8DRxiREy3SiZNrgxq9DScOdNBxwRJ","object":"text_completion","created":1698216442,"choices":[{"text":" is","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}

data: {"id":"cmpl-8DRxiREy3SiZNrgxq9DScOdNBxwRJ","object":"text_completion","created":1698216442,"choices":[{"text":" a","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}

data: {"id":"cmpl-8DRxiREy3SiZNrgxq9DScOdNBxwRJ","object":"text_completion","created":1698216442,"choices":[{"text":" test","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}

data: {"id":"cmpl-8DRxiREy3SiZNrgxq9DScOdNBxwRJ","object":"text_completion","created":1698216442,"choices":[{"text":".","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}

data: {"id":"cmpl-8DRxiREy3SiZNrgxq9DScOdNBxwRJ","object":"text_completion","created":1698216442,"choices":[{"text":"","index":0,"logprobs":null,"finish_reason":"stop"}],"model":"gpt-3.5-turbo-instruct"}

data: [DONE]

The current spec does not allow the finish_reason field to be null, which creates issues when using streaming in a client generated from the spec.

Assuming that keeping the same schema for both modes is the preferred option, this PR makes the finish_reason field nullable.

An alternative would be to split the CreateCompletionResponse schema into CreateCompletionResponse and CreateCompletionStreamResponse like it is done in the ChatCompletionResponse definition.

@gittb
Copy link

gittb commented Oct 25, 2024

I can also confirm David's findings. This is currently causing issues when validating responses via pydantic models generated from this schema. Even after the latest 2024-10-17 update. #356

@kwhinnery-openai, Hope you're well. Could you resolve this misalignment between OAI's responses, the spec, and the docs? We'd like to rely on this spec as ground truth. I'd rather not have to manually modify this schema to use it downstream.

I'm happy to create an updated PR, but it seems this schema is generated and needs to be fixed internally at OpenAI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants