mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-22 08:14:02 +01:00
Better log messages and error messages
This commit is contained in:
parent
afe1a38a0e
commit
6962233e1e
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user