From 50ec28929db6969ffb8e5e2edf60b8118e11dc31 Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Fri, 22 Dec 2023 16:32:19 +0800 Subject: [PATCH] feat: when no userPrompt setting, we use default one Signed-off-by: Abirdcfly --- .../prompt/v1alpha1/prompttemplate.go | 21 +++++++++++++++++++ .../prompt/v1alpha1/prompttemplate_types.go | 1 + apiserver/pkg/application/application.go | 8 ++++++- ...pt.arcadia.kubeagi.k8s.com.cn_prompts.yaml | 1 + deploy/charts/arcadia/Chart.yaml | 2 +- ...pt.arcadia.kubeagi.k8s.com.cn_prompts.yaml | 1 + 6 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 api/app-node/prompt/v1alpha1/prompttemplate.go diff --git a/api/app-node/prompt/v1alpha1/prompttemplate.go b/api/app-node/prompt/v1alpha1/prompttemplate.go new file mode 100644 index 000000000..1514d5966 --- /dev/null +++ b/api/app-node/prompt/v1alpha1/prompttemplate.go @@ -0,0 +1,21 @@ +/* +Copyright 2023 KubeAGI. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +const ( + DefaultUserPrompt = `{{.question}}` +) diff --git a/api/app-node/prompt/v1alpha1/prompttemplate_types.go b/api/app-node/prompt/v1alpha1/prompttemplate_types.go index 1dbc22216..d70ce5cfa 100644 --- a/api/app-node/prompt/v1alpha1/prompttemplate_types.go +++ b/api/app-node/prompt/v1alpha1/prompttemplate_types.go @@ -37,6 +37,7 @@ type CommonPromptConfig struct { // system prompts, support template SystemMessage string `json:"systemMessage,omitempty"` // user prompts,support template + // +kubebuilder:default="{{.question}}" UserMessage string `json:"userMessage,omitempty"` } diff --git a/apiserver/pkg/application/application.go b/apiserver/pkg/application/application.go index a3717bb3a..1216d08e1 100644 --- a/apiserver/pkg/application/application.go +++ b/apiserver/pkg/application/application.go @@ -354,8 +354,14 @@ 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 { + userMessage = apiprompt.DefaultUserPrompt + } else { + userMessage = *input.UserPrompt + } prompt.Spec.CommonPromptConfig = apiprompt.CommonPromptConfig{ - UserMessage: pointer.StringDeref(input.UserPrompt, "just say something."), + UserMessage: userMessage, } }, prompt); err != nil { return nil, err diff --git a/config/crd/bases/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml b/config/crd/bases/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml index a8f1ca74d..1b64d0f68 100644 --- a/config/crd/bases/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml +++ b/config/crd/bases/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml @@ -80,6 +80,7 @@ spec: description: system prompts, support template type: string userMessage: + default: '{{.question}}' description: user prompts,support template type: string type: object diff --git a/deploy/charts/arcadia/Chart.yaml b/deploy/charts/arcadia/Chart.yaml index 4249bb3fb..a6ded5cc5 100644 --- a/deploy/charts/arcadia/Chart.yaml +++ b/deploy/charts/arcadia/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: arcadia description: A Helm chart(KubeBB Component) for KubeAGI Arcadia type: application -version: 0.1.50 +version: 0.1.51 appVersion: "0.0.1" keywords: diff --git a/deploy/charts/arcadia/crds/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml b/deploy/charts/arcadia/crds/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml index a8f1ca74d..1b64d0f68 100644 --- a/deploy/charts/arcadia/crds/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml +++ b/deploy/charts/arcadia/crds/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml @@ -80,6 +80,7 @@ spec: description: system prompts, support template type: string userMessage: + default: '{{.question}}' description: user prompts,support template type: string type: object