diff --git a/api/app-node/agent/v1alpha1/agent_types.go b/api/app-node/agent/v1alpha1/agent_types.go index 21ac6b732..747ad88ca 100644 --- a/api/app-node/agent/v1alpha1/agent_types.go +++ b/api/app-node/agent/v1alpha1/agent_types.go @@ -42,6 +42,9 @@ type AgentConfig struct { // Options defines the options to be used by agent type Options struct { + // Whether to show tool action in the streaming output + // +kubebuilder:default=false + ShowToolAction bool `json:"showToolAction,omitempty"` // +kubebuilder:validation:Minimum=1 // +kubebuilder:validation:Maximum=10 // +kubebuilder:default=5 diff --git a/config/crd/bases/arcadia.kubeagi.k8s.com.cn_agents.yaml b/config/crd/bases/arcadia.kubeagi.k8s.com.cn_agents.yaml index d7a366aa2..cb8d1216a 100644 --- a/config/crd/bases/arcadia.kubeagi.k8s.com.cn_agents.yaml +++ b/config/crd/bases/arcadia.kubeagi.k8s.com.cn_agents.yaml @@ -67,6 +67,10 @@ spec: maximum: 10 minimum: 1 type: integer + showToolAction: + default: false + description: Whether to show tool action in the streaming output + type: boolean type: object type: default: zeroShot diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index bcd01d0f5..332e93275 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -196,6 +196,32 @@ rules: - get - patch - update +- apiGroups: + - arcadia.kubeagi.k8s.com.cn + resources: + - documentloaders + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - arcadia.kubeagi.k8s.com.cn + resources: + - documentloaders/finalizers + verbs: + - update +- apiGroups: + - arcadia.kubeagi.k8s.com.cn + resources: + - documentloaders/status + verbs: + - get + - patch + - update - apiGroups: - arcadia.kubeagi.k8s.com.cn resources: diff --git a/controllers/base/application_controller.go b/controllers/base/application_controller.go index 84f8c54f2..3faae168a 100644 --- a/controllers/base/application_controller.go +++ b/controllers/base/application_controller.go @@ -85,6 +85,9 @@ type ApplicationReconciler struct { //+kubebuilder:rbac:groups=arcadia.kubeagi.k8s.com.cn,resources=agents,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=arcadia.kubeagi.k8s.com.cn,resources=agents/status,verbs=get;update;patch //+kubebuilder:rbac:groups=arcadia.kubeagi.k8s.com.cn,resources=agents/finalizers,verbs=update +//+kubebuilder:rbac:groups=arcadia.kubeagi.k8s.com.cn,resources=documentloaders,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=arcadia.kubeagi.k8s.com.cn,resources=documentloaders/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=arcadia.kubeagi.k8s.com.cn,resources=documentloaders/finalizers,verbs=update // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. diff --git a/deploy/charts/arcadia/Chart.yaml b/deploy/charts/arcadia/Chart.yaml index 9508b8b07..aa278aae7 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(Also a KubeBB Component) for KubeAGI Arcadia type: application -version: 0.3.1 +version: 0.3.2 appVersion: "0.2.0" keywords: diff --git a/deploy/charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_agents.yaml b/deploy/charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_agents.yaml index d7a366aa2..cb8d1216a 100644 --- a/deploy/charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_agents.yaml +++ b/deploy/charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_agents.yaml @@ -67,6 +67,10 @@ spec: maximum: 10 minimum: 1 type: integer + showToolAction: + default: false + description: Whether to show tool action in the streaming output + type: boolean type: object type: default: zeroShot diff --git a/deploy/charts/arcadia/templates/rbac.yaml b/deploy/charts/arcadia/templates/rbac.yaml index 4d94da9de..500657ece 100644 --- a/deploy/charts/arcadia/templates/rbac.yaml +++ b/deploy/charts/arcadia/templates/rbac.yaml @@ -213,6 +213,32 @@ rules: - get - patch - update +- apiGroups: + - arcadia.kubeagi.k8s.com.cn + resources: + - documentloaders + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - arcadia.kubeagi.k8s.com.cn + resources: + - documentloaders/finalizers + verbs: + - update +- apiGroups: + - arcadia.kubeagi.k8s.com.cn + resources: + - documentloaders/status + verbs: + - get + - patch + - update - apiGroups: - arcadia.kubeagi.k8s.com.cn resources: diff --git a/deploy/charts/arcadia/values.yaml b/deploy/charts/arcadia/values.yaml index cdf9ea367..117cbe4b4 100644 --- a/deploy/charts/arcadia/values.yaml +++ b/deploy/charts/arcadia/values.yaml @@ -12,7 +12,7 @@ global: # @param resources Resources to be used controller: loglevel: 3 - image: kubeagi/arcadia:v0.2.0 + image: kubeagi/arcadia:latest imagePullPolicy: IfNotPresent resources: limits: @@ -27,7 +27,7 @@ controller: apiserver: bingKey: c30e4d7f3ec24c31a489f883616844b5 loglevel: 3 - image: kubeagi/arcadia:v0.2.0 + image: kubeagi/arcadia:latest enableplayground: false port: 8081 ingress: @@ -45,7 +45,7 @@ apiserver: portal: enabled: true kubebbEnabled: true - image: kubeagi/ops-console:v0.2.0 + image: kubeagi/ops-console:latest port: 80 ingress: path: kubeagi-portal-public @@ -108,7 +108,7 @@ minio: # Related project: https://github.com/kubeagi/arcadia/tree/main/data-processing dataprocess: enabled: true - image: kubeagi/data-processing:v0.2.0 + image: kubeagi/data-processing:latest port: 28888 config: llm: diff --git a/main.go b/main.go index 9f3b27c7f..5ac1b0133 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ import ( agentv1alpha1 "github.com/kubeagi/arcadia/api/app-node/agent/v1alpha1" apichain "github.com/kubeagi/arcadia/api/app-node/chain/v1alpha1" + documentloaderv1alpha1 "github.com/kubeagi/arcadia/api/app-node/documentloader/v1alpha1" apiprompt "github.com/kubeagi/arcadia/api/app-node/prompt/v1alpha1" apiretriever "github.com/kubeagi/arcadia/api/app-node/retriever/v1alpha1" arcadiav1alpha1 "github.com/kubeagi/arcadia/api/base/v1alpha1" @@ -73,6 +74,7 @@ func init() { utilruntime.Must(batchv1.AddToScheme(scheme)) utilruntime.Must(agentv1alpha1.AddToScheme(scheme)) utilruntime.Must(rbacv1.AddToScheme(scheme)) + utilruntime.Must(documentloaderv1alpha1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme } diff --git a/pkg/appruntime/agent/executor.go b/pkg/appruntime/agent/executor.go index 6f3374458..5af7a3222 100644 --- a/pkg/appruntime/agent/executor.go +++ b/pkg/appruntime/agent/executor.go @@ -71,6 +71,9 @@ func (p *Executor) Run(ctx context.Context, cli client.Client, args map[string]a continue } allowedTools = append(allowedTools, tool) + case "calculator": + tool := tools.Calculator{} + allowedTools = append(allowedTools, tool) case "scraper": // prepare options from toolSpec options := make([]scraper.Options, 0) @@ -109,16 +112,20 @@ func (p *Executor) Run(ctx context.Context, cli client.Client, args map[string]a } allowedTools = append(allowedTools, tool) default: - return nil, fmt.Errorf("no tool found with name: %s", toolSpec.Name) + // Just continue if the tool does not exist + klog.Errorln("no tool found with name: %s", toolSpec.Name) } } // Initialize executor using langchaingo executorOptions := func(o *agents.CreationOptions) { agents.WithMaxIterations(instance.Spec.Options.MaxIterations)(o) - if needStream, ok := args["_need_stream"].(bool); ok && needStream { - streamHandler := StreamHandler{callbacks.SimpleHandler{}, args} - agents.WithCallbacksHandler(streamHandler)(o) + // Only show tool action in the streaming output if configured + if instance.Spec.Options.ShowToolAction { + if needStream, ok := args["_need_stream"].(bool); ok && needStream { + streamHandler := StreamHandler{callbacks.SimpleHandler{}, args} + agents.WithCallbacksHandler(streamHandler)(o) + } } } executor, err := agents.Initialize(llm, allowedTools, agents.ZeroShotReactDescription, executorOptions) @@ -132,9 +139,6 @@ func (p *Executor) Run(ctx context.Context, cli client.Client, args map[string]a return args, fmt.Errorf("error when call agent: %w", err) } klog.FromContext(ctx).V(5).Info("use agent, blocking out:", response["output"]) - if err == nil { - args["_answer"] = response["output"] - return args, nil - } + args["_answer"] = response["output"] return args, nil } diff --git a/pkg/appruntime/documentloader/documentloader.go b/pkg/appruntime/documentloader/documentloader.go index 5a60d3d55..70e6f6e51 100644 --- a/pkg/appruntime/documentloader/documentloader.go +++ b/pkg/appruntime/documentloader/documentloader.go @@ -54,7 +54,7 @@ func NewDocumentLoader(baseNode base.BaseNode) *DocumentLoader { func (dl *DocumentLoader) Init(ctx context.Context, cli client.Client, _ map[string]any) error { instance := &v1alpha1.DocumentLoader{} if err := cli.Get(ctx, types.NamespacedName{Namespace: dl.RefNamespace(), Name: dl.Ref.Name}, instance); err != nil { - return fmt.Errorf("can't find the knowledgebase in cluster: %w", err) + return fmt.Errorf("can't find the documentloader in cluster: %w", err) } dl.Instance = instance return nil diff --git a/pkg/appruntime/prompt/prompt.go b/pkg/appruntime/prompt/prompt.go index b538543f4..610e11a2b 100644 --- a/pkg/appruntime/prompt/prompt.go +++ b/pkg/appruntime/prompt/prompt.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "strings" + "time" "github.com/tmc/langchaingo/prompts" "k8s.io/apimachinery/pkg/types" @@ -69,7 +70,15 @@ func (p *Prompt) Run(ctx context.Context, cli client.Client, args map[string]any } ps = append(ps, prompts.NewHumanMessagePromptTemplate(instance.Spec.UserMessage, []string{"question"})) } - template := prompts.NewChatPromptTemplate(ps) + template := prompts.ChatPromptTemplate{ + Messages: ps, + // Add the date function to the prompt, and it'll be called when the prompt template is rendered + PartialVariables: map[string]any{ + "date": func() string { + return fmt.Sprintf("%s %s", time.Now().Format("2006-01-02"), time.Now().Weekday()) + }, + }, + } // todo format p.ChatPromptTemplate = template args["prompt"] = p diff --git a/pypi/data-processing/requirements.txt b/pypi/data-processing/requirements.txt index e0cec85aa..5e10b699d 100644 --- a/pypi/data-processing/requirements.txt +++ b/pypi/data-processing/requirements.txt @@ -17,7 +17,7 @@ duckdb==0.9.2 DBUtils==3.0.3 pyyaml==6.0.1 -opencc==1.1.2 +opencc==0.2 opencc-python-reimplemented==0.1.7 selectolax==0.3.17 openai==1.3.7