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

ENH: Add "[DONE]" to the end of stream generation for better openai SDK compatibility #1062

Merged

Conversation

ZhangTianrong
Copy link
Contributor

@ZhangTianrong ZhangTianrong commented Feb 29, 2024

The official API from OpenAI always send a "[DONE]" before it terminates the stream. Although redundant, some clients like ChatGPT.好友 rely on it instead of a non-empty finish_reason to determine the the end of the stream. So, it might be beneficial to abide by this convension.

fixes #998

@XprobeBot XprobeBot added this to the v0.9.1 milestone Feb 29, 2024
@ZhangTianrong
Copy link
Contributor Author

test_client.py requires all chunks in the stream generation to be a valid json object, but "[DONE]" is supposed to be a special case. It's worth modifying the test to handle the last chunk specifically.

@qinxuye
Copy link
Contributor

qinxuye commented Mar 1, 2024

test_client.py requires all chunks in the stream generation to be a valid json object, but "[DONE]" is supposed to be a special case. It's worth modifying the test to handle the last chunk specifically.

I think you can strip the [DONE] and make the tests passed.

@ZhangTianrong ZhangTianrong force-pushed the add_done_to_end_of_stream branch from 5049600 to e997060 Compare March 1, 2024 06:24
@ZhangTianrong
Copy link
Contributor Author

It seems that the assert in test_client.py is not working. In assert "content" or "role" in chunk["choices"][0]["delta"], since comparation operators like in takes precedence over logical operators like or and "content" is a non empty, the statement always evaluates to True.

@XprobeBot XprobeBot modified the milestones: v0.9.1, v0.9.2 Mar 1, 2024
@ChengjieLi28 ChengjieLi28 changed the title Add "[DONE]" to the end of stream generation for better compatibility ENH: Add "[DONE]" to the end of stream generation for better openai SDK compatibility Mar 7, 2024
@XprobeBot XprobeBot added the enhancement New feature or request label Mar 7, 2024
@ChengjieLi28 ChengjieLi28 merged commit 374647e into xorbitsai:main Mar 7, 2024
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG 通过api调用,一句话完了好像没有返回[DONE]
4 participants