@@ -43,9 +43,9 @@ func NewOpenAIProviderFromEnv() *OpenAIProvider {
4343}
4444
4545type openAIChatRequest struct {
46- Model string `json:"model"`
47- Messages []openAIChatMessage `json:"messages"`
48- Stream bool `json:"stream"`
46+ Model string `json:"model"`
47+ Messages []openAIChatMessage `json:"messages"`
48+ Stream bool `json:"stream"`
4949}
5050
5151type openAIChatMessage struct {
@@ -54,18 +54,18 @@ type openAIChatMessage struct {
5454}
5555
5656type openAIStreamChunk struct {
57- ID string `json:"id"`
58- Object string `json:"object"`
59- Created int64 `json:"created"`
60- Model string `json:"model"`
57+ ID string `json:"id"`
58+ Object string `json:"object"`
59+ Created int64 `json:"created"`
60+ Model string `json:"model"`
6161 Choices []openAIStreamChunkChoice `json:"choices"`
6262}
6363
6464type openAIStreamChunkChoice struct {
65- Index int `json:"index"`
66- Delta openAIStreamDelta `json:"delta"`
65+ Index int `json:"index"`
66+ Delta openAIStreamDelta `json:"delta"`
6767 // finish_reason may be "stop" etc.
68- FinishReason * string `json:"finish_reason"`
68+ FinishReason * string `json:"finish_reason"`
6969}
7070
7171type openAIStreamDelta struct {
@@ -125,7 +125,10 @@ func (p *OpenAIProvider) ChatCompletionStream(ctx context.Context, model string,
125125 for {
126126 select {
127127 case <- ctx .Done ():
128- ch <- StreamChunk {Err : ctx .Err ()}
128+ select {
129+ case ch <- StreamChunk {Err : ctx .Err ()}:
130+ default :
131+ }
129132 return
130133 default :
131134 }
0 commit comments