diff --git a/pkg/api/handlers/modelprovider.go b/pkg/api/handlers/modelprovider.go index a9864c88..eb496dcc 100644 --- a/pkg/api/handlers/modelprovider.go +++ b/pkg/api/handlers/modelprovider.go @@ -7,13 +7,11 @@ import ( "github.com/gptscript-ai/go-gptscript" "github.com/obot-platform/obot/apiclient/types" - "github.com/obot-platform/obot/logger" "github.com/obot-platform/obot/pkg/api" "github.com/obot-platform/obot/pkg/gateway/server/dispatcher" "github.com/obot-platform/obot/pkg/invoke" v1 "github.com/obot-platform/obot/pkg/storage/apis/otto.otto8.ai/v1" "github.com/obot-platform/obot/pkg/system" - apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" kclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -115,8 +113,7 @@ func (mp *ModelProviderHandler) Validate(req api.Context) error { return types.NewErrBadRequest("%q is not a model provider", ref.Name) } - l := logger.Package() - l.Debugf("Validating model provider %q", ref.Name) + log.Debugf("Validating model provider %q", ref.Name) var envVars map[string]string if err := req.Read(&envVars); err != nil { @@ -138,10 +135,8 @@ func (mp *ModelProviderHandler) Validate(req api.Context) error { }, } - if err := req.Get(thread, thread.Name); apierrors.IsNotFound(err) { - if err = req.Create(thread); err != nil { - return fmt.Errorf("failed to create thread: %w", err) - } + if err := req.Create(thread); err != nil { + return fmt.Errorf("failed to create thread: %w", err) } defer func() { _ = req.Delete(thread) }() @@ -155,8 +150,11 @@ func (mp *ModelProviderHandler) Validate(req api.Context) error { res, err := task.Result(req.Context()) if err != nil { if strings.Contains(err.Error(), "tool not found: validate from "+ref.Spec.Reference) { // there's no simple way to do errors.As/.Is at this point unfortunately - l.Infof("Model provider %q does not provide a validate tool. Looking for 'validate from %s'", ref.Name, ref.Spec.Reference) - return nil // Do not fail if model provider doesn't provide a validate tool + log.Errorf("Model provider %q does not provide a validate tool. Looking for 'validate from %s'", ref.Name, ref.Spec.Reference) + return types.NewErrNotFound( + fmt.Sprintf("`validate from %s` tool not found", ref.Spec.Reference), + ref.Name, + ) } return &ValidationError{Err: strings.Trim(err.Error(), "\"'")} }