Skip to content

Commit

Permalink
feat: dump failure response body for baichuan
Browse files Browse the repository at this point in the history
Signed-off-by: Zhou Zhiqiang <[email protected]>
  • Loading branch information
STRRL committed Apr 2, 2024
1 parent fa5fe22 commit e47d9fe
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions provider/Baichuan/chat_completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
"net/http"
)

Expand All @@ -29,8 +32,18 @@ func (c *Client) ChatCompletion(body ChatCompletionRequest) (result ChatCompleti

}
defer resp.Body.Close()

err = json.NewDecoder(resp.Body).Decode(&result)
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return ChatCompletionResponse{}, fmt.Errorf("reading response body: %w", err)
}
if resp.StatusCode != http.StatusOK {
slog.Error("Baichuan ChatCompletion: response status code not 200",
"status_code", resp.StatusCode,
"response_body", string(responseBody),
)
return ChatCompletionResponse{}, ErrNotSuccess
}
json.Unmarshal(responseBody, &result)
if err != nil {
return ChatCompletionResponse{}, err

Expand Down

0 comments on commit e47d9fe

Please sign in to comment.