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

emptyMessagesLimit and Stream error #71

Closed
vadim-ivlev opened this issue Feb 14, 2023 · 3 comments
Closed

emptyMessagesLimit and Stream error #71

vadim-ivlev opened this issue Feb 14, 2023 · 3 comments

Comments

@vadim-ivlev
Copy link

Hi,

Thanks for your excellent work.

Yesterday, doing calls to CreateCompletionStream() function I started getting the following error:
Stream error: stream has sent too many empty messages

Requests were like this:

{
  "model": "text-davinci-003",
  "prompt": "В чем смысл жизни?",
  "max_tokens": 512,
  "temperature": 0.7,
  "stream": true
}

Seems like it's related to
emptyMessagesLimit = 100 in stream.go.

My code:

	stream, err := c.CreateCompletionStream(context.Background(), params)
	if err != nil {
		return
	}
	defer stream.Close()

	for {
		response, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			return
		}

		if err != nil {
			fmt.Printf("Stream error: %v\n", err)
			return
		}

		choices := response.Choices
		if len(choices) > 0 {
			fmt.Printf("%s", choices[0].Text)
		}
	}

I copied it from your example. Before yesterday it worked fine. Today this error seems to persist.

Could you please check it or make the variable configurable?

Thanks again.

@sashabaranov
Copy link
Owner

sashabaranov commented Feb 14, 2023

@vadim-ivlev bumped this limit to 300 in #72, please re-try after doing go get -u github.com/sashabaranov/go-gpt3.

You may also want to treat ErrTooManyEmptyStreamMessages as the of the stream e.g.

if errors.Is(err, gogpt.ErrTooManyEmptyStreamMessages) {
	// ... handle stream end
}

@vadim-ivlev
Copy link
Author

vadim-ivlev commented Feb 14, 2023 via email

@vadim-ivlev
Copy link
Author

Hi Sasha,
Have tested your changes.
Seems to work.
Thanks again for your kind response and the quick fix.

sashabaranov added a commit that referenced this issue Feb 20, 2023
* Configurable Transport (#75)

* new functions to allow HTTPClient configuration

* updated go.mod for testing from remote

* updated go.mod for remote testing

* revert go.mod replace directives

* Fixed NewOrgClientWithTransport comment

* Make client fully configurable

* make empty messages limit configurable #70 #71

* make auth token private in config

* add docs

* lint

---------

Co-authored-by: Michael Fox <m.will.fox@gmail.com>
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

No branches or pull requests

2 participants