Skip to content

Commit

Permalink
change: address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Jan 7, 2025
1 parent fb1cb19 commit ab6f22f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/api/handlers/modelprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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) }()
Expand All @@ -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(), "\"'")}
}
Expand Down

0 comments on commit ab6f22f

Please sign in to comment.