Skip to content

Commit

Permalink
fix: stop failing if unable to get knowledge set in API
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Nov 25, 2024
1 parent 1ed16ce commit 9d9f8b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/api/handlers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ func convertAgent(agent v1.Agent, req api.Context) (*types.Agent, error) {
var embeddingModel string
if len(agent.Status.KnowledgeSetNames) > 0 {
var ks v1.KnowledgeSet
if err := req.Get(&ks, agent.Status.KnowledgeSetNames[0]); err != nil {
return nil, fmt.Errorf("failed to get KnowledgeSet %q: %v", agent.Status.KnowledgeSetNames[0], err)
if err := req.Get(&ks, agent.Status.KnowledgeSetNames[0]); err == nil {
embeddingModel = ks.Status.TextEmbeddingModel
} else {
log.Warnf("failed to get KnowledgeSet %q for agent %q: %v", agent.Status.KnowledgeSetNames[0], agent.Name, err)
}
embeddingModel = ks.Status.TextEmbeddingModel
}

return &types.Agent{
Expand Down
10 changes: 7 additions & 3 deletions pkg/api/handlers/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/gptscript-ai/go-gptscript"
"github.com/gptscript-ai/gptscript/pkg/mvl"
"github.com/otto8-ai/otto8/apiclient/types"
"github.com/otto8-ai/otto8/pkg/alias"
"github.com/otto8-ai/otto8/pkg/api"
Expand All @@ -18,6 +19,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var log = mvl.Package()

type WorkflowHandler struct {
gptscript *gptscript.GPTScript
serverURL string
Expand Down Expand Up @@ -149,10 +152,11 @@ func convertWorkflow(workflow v1.Workflow, req api.Context) (*types.Workflow, er
var embeddingModel string
if len(workflow.Status.KnowledgeSetNames) > 0 {
var ks v1.KnowledgeSet
if err := req.Get(&ks, workflow.Status.KnowledgeSetNames[0]); err != nil {
return nil, fmt.Errorf("failed to get KnowledgeSet %q: %v", workflow.Status.KnowledgeSetNames[0], err)
if err := req.Get(&ks, workflow.Status.KnowledgeSetNames[0]); err == nil {
embeddingModel = ks.Status.TextEmbeddingModel
} else {
log.Warnf("failed to get KnowledgeSet %q for workflow %q: %v", workflow.Status.KnowledgeSetNames[0], workflow.Name, err)
}
embeddingModel = ks.Status.TextEmbeddingModel
}

return &types.Workflow{
Expand Down

0 comments on commit 9d9f8b9

Please sign in to comment.