Better log messages and error messages

This commit is contained in:
David Dworken 2023-11-11 21:44:21 -08:00
parent afe1a38a0e
commit 6962233e1e
2 changed files with 4 additions and 2 deletions

View File

@ -34,6 +34,7 @@ func GetAiSuggestions(ctx context.Context, query string, numberCompletions int)
}
func GetAiSuggestionsViaHishtoryApi(ctx context.Context, query string, numberCompletions int) ([]string, error) {
hctx.GetLogger().Infof("Running OpenAI query for %#v", query)
req := ai.AiSuggestionRequest{
DeviceId: hctx.GetConf(ctx).DeviceId,
UserId: data.UserId(hctx.GetConf(ctx).UserSecret),
@ -53,5 +54,6 @@ func GetAiSuggestionsViaHishtoryApi(ctx context.Context, query string, numberCom
if err != nil {
return nil, fmt.Errorf("failed to parse /api/v1/ai-suggest response: %w", err)
}
hctx.GetLogger().Infof("For OpenAI query=%#v ==> %#v", query, resp.Suggestions)
return resp.Suggestions, nil
}

View File

@ -91,10 +91,10 @@ func GetAiSuggestionsViaOpenAiApi(query string, numberCompletions int) ([]string
var apiResp openAiResponse
err = json.Unmarshal(bodyText, &apiResp)
if err != nil {
return nil, OpenAiUsage{}, fmt.Errorf("failed to parse OpenAI API response: %w", err)
return nil, OpenAiUsage{}, fmt.Errorf("failed to parse OpenAI API response=%#v: %w", bodyText, err)
}
if len(apiResp.Choices) == 0 {
return nil, OpenAiUsage{}, fmt.Errorf("OpenAI API returned zero choicesm, resp=%#v", apiResp)
return nil, OpenAiUsage{}, fmt.Errorf("OpenAI API returned zero choices, resp=%#v", apiResp)
}
ret := make([]string, 0)
for _, item := range apiResp.Choices {