go-openai icon indicating copy to clipboard operation
go-openai copied to clipboard

support ChatCompletionStreamResponse Usage

Open allenhaozi opened this issue 1 year ago • 0 comments

https://github.com/sashabaranov/go-openai/blob/master/chat_stream.go#L22

type ChatCompletionStreamResponse struct {
	ID                string                       `json:"id"`
	Object            string                       `json:"object"`
	Created           int64                        `json:"created"`
	Model             string                       `json:"model"`
	Choices           []ChatCompletionStreamChoice `json:"choices"`
	PromptAnnotations []PromptAnnotation           `json:"prompt_annotations,omitempty"`
        Usage             Usage                     `json:"usage"`
 
}

// ChatCompletionStream
// Note: Perhaps it is more elegant to abstract Stream using generics.
type ChatCompletionStream struct {
	*streamReader[ChatCompletionStreamResponse]
}

allenhaozi avatar Mar 05 '24 08:03 allenhaozi