-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
[0.4] Adds stream support #84
Conversation
cc @GromNaN Can you please have a look if this would work with the symphony client? |
Great job, looks like we are close! Do we need an extra call to the I'm a little confused about the name of the factory method |
Just a heads up with the streaming: the key off of choices is delta, not text (https://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb) |
Feat/stream support feedback
…o add-stream-support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testing pull request needs to be updated with this changes.
Thanks @slavarazum . @nunomaduro already updated the parts you mentioned. |
@jhull Thanks for your hint but the key in completion responses is still |
When will you release this PR? |
Later today. |
Add streaming function for Symfony Http Client
This PR adds stream support.
This resolves #19 #21 #80
Since the library is HTTP client agnostic now it was a bit more complicated than expected. See explanations below.
Here are the key changes:
Examples
Completion Create
(copy from README)
Chat Create
(copy from README)
FineTunes Events List
(copy from README)
Explanations
create()
->createStreamed()
etc.StreamResponse
object which has a methodread()
that returns aGenerator
instance for all the incoming responses.Chat Create
this was not possible as the response structure is very different from the non streaming response.Async requests and PSR-18
PSR-18 sadly does not cover async requests. Therefore it is not possible to write generic code which will work with all the HTTP clients.
To work around this issue I have extended the
OpenAI::factory()
with a new methodwithAsyncRequest
where a closure can be passed which will be used for async requests.If GuzzleHttp is used there is an implementation available and it is not necessary to provide it manually.
To be honest, this is not very developer friendly but so far I had no better idea. The only thing we could do is to provide more implementations for various HTTP clients.
Example factory usage (with GuzzleHttp which is redundant because it is already baked in):
Thanks
Many thanks to @slavarazum for giving me a starting point here #21