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

index out of bound when streaming with IncludeUsage as true #776

Open
aryanshridhar opened this issue Jun 24, 2024 · 1 comment
Open

index out of bound when streaming with IncludeUsage as true #776

aryanshridhar opened this issue Jun 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@aryanshridhar
Copy link

To Reproduce
When streamed chat completion with request having StreamOptions defined as -

req := openai.ChatCompletionRequest{
	Model:     openai.GPT3Dot5Turbo,
	Messages: []openai.ChatCompletionMessage{
		{
			Role:    openai.ChatMessageRoleUser,
			Content: "Lorem ipsum",
		},
	},
	StreamOptions: &openai.StreamOptions{IncludeUsage: true},
	Stream:        true,
}

breaks for last chunk-

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.main()
	/Users/aryan/Desktop/go-openai/examples/completion/main.go:60 +0x4b0
exit status 2

Expected behavior
The condition to his the EOF error and stop the streaming process.

Environment (please complete the following information):

  • go-openai version: master
  • Go version: go version go1.22.3 darwin/arm64
  • OpenAI API version: v1
@aryanshridhar aryanshridhar added the bug Something isn't working label Jun 24, 2024
@aryanshridhar
Copy link
Author

For anyone facing issue till this is fixed, can rely on FinishReason explicitly and return if present

response, err := stream.Recv()
isOver := response.Choices[0].FinishReason

if errors.Is(err, io.EOF) || len(isOver) > 0 {
	return
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant