diff --git a/controller/ai-local/iml.go b/controller/ai-local/iml.go index f2c13487..a34d4a9b 100644 --- a/controller/ai-local/iml.go +++ b/controller/ai-local/iml.go @@ -267,7 +267,7 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model }) return func() error { - path := fmt.Sprintf("/%s/chat", strings.Trim(prefix, "/")) + path := fmt.Sprintf("/%s/chat/completions", strings.Trim(prefix, "/")) timeout := 300000 retry := 0 aiPrompt := &ai_api_dto.AiPrompt{ diff --git a/module/ai-api/schema.go b/module/ai-api/schema.go index 5c7c7c5c..b510f044 100644 --- a/module/ai-api/schema.go +++ b/module/ai-api/schema.go @@ -23,12 +23,32 @@ func genOperation(summary string, description string, variables []*ai_api_dto.Ai operation := openapi3.NewOperation() operation.Summary = summary operation.Description = description + operation.AddParameter(&openapi3.Parameter{ + Name: "Authorization", + In: "header", + Required: true, + Example: "Bearer {your_apipark_apikey}", + }) operation.RequestBody = genRequestBody(variables) operation.Responses = &openapi3.Responses{} operation.Responses.Set("200", genResponse()) return operation } +func genRequestHeaders() openapi3.Parameters { + return openapi3.Parameters{ + { + Value: &openapi3.Parameter{ + Name: "Authorization", + In: "header", + Description: "your_apipark_apikey", // 替换Prompt的变量列表 + Required: true, + Example: "your_apipark_apikey", + }, + }, + } +} + func genRequestParameters(variables []*ai_api_dto.AiPromptVariable) openapi3.Parameters { return openapi3.Parameters{ { diff --git a/module/ai/dto/input.go b/module/ai/dto/input.go index 45f8468f..adeb7286 100644 --- a/module/ai/dto/input.go +++ b/module/ai/dto/input.go @@ -17,5 +17,4 @@ type Sort struct { type NewProvider struct { Name string `json:"name"` - Type string `json:"type"` } diff --git a/module/ai/iml.go b/module/ai/iml.go index f09c8be5..d3d9b535 100644 --- a/module/ai/iml.go +++ b/module/ai/iml.go @@ -201,12 +201,9 @@ func (i *imlProviderModule) Delete(ctx context.Context, id string) error { } func (i *imlProviderModule) AddProvider(ctx context.Context, input *ai_dto.NewProvider) (*ai_dto.SimpleProvider, error) { - switch input.Type { - case "customize": - _, has := model_runtime.GetProvider(strings.ToLower(input.Name)) - if has { - return nil, fmt.Errorf("provider `%s` duplicate", input.Name) - } + _, has := model_runtime.GetProvider(strings.ToLower(input.Name)) + if has { + return nil, fmt.Errorf("provider `%s` duplicate", input.Name) } // uuid = name if has := i.providerService.CheckUuidDuplicate(ctx, input.Name); has { @@ -249,7 +246,7 @@ func (i *imlProviderModule) SimpleProvider(ctx context.Context, id string) (*ai_ func (i *imlProviderModule) ConfiguredProviders(ctx context.Context, keyword string) ([]*ai_dto.ConfiguredProviderItem, error) { // 获取已配置的AI服务商 - list, err := i.providerService.Search(ctx, keyword, nil, "update_at") + list, err := i.providerService.Search(ctx, keyword, nil, "update_at desc") if err != nil { return nil, fmt.Errorf("get provider list error:%v", err) } diff --git a/module/service/iml.go b/module/service/iml.go index 636b7515..5da979b2 100644 --- a/module/service/iml.go +++ b/module/service/iml.go @@ -396,15 +396,36 @@ func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *ser } } } - - err := i.serviceModelMappingService.Save(ctx, &service_model_mapping.Save{ - Sid: input.Id, - Content: input.ModelMapping, - }) + err := i.serviceService.Create(ctx, mo) if err != nil { return err } - return i.serviceService.Create(ctx, mo) + if input.ModelMapping != "" { + m := make(map[string]string) + err = json.Unmarshal([]byte(input.ModelMapping), &m) + if err != nil { + return err + } + err = i.serviceModelMappingService.Save(ctx, &service_model_mapping.Save{ + Sid: input.Id, + Content: input.ModelMapping, + }) + if err != nil { + return err + } + client, err := i.clusterService.GatewayClient(ctx, cluster.DefaultClusterID) + if err != nil { + return err + } + err = client.Hash().Online(ctx, &gateway.HashRelease{ + HashKey: fmt.Sprintf("%s:%s", gateway.KeyServiceMapping, input.Id), + HashMap: m, + }) + if err != nil { + return err + } + } + return nil }) if err != nil { return nil, err