valentinegb / openai

An unofficial Rust library for the OpenAI API.
https://crates.io/crates/openai/
MIT License
61 stars 18 forks source link

Support EventSource for Chat completions #60

Closed rellfy closed 1 year ago

rellfy commented 1 year ago

This PR resolves #30 (for Chat completions only)

This approach involves creating a ChatCompletionDelta which can be merged into another ChatCompletionDelta. This allows collecting a delta for each token, as it is streamed, and reducing them into a single completion which can then be converted into a regular ChatCompletion at the end of the request. See the example.