From 9d9f8b91ddd3e5419ce586c2c77bfc1fa9424d92 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Mon, 25 Nov 2024 14:12:53 -0500 Subject: [PATCH] fix: stop failing if unable to get knowledge set in API Signed-off-by: Donnie Adams --- pkg/api/handlers/agent.go | 7 ++++--- pkg/api/handlers/workflows.go | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/api/handlers/agent.go b/pkg/api/handlers/agent.go index 4309b0ab1..5b271ef36 100644 --- a/pkg/api/handlers/agent.go +++ b/pkg/api/handlers/agent.go @@ -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{ diff --git a/pkg/api/handlers/workflows.go b/pkg/api/handlers/workflows.go index 6c24de7fe..59c01190a 100644 --- a/pkg/api/handlers/workflows.go +++ b/pkg/api/handlers/workflows.go @@ -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" @@ -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 @@ -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{