Skip to content

Conversation

bakks
Copy link
Contributor

@bakks bakks commented Mar 2, 2023

Hey all - I'm just piggybacking on #30 and adding streaming support. Recommend that you merge @abatilo 's code first so that my additions are more clear. And please feel free to edit this PR yourself.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ This pull request was sent to the PullRequest network.


@bakks you can click here to see the review status or cancel the code review job.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PullRequest Breakdown

Reviewable lines of change

+ 105
- 0

100% Go

Type of change

Feature - These changes are adding a new feature or improvement to existing code.

@bakks
Copy link
Contributor Author

bakks commented Mar 2, 2023

Related to #28 and #29

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to add the ChatCompletion calls. One minor question noted, but it's more for future diagnostics rather than anything substantial.

Image of David K David K


Reviewed with ❤️ by PullRequest

// make sure there isn't any extra whitespace before or after
line = bytes.TrimSpace(line)
// the completion API only returns data events
if !bytes.HasPrefix(line, dataPrefix) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case that the line doesn't start with "data:" is it worth logging this event?

🔹 Giving Information (Nice to have)

Image of David K David K

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this line is here partly to filter out empty lines in the streaming response, of which there are many, so I don't think it makes sense to add extra logging here.

Some background context - the OpenAI documentation on the streaming flag is:

Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.

What I saw when debugging the responses is that every bit of data indeed had the data: prefix, except for the completely empty lines. So this line is exercised during normal operation, and the JSON unmarshalling will take care of throwing an error if there's line corruption.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes perfect sense, thanks for the details.

Image of David K David K

@bakks
Copy link
Contributor Author

bakks commented Mar 3, 2023

Please merge when ready, i don't have write access

@bakks
Copy link
Contributor Author

bakks commented Mar 3, 2023

I've rebased and pushed after the merge of #30, so this branch should only show my own changes now. Merge when ready.

Copy link
Contributor

@tylermann tylermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the streaming support for this one too. I'll go ahead and merge this in.

@tylermann tylermann merged commit ab408b5 into PullRequestInc:main Mar 4, 2023
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.

3 participants