mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:31:43 +00:00
cody-gateway: handle missing Google response (#63895)
- Logs a warning instead of returning an error when the Google response is missing - This prevents the API from returning an error when the Google response is empty, which can happen when Google is not happy with the question due to safety issues. We will only log a decoder error as error. <!-- PR description tips: https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e --> ## Test plan <!-- REQUIRED; info at https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles --> only the log level was updated for empty responses. the function behavior was not changed. ## Changelog <!-- OPTIONAL; info at https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c --> cody-gateway: log missing Google response as warning
This commit is contained in:
parent
56817a7a9e
commit
468a01a3ab
@ -168,5 +168,6 @@ func parseGoogleTokenUsage(r io.Reader, logger log.Logger) (promptTokens int, co
|
||||
return res.UsageMetadata.PromptTokenCount, res.UsageMetadata.CompletionTokenCount, nil
|
||||
}
|
||||
|
||||
return -1, -1, errors.New("no Google response found")
|
||||
logger.Warn("no Google response found", log.Error(err))
|
||||
return -1, -1, nil
|
||||
}
|
||||
|
||||
@ -128,13 +128,13 @@ func TestParseGoogleTokenUsage(t *testing.T) {
|
||||
name: "no prefix",
|
||||
input: `{"usageMetadata": {"promptTokenCount": 10, "candidatesTokenCount": 20}}`,
|
||||
want: nil,
|
||||
wantErr: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "empty input",
|
||||
input: ``,
|
||||
want: nil,
|
||||
wantErr: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "multiple lines with one valid",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user