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.

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.

None yet

1 participant