From 79ec16486d1b38b617d30437cb82b889719c25d4 Mon Sep 17 00:00:00 2001 From: bjwswang Date: Fri, 15 Mar 2024 02:53:55 +0000 Subject: [PATCH 1/2] chore: use same stream options between mpchain and others Signed-off-by: bjwswang --- pkg/appruntime/chain/llmchain.go | 20 +++++++++++--------- pkg/appruntime/chain/mpchain.go | 12 +++++++----- pkg/appruntime/chain/retrievalqachain.go | 19 ++++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/pkg/appruntime/chain/llmchain.go b/pkg/appruntime/chain/llmchain.go index 8b410384d..339b12893 100644 --- a/pkg/appruntime/chain/llmchain.go +++ b/pkg/appruntime/chain/llmchain.go @@ -76,6 +76,12 @@ func (l *LLMChain) Run(ctx context.Context, _ client.Client, args map[string]any instance := l.Instance options := GetChainOptions(instance.Spec.CommonChainConfig) + needStream := false + needStream, ok = args[base.InputIsNeedStreamKeyInArg].(bool) + if ok && needStream { + options = append(options, chains.WithStreamingFunc(stream(args))) + } + // Check if have files as input v3, ok := args["documents"] if ok { @@ -117,18 +123,14 @@ func (l *LLMChain) Run(ctx context.Context, _ client.Client, args map[string]any l.LLMChain = *chain var out string - needStream := false - needStream, ok = args[base.InputIsNeedStreamKeyInArg].(bool) - if ok && needStream { - options = append(options, chains.WithStreamingFunc(stream(args))) + + // Predict based on options + if len(options) > 0 { out, err = chains.Predict(ctx, l.LLMChain, args, options...) } else { - if len(options) > 0 { - out, err = chains.Predict(ctx, l.LLMChain, args, options...) - } else { - out, err = chains.Predict(ctx, l.LLMChain, args) - } + out, err = chains.Predict(ctx, l.LLMChain, args) } + out, err = handleNoErrNoOut(ctx, needStream, out, err, l.LLMChain, args, options) klog.FromContext(ctx).V(5).Info("use llmchain, blocking out:" + out) if err == nil { diff --git a/pkg/appruntime/chain/mpchain.go b/pkg/appruntime/chain/mpchain.go index 554b045c6..1e0474cf4 100644 --- a/pkg/appruntime/chain/mpchain.go +++ b/pkg/appruntime/chain/mpchain.go @@ -34,16 +34,18 @@ import ( const ( // For map-reduce DefaultPromptTemplateForMap = ` - Content: {{.context}} + As an expert document summarizer, please provide a concise summary of the following content based on your expertise. Don't worry about the length of the summary: - With above content, please summarize it with only 1/5 size of the content.Please remind that your answer must use same language(中文或English) of the content. + Content: {{.context}} + + Please note that your response should be in the same language as the content (English or Chinese). ` DefaultPromptTemplatForReduce = ` - Below is the sub-summaries that each is based on a piece of a complete document: + After segmenting the document and generating sub-summaries for each section, it is now time to create a comprehensive summary. Below are the sub-summaries, each based on a specific part of the complete document: - {{.context}} + {{.context}} - Please generate a single summary based on above sub-summaries. + Please generate a cohesive summary that encapsulates the main points from the provided sub-summaries. ` ) diff --git a/pkg/appruntime/chain/retrievalqachain.go b/pkg/appruntime/chain/retrievalqachain.go index a59fabc32..dde143988 100644 --- a/pkg/appruntime/chain/retrievalqachain.go +++ b/pkg/appruntime/chain/retrievalqachain.go @@ -91,6 +91,11 @@ func (l *RetrievalQAChain) Run(ctx context.Context, _ client.Client, args map[st instance := l.Instance options := GetChainOptions(instance.Spec.CommonChainConfig) + needStream := false + needStream, ok = args[base.InputIsNeedStreamKeyInArg].(bool) + if ok && needStream { + options = append(options, chains.WithStreamingFunc(stream(args))) + } // Check if have files as input v5, ok := args["documents"] @@ -119,18 +124,14 @@ func (l *RetrievalQAChain) Run(ctx context.Context, _ client.Client, args map[st l.ConversationalRetrievalQA = chain args["query"] = args["question"] var out string - needStream := false - needStream, ok = args[base.InputIsNeedStreamKeyInArg].(bool) - if ok && needStream { - options = append(options, chains.WithStreamingFunc(stream(args))) + + // Predict based on options + if len(options) > 0 { out, err = chains.Predict(ctx, l.ConversationalRetrievalQA, args, options...) } else { - if len(options) > 0 { - out, err = chains.Predict(ctx, l.ConversationalRetrievalQA, args, options...) - } else { - out, err = chains.Predict(ctx, l.ConversationalRetrievalQA, args) - } + out, err = chains.Predict(ctx, l.ConversationalRetrievalQA, args) } + out, err = handleNoErrNoOut(ctx, needStream, out, err, l.ConversationalRetrievalQA, args, options) klog.FromContext(ctx).V(5).Info("use retrievalqachain, blocking out:" + out) if err == nil { From 289a7f5a5998a27dc92c37507691a5a9bffd313e Mon Sep 17 00:00:00 2001 From: bjwswang Date: Fri, 15 Mar 2024 02:57:30 +0000 Subject: [PATCH 2/2] fix: update dependency Signed-off-by: bjwswang --- deploy/charts/gpu-operator/Chart.lock | 8 +++--- deploy/gpu-operator/nvidia_gpu.yaml | 37 --------------------------- 2 files changed, 4 insertions(+), 41 deletions(-) delete mode 100644 deploy/gpu-operator/nvidia_gpu.yaml diff --git a/deploy/charts/gpu-operator/Chart.lock b/deploy/charts/gpu-operator/Chart.lock index f5c7fcca3..a2a52a523 100644 --- a/deploy/charts/gpu-operator/Chart.lock +++ b/deploy/charts/gpu-operator/Chart.lock @@ -1,6 +1,6 @@ dependencies: - name: node-feature-discovery - repository: https://kubernetes-sigs.github.io/node-feature-discovery/charts - version: 0.14.2 -digest: sha256:84ec59c0c12da825ca7dc25bdac63d0f2106822a129f7fe1f9d60a4023a543ce -generated: "2023-10-10T11:26:00.823757+02:00" + repository: "" + version: v0.14.2 +digest: sha256:8c36de373825e52e288835695ed9298337359d6b65f56971feecb6ac907dcb89 +generated: "2024-03-15T02:54:39.089270185Z" diff --git a/deploy/gpu-operator/nvidia_gpu.yaml b/deploy/gpu-operator/nvidia_gpu.yaml deleted file mode 100644 index 04cf15b88..000000000 --- a/deploy/gpu-operator/nvidia_gpu.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: core.kubebb.k8s.com.cn/v1alpha1 -kind: Repository -metadata: - name: nvidia - namespace: default -spec: - url: https://helm.ngc.nvidia.com/nvidia - pullStategy: - intervalSeconds: 120 - retry: 5 - imageOverride: - - registry: nvcr.io - newRegistry: docker.io - pathOverride: - path: nvidia/gpu-operator - newPath: kubeagi/gpu-operator - - registry: nvcr.io - newRegistry: docker.io - pathOverride: - path: nvidia-node-feature-discovery - newPath: kubeagi/nvidia-node-feature-discovery ---- -apiVersion: core.kubebb.k8s.com.cn/v1alpha1 -kind: ComponentPlan -metadata: - name: gpu-operator - namespace: default -spec: - approved: true - name: gpu-operator - version: "v23.9.0" - component: - name: nvidia.gpu-operator - namespace: default - override: - set: - - driver.enabled=false \ No newline at end of file