Skip to content

Commit

Permalink
fix: nil pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakurasan committed Apr 22, 2024
1 parent 08ce7e2 commit 3db8ebe
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/google/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"opencatd-open/pkg/openai"
"opencatd-open/pkg/tokenizer"
Expand Down Expand Up @@ -179,12 +180,15 @@ func ChatProxy(c *gin.Context, chatReq *openai.ChatCompletionRequest) {

var chatResp openai.ChatCompletionStreamResponse
chatResp.Model = chatReq.Model
chatResp.Choices[0].FinishReason = "stop"
choice := openai.Choice{}
choice.FinishReason = "stop"
chatResp.Choices = append(chatResp.Choices, choice)
datachan <- "data: " + string(chatResp.ByteJson())
close(datachan)
break
}
if err != nil {
log.Println(err)
var errResp openai.ErrResponse
errResp.Error.Code = "500"
errResp.Error.Message = err.Error()
Expand All @@ -204,8 +208,11 @@ func ChatProxy(c *gin.Context, chatReq *openai.ChatCompletionRequest) {

var chatResp openai.ChatCompletionStreamResponse
chatResp.Model = chatReq.Model
chatResp.Choices[0].Delta.Role = resp.Candidates[0].Content.Role
chatResp.Choices[0].Delta.Content = content
choice := openai.Choice{}
choice.Delta.Role = resp.Candidates[0].Content.Role
choice.Delta.Content = content
chatResp.Choices = append(chatResp.Choices, choice)

chunk := "data: " + string(chatResp.ByteJson()) + "\n\n"
datachan <- chunk
}
Expand Down

0 comments on commit 3db8ebe

Please sign in to comment.