Skip to content

Commit

Permalink
fix: when no knowledgebase setting or is empty, we should ignore it
Browse files Browse the repository at this point in the history
Signed-off-by: Abirdcfly <[email protected]>
  • Loading branch information
Abirdcfly committed Dec 24, 2023
1 parent 41f52e4 commit 17832f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions apiserver/pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func UpdateApplicationConfig(ctx context.Context, c dynamic.Interface, input gen
return nil, err
}
chainKind := "LLMChain"
if input.Knowledgebase != nil {
if utils.HasValue(input.Knowledgebase) {
chainKind = "RetrievalQAChain"
}

Expand Down Expand Up @@ -355,7 +355,7 @@ func UpdateApplicationConfig(ctx context.Context, c dynamic.Interface, input gen
}
if err = createOrUpdateResource(ctx, c, common.SchemaOf(&common.ArcadiaAPIGroup, "Prompt"), input.Namespace, input.Name, func() {
var userMessage string
if input.UserPrompt == nil || len(strings.TrimSpace(*input.UserPrompt)) == 0 {
if !utils.HasValue(input.UserPrompt) {
userMessage = apiprompt.DefaultUserPrompt
} else {
userMessage = *input.UserPrompt
Expand All @@ -373,7 +373,7 @@ func UpdateApplicationConfig(ctx context.Context, c dynamic.Interface, input gen
llmchainInput *apichain.LLMChainInput
retriever *apiretriever.KnowledgeBaseRetriever
)
if input.Knowledgebase != nil {
if utils.HasValue(input.Knowledgebase) {
qachain := &apichain.RetrievalQAChain{
TypeMeta: metav1.TypeMeta{
Kind: "RetrievalQAChain",
Expand Down Expand Up @@ -497,7 +497,7 @@ func UpdateApplicationConfig(ctx context.Context, c dynamic.Interface, input gen
}

// 4. create or update retriever
if input.Knowledgebase != nil {
if utils.HasValue(input.Knowledgebase) {
retriever = &apiretriever.KnowledgeBaseRetriever{
TypeMeta: metav1.TypeMeta{
Kind: "KnowledgeBaseRetriever",
Expand Down
6 changes: 6 additions & 0 deletions apiserver/pkg/utils/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package utils

import (
"strings"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

Expand All @@ -32,3 +34,7 @@ func MapStr2Any(input map[string]string) map[string]any {
}
return output
}

func HasValue(s *string) bool {
return s != nil && strings.TrimSpace(*s) != ""
}

0 comments on commit 17832f0

Please sign in to comment.