From 24612a42134151ce3f30c84ded73a7be8ceab79b Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Mon, 8 Apr 2024 15:42:37 +0800 Subject: [PATCH] feat: add notReadyReasonCode into app Signed-off-by: Abirdcfly --- apiserver/graph/generated/generated.go | 100 ++++++++++++++++---- apiserver/graph/generated/models_gen.go | 11 ++- apiserver/graph/schema/application.gql | 5 + apiserver/graph/schema/application.graphqls | 11 +++ apiserver/graph/schema/gpt.graphqls | 2 +- apiserver/pkg/application/application.go | 32 ++++--- 6 files changed, 129 insertions(+), 32 deletions(-) diff --git a/apiserver/graph/generated/generated.go b/apiserver/graph/generated/generated.go index 9e178de29..8df013ed8 100644 --- a/apiserver/graph/generated/generated.go +++ b/apiserver/graph/generated/generated.go @@ -106,21 +106,22 @@ type ComplexityRoot struct { } ApplicationMetadata struct { - Annotations func(childComplexity int) int - Category func(childComplexity int) int - CreationTimestamp func(childComplexity int) int - Creator func(childComplexity int) int - Description func(childComplexity int) int - DisplayName func(childComplexity int) int - ID func(childComplexity int) int - Icon func(childComplexity int) int - IsPublic func(childComplexity int) int - IsRecommended func(childComplexity int) int - Labels func(childComplexity int) int - Name func(childComplexity int) int - Namespace func(childComplexity int) int - Status func(childComplexity int) int - UpdateTimestamp func(childComplexity int) int + Annotations func(childComplexity int) int + Category func(childComplexity int) int + CreationTimestamp func(childComplexity int) int + Creator func(childComplexity int) int + Description func(childComplexity int) int + DisplayName func(childComplexity int) int + ID func(childComplexity int) int + Icon func(childComplexity int) int + IsPublic func(childComplexity int) int + IsRecommended func(childComplexity int) int + Labels func(childComplexity int) int + Name func(childComplexity int) int + Namespace func(childComplexity int) int + NotReadyReasonCode func(childComplexity int) int + Status func(childComplexity int) int + UpdateTimestamp func(childComplexity int) int } ApplicationMutation struct { @@ -1298,6 +1299,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ApplicationMetadata.Namespace(childComplexity), true + case "ApplicationMetadata.notReadyReasonCode": + if e.complexity.ApplicationMetadata.NotReadyReasonCode == nil { + break + } + + return e.complexity.ApplicationMetadata.NotReadyReasonCode(childComplexity), true + case "ApplicationMetadata.status": if e.complexity.ApplicationMetadata.Status == nil { break @@ -5316,6 +5324,17 @@ type ApplicationMetadata { category:所属分类 """ category: [String] + """ + notReadyReasonCode: 用于指明当前应用状态不正常的原因。状态码要和gpts中同字段保持一致。 + 可选值: + - 空:就绪,应用 可以使用 + - VectorStoreIsNotReady: 向量数据库没有就绪 + - EmbedderIsNotReady: embedder服务没有就绪 + - KnowledgeBaseNotReady: 知识库未就绪,指向量数据库和embedder出错之外的其他情况 + - LLMNotReady: 模型服务没有就绪 + - ConfigError: 应用配置错误,比如写了多个Output节点,比如节点名称重复等其他错误 + """ + notReadyReasonCode: String } input CreateApplicationMetadataInput { @@ -6615,7 +6634,7 @@ type GPT { """ enableUploadFile: Boolean """ - notReadyReasonCode: 用于指明当前gpt状态不正常的原因。 + notReadyReasonCode: 用于指明当前gpt状态不正常的原因。状态码要和应用中同字段保持一致。 可选值: - 空:就绪,gpt 可以使用 - VectorStoreIsNotReady: 向量数据库没有就绪 @@ -9677,6 +9696,8 @@ func (ec *executionContext) fieldContext_Application_metadata(ctx context.Contex return ec.fieldContext_ApplicationMetadata_status(ctx, field) case "category": return ec.fieldContext_ApplicationMetadata_category(ctx, field) + case "notReadyReasonCode": + return ec.fieldContext_ApplicationMetadata_notReadyReasonCode(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type ApplicationMetadata", field.Name) }, @@ -11339,6 +11360,47 @@ func (ec *executionContext) fieldContext_ApplicationMetadata_category(ctx contex return fc, nil } +func (ec *executionContext) _ApplicationMetadata_notReadyReasonCode(ctx context.Context, field graphql.CollectedField, obj *ApplicationMetadata) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ApplicationMetadata_notReadyReasonCode(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.NotReadyReasonCode, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ApplicationMetadata_notReadyReasonCode(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ApplicationMetadata", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _ApplicationMutation_createApplication(ctx context.Context, field graphql.CollectedField, obj *ApplicationMutation) (ret graphql.Marshaler) { fc, err := ec.fieldContext_ApplicationMutation_createApplication(ctx, field) if err != nil { @@ -11408,6 +11470,8 @@ func (ec *executionContext) fieldContext_ApplicationMutation_createApplication(c return ec.fieldContext_ApplicationMetadata_status(ctx, field) case "category": return ec.fieldContext_ApplicationMetadata_category(ctx, field) + case "notReadyReasonCode": + return ec.fieldContext_ApplicationMetadata_notReadyReasonCode(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type ApplicationMetadata", field.Name) }, @@ -11495,6 +11559,8 @@ func (ec *executionContext) fieldContext_ApplicationMutation_updateApplication(c return ec.fieldContext_ApplicationMetadata_status(ctx, field) case "category": return ec.fieldContext_ApplicationMetadata_category(ctx, field) + case "notReadyReasonCode": + return ec.fieldContext_ApplicationMetadata_notReadyReasonCode(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type ApplicationMetadata", field.Name) }, @@ -40606,6 +40672,8 @@ func (ec *executionContext) _ApplicationMetadata(ctx context.Context, sel ast.Se out.Values[i] = ec._ApplicationMetadata_status(ctx, field, obj) case "category": out.Values[i] = ec._ApplicationMetadata_category(ctx, field, obj) + case "notReadyReasonCode": + out.Values[i] = ec._ApplicationMetadata_notReadyReasonCode(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } diff --git a/apiserver/graph/generated/models_gen.go b/apiserver/graph/generated/models_gen.go index 7f4c6e10d..9aa286ef1 100644 --- a/apiserver/graph/generated/models_gen.go +++ b/apiserver/graph/generated/models_gen.go @@ -128,6 +128,15 @@ type ApplicationMetadata struct { Status *string `json:"status,omitempty"` // category:所属分类 Category []*string `json:"category,omitempty"` + // notReadyReasonCode: 用于指明当前应用状态不正常的原因。状态码要和gpts中同字段保持一致。 + // 可选值: + // - 空:就绪,应用 可以使用 + // - VectorStoreIsNotReady: 向量数据库没有就绪 + // - EmbedderIsNotReady: embedder服务没有就绪 + // - KnowledgeBaseNotReady: 知识库未就绪,指向量数据库和embedder出错之外的其他情况 + // - LLMNotReady: 模型服务没有就绪 + // - ConfigError: 应用配置错误,比如写了多个Output节点,比如节点名称重复等其他错误 + NotReadyReasonCode *string `json:"notReadyReasonCode,omitempty"` } func (ApplicationMetadata) IsPageNode() {} @@ -887,7 +896,7 @@ type Gpt struct { ShowNextGuide *bool `json:"showNextGuide,omitempty"` // enableUploadFile 是否开启对话上传文档功能 EnableUploadFile *bool `json:"enableUploadFile,omitempty"` - // notReadyReasonCode: 用于指明当前gpt状态不正常的原因。 + // notReadyReasonCode: 用于指明当前gpt状态不正常的原因。状态码要和应用中同字段保持一致。 // 可选值: // - 空:就绪,gpt 可以使用 // - VectorStoreIsNotReady: 向量数据库没有就绪 diff --git a/apiserver/graph/schema/application.gql b/apiserver/graph/schema/application.gql index 25462e38b..82804af47 100644 --- a/apiserver/graph/schema/application.gql +++ b/apiserver/graph/schema/application.gql @@ -16,6 +16,7 @@ mutation createApplication($input:CreateApplicationMetadataInput!){ isRecommended status category + notReadyReasonCode } } } @@ -38,6 +39,7 @@ mutation updateApplication($input: UpdateApplicationMetadataInput!){ isRecommended status category + notReadyReasonCode } } } @@ -66,6 +68,7 @@ mutation updateApplicationConfig($input: UpdateApplicationConfigInput!){ isRecommended status category + notReadyReasonCode } prologue model @@ -118,6 +121,7 @@ query getApplication($name: String!, $namespace: String!){ isRecommended status category + notReadyReasonCode } prologue model @@ -175,6 +179,7 @@ query listApplications($input: ListCommonInput!) { isRecommended status category + notReadyReasonCode } } } diff --git a/apiserver/graph/schema/application.graphqls b/apiserver/graph/schema/application.graphqls index 60b890c32..f6c04afe7 100644 --- a/apiserver/graph/schema/application.graphqls +++ b/apiserver/graph/schema/application.graphqls @@ -211,6 +211,17 @@ type ApplicationMetadata { category:所属分类 """ category: [String] + """ + notReadyReasonCode: 用于指明当前应用状态不正常的原因。状态码要和gpts中同字段保持一致。 + 可选值: + - 空:就绪,应用 可以使用 + - VectorStoreIsNotReady: 向量数据库没有就绪 + - EmbedderIsNotReady: embedder服务没有就绪 + - KnowledgeBaseNotReady: 知识库未就绪,指向量数据库和embedder出错之外的其他情况 + - LLMNotReady: 模型服务没有就绪 + - ConfigError: 应用配置错误,比如写了多个Output节点,比如节点名称重复等其他错误 + """ + notReadyReasonCode: String } input CreateApplicationMetadataInput { diff --git a/apiserver/graph/schema/gpt.graphqls b/apiserver/graph/schema/gpt.graphqls index 9e14d1847..1dac5b672 100644 --- a/apiserver/graph/schema/gpt.graphqls +++ b/apiserver/graph/schema/gpt.graphqls @@ -95,7 +95,7 @@ type GPT { """ enableUploadFile: Boolean """ - notReadyReasonCode: 用于指明当前gpt状态不正常的原因。 + notReadyReasonCode: 用于指明当前gpt状态不正常的原因。状态码要和应用中同字段保持一致。 可选值: - 空:就绪,gpt 可以使用 - VectorStoreIsNotReady: 向量数据库没有就绪 diff --git a/apiserver/pkg/application/application.go b/apiserver/pkg/application/application.go index 0b8c926e0..ef632d7d2 100644 --- a/apiserver/pkg/application/application.go +++ b/apiserver/pkg/application/application.go @@ -42,6 +42,7 @@ import ( pkgconf "github.com/kubeagi/arcadia/apiserver/config" "github.com/kubeagi/arcadia/apiserver/graph/generated" "github.com/kubeagi/arcadia/apiserver/pkg/common" + "github.com/kubeagi/arcadia/apiserver/pkg/gpt" "github.com/kubeagi/arcadia/apiserver/pkg/utils" "github.com/kubeagi/arcadia/pkg/config" "github.com/kubeagi/arcadia/pkg/datasource" @@ -85,20 +86,21 @@ func cr2app(prompt *apiprompt.Prompt, chainConfig *apichain.CommonChainConfig, r icon := common.AppIconLink(app, pkgconf.GetConfig().PlaygroundEndpointPrefix) gApp := &generated.Application{ Metadata: &generated.ApplicationMetadata{ - Name: app.Name, - Namespace: app.Namespace, - ID: pointer.String(string(app.UID)), - Labels: utils.MapStr2Any(app.Labels), - Annotations: utils.MapStr2Any(app.Annotations), - DisplayName: pointer.String(app.Spec.DisplayName), - Description: pointer.String(app.Spec.Description), - Icon: &icon, - Creator: pointer.String(app.Spec.Creator), - CreationTimestamp: &app.CreationTimestamp.Time, - UpdateTimestamp: UpdateTimestamp, - IsPublic: pointer.Bool(app.Spec.IsPublic), - IsRecommended: pointer.Bool(app.Spec.IsRecommended), - Status: pointer.String(status), + Name: app.Name, + Namespace: app.Namespace, + ID: pointer.String(string(app.UID)), + Labels: utils.MapStr2Any(app.Labels), + Annotations: utils.MapStr2Any(app.Annotations), + DisplayName: pointer.String(app.Spec.DisplayName), + Description: pointer.String(app.Spec.Description), + Icon: &icon, + Creator: pointer.String(app.Spec.Creator), + CreationTimestamp: &app.CreationTimestamp.Time, + UpdateTimestamp: UpdateTimestamp, + IsPublic: pointer.Bool(app.Spec.IsPublic), + IsRecommended: pointer.Bool(app.Spec.IsRecommended), + Status: pointer.String(status), + NotReadyReasonCode: pointer.String(string(gpt.GetGPTNotReadyReasonCode(app))), }, Prologue: pointer.String(app.Spec.Prologue), ShowNextGuide: pointer.Bool(app.Spec.ShowNextGuide), @@ -491,11 +493,13 @@ func UpdateApplicationConfig(ctx context.Context, c client.Client, input generat }, ChunkSize: pointer.IntDeref(input.ChunkSize, 1024), ChunkOverlap: input.ChunkOverlap, + BatchSize: pointer.IntDeref(input.BatchSize, 3), LoaderConfig: apidocumentloader.LoaderConfig{}, }, } if _, err := controllerutil.CreateOrUpdate(ctx, c, documentLoader, func() error { documentLoader.Spec.ChunkSize = pointer.IntDeref(input.ChunkSize, documentLoader.Spec.ChunkSize) + documentLoader.Spec.BatchSize = pointer.IntDeref(input.BatchSize, documentLoader.Spec.BatchSize) if input.ChunkOverlap == nil { documentLoader.Spec.ChunkOverlap = pointer.Int(50) } else {