Skip to content

Commit

Permalink
chore: error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Dec 23, 2024
1 parent ed46b08 commit a140cbd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/availablemodels/availablemodels.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ForProvider(ctx context.Context, dispatcher *dispatcher.Dispatcher, modelPr

r, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String()+"/v1/models", nil)
if err != nil {
return nil, fmt.Errorf("failed to create request to model provider %s: %w", modelProviderName, err)
return nil, fmt.Errorf("failed to create request to model provider %q: %w", modelProviderName, err)
}

if token != "" {
Expand All @@ -28,18 +28,18 @@ func ForProvider(ctx context.Context, dispatcher *dispatcher.Dispatcher, modelPr

resp, err := http.DefaultClient.Do(r)
if err != nil {
return nil, fmt.Errorf("failed to make request to model provider %s: %w", modelProviderName, err)
return nil, fmt.Errorf("failed to make request to model provider %q: %w", modelProviderName, err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
message, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("failed to get model list from model provider %s: %s", modelProviderName, message)
return nil, fmt.Errorf("failed to get model list from model provider %q: %s", modelProviderName, message)
}

var oModels openai.ModelsList
if err = json.NewDecoder(resp.Body).Decode(&oModels); err != nil {
return nil, fmt.Errorf("failed to decode model list from model provider %s: %w", modelProviderName, err)
return nil, fmt.Errorf("failed to decode model list from model provider %q: %w", modelProviderName, err)
}

return &oModels, nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/handlers/toolreference/toolreference.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ func (h *Handler) BackPopulateModels(req router.Request, _ router.Response) erro
availableModels, err := availablemodels.ForProvider(req.Ctx, h.dispatcher, req.Namespace, req.Name)
if err != nil {
// Don't error and retry because it will likely fail again. Log the error, and the user can re-sync manually.
log.Errorf("Failed to get available models for model provider %q: %v", toolRef.Name, err)
// Also, the toolRef.Status.Error field will bubble up to the user in the UI.
toolRef.Status.Error = err.Error()
log.Errorf(err.Error())
return nil
}

Expand Down

0 comments on commit a140cbd

Please sign in to comment.