diff --git a/controller/ai-local/iml.go b/controller/ai-local/iml.go index e310ecb9..7f20520c 100644 --- a/controller/ai-local/iml.go +++ b/controller/ai-local/iml.go @@ -213,7 +213,7 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model } providerId := "ollama" - prefix := "/" + model + prefix := strings.Replace("/"+model, ":", "_", -1) info, err := i.serviceModule.Create(ctx, teamID, &service_dto.CreateService{ Id: model, Name: model, @@ -229,28 +229,12 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model if err != nil { return err } - path := fmt.Sprintf("/%s/demo_translation_api", strings.Trim(prefix, "/")) + path := fmt.Sprintf("/%s/chat", strings.Trim(prefix, "/")) timeout := 300000 retry := 0 aiPrompt := &ai_api_dto.AiPrompt{ - Variables: []*ai_api_dto.AiPromptVariable{ - { - Key: "source_lang", - Description: "", - Require: true, - }, - { - Key: "target_lang", - Description: "", - Require: true, - }, - { - Key: "text", - Description: "", - Require: true, - }, - }, - Prompt: "You need to translate {{source_lang}} into {{target_lang}}, and the following is the content that needs to be translated.\n---\n{{text}}", + Variables: []*ai_api_dto.AiPromptVariable{}, + Prompt: "", } aiModel := &ai_api_dto.AiModel{ Id: model, @@ -258,8 +242,8 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model Provider: providerId, Type: "local", } - name := "Demo Translation API" - description := "A demo that shows you how to use a prompt to create a Translation API." + name := "Demo AI API" + description := "A demo that shows you how to use a e a Chat API." apiId := uuid.New().String() err = i.aiAPIModule.Create( ctx, @@ -316,7 +300,7 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model } return i.docModule.SaveServiceDoc(ctx, info.Id, &service_dto.SaveServiceDoc{ - Doc: "The Translation API allows developers to translate text from one language to another. It supports multiple languages and enables easy integration of high-quality translation features into applications. With simple API requests, you can quickly translate content into different target languages.", + Doc: "", }) }) diff --git a/controller/service/iml.go b/controller/service/iml.go index d52616af..803d0318 100644 --- a/controller/service/iml.go +++ b/controller/service/iml.go @@ -122,36 +122,20 @@ func (i *imlServiceController) QuickCreateAIService(ctx *gin.Context, input *ser return err } - path := fmt.Sprintf("%s/demo_translation_api", prefix) + path := fmt.Sprintf("%s/chat", prefix) timeout := 300000 retry := 0 aiPrompt := &ai_api_dto.AiPrompt{ - Variables: []*ai_api_dto.AiPromptVariable{ - { - Key: "source_lang", - Description: "", - Require: true, - }, - { - Key: "target_lang", - Description: "", - Require: true, - }, - { - Key: "text", - Description: "", - Require: true, - }, - }, - Prompt: "You need to translate {{source_lang}} into {{target_lang}}, and the following is the content that needs to be translated.\n---\n{{text}}", + Variables: []*ai_api_dto.AiPromptVariable{}, + Prompt: "", } aiModel := &ai_api_dto.AiModel{ Id: m.ID(), Config: m.DefaultConfig(), Provider: input.Provider, } - name := "Demo Translation API" - description := "A demo that shows you how to use a prompt to create a Translation API." + name := "Demo AI API" + description := "A demo that shows you how to use a e a Chat" apiId := uuid.New().String() err = i.aiAPIModule.Create( ctx, @@ -208,7 +192,7 @@ func (i *imlServiceController) QuickCreateAIService(ctx *gin.Context, input *ser } return i.docModule.SaveServiceDoc(ctx, info.Id, &service_dto.SaveServiceDoc{ - Doc: "The Translation API allows developers to translate text from one language to another. It supports multiple languages and enables easy integration of high-quality translation features into applications. With simple API requests, you can quickly translate content into different target languages.", + Doc: "", }) }) } @@ -457,28 +441,13 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string, if err != nil { return err } - path := fmt.Sprintf("/%s/demo_translation_api", strings.Trim(input.Prefix, "/")) + prefix := strings.Replace(input.Prefix, ":", "_", -1) + path := fmt.Sprintf("/%s/chat", strings.Trim(prefix, "/")) timeout := 300000 retry := 0 aiPrompt := &ai_api_dto.AiPrompt{ - Variables: []*ai_api_dto.AiPromptVariable{ - { - Key: "source_lang", - Description: "", - Require: true, - }, - { - Key: "target_lang", - Description: "", - Require: true, - }, - { - Key: "text", - Description: "", - Require: true, - }, - }, - Prompt: "You need to translate {{source_lang}} into {{target_lang}}, and the following is the content that needs to be translated.\n---\n{{text}}", + Variables: []*ai_api_dto.AiPromptVariable{}, + Prompt: "", } aiModel := &ai_api_dto.AiModel{ Id: modelId, @@ -486,8 +455,8 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string, Provider: *input.Provider, Type: modelType, } - name := "Demo Translation API" - description := "A demo that shows you how to use a prompt to create a Translation API." + name := "Demo AI API " + description := "A demo that shows you how to use Chat API." apiId := uuid.New().String() err = i.aiAPIModule.Create( ctx, @@ -545,7 +514,7 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string, } return i.docModule.SaveServiceDoc(ctx, info.Id, &service_dto.SaveServiceDoc{ - Doc: "The Translation API allows developers to translate text from one language to another. It supports multiple languages and enables easy integration of high-quality translation features into applications. With simple API requests, you can quickly translate content into different target languages.", + Doc: "", }) }) diff --git a/module/ai-api/iml.go b/module/ai-api/iml.go index 548a88df..58b9d884 100644 --- a/module/ai-api/iml.go +++ b/module/ai-api/iml.go @@ -54,7 +54,7 @@ func (i *imlAPIModule) getAPIDoc(ctx context.Context, serviceId string) (*openap return openapi3Loader.LoadFromData([]byte(doc.Content)) } -func (i *imlAPIModule) updateAPIDoc(ctx context.Context, serviceId string, serviceName string, path string, summary string, description string, aiPrompt *ai_api_dto.AiPrompt) error { +func (i *imlAPIModule) updateAPIDoc(ctx context.Context, serviceId, serviceName, orgPath, path, summary, description string, aiPrompt *ai_api_dto.AiPrompt) error { doc, err := i.getAPIDoc(ctx, serviceId) if err != nil { return err @@ -64,6 +64,10 @@ func (i *imlAPIModule) updateAPIDoc(ctx context.Context, serviceId string, servi if aiPrompt != nil { variables = aiPrompt.Variables } + if doc.Paths != nil { + doc.Paths.Delete(orgPath) + } + doc.AddOperation(path, http.MethodPost, genOperation(summary, description, variables)) result, err := doc.MarshalJSON() if err != nil { @@ -103,7 +107,7 @@ func (i *imlAPIModule) Create(ctx context.Context, serviceId string, input *ai_a input.Id = uuid.New().String() } return i.transaction.Transaction(ctx, func(txCtx context.Context) error { - err = i.updateAPIDoc(ctx, serviceId, info.Name, input.Path, input.Name, input.Description, input.AiPrompt) + err = i.updateAPIDoc(ctx, serviceId, info.Name, "", input.Path, input.Name, input.Description, input.AiPrompt) if err != nil { return err } @@ -143,13 +147,14 @@ func (i *imlAPIModule) Edit(ctx context.Context, serviceId string, apiId string, if err != nil { return err } + orgPath := apiInfo.Path if input.Path != nil { apiInfo.Path = *input.Path } if input.Description != nil { apiInfo.Description = *input.Description } - err = i.updateAPIDoc(ctx, serviceId, info.Name, apiInfo.Path, apiInfo.Name, apiInfo.Description, input.AiPrompt) + err = i.updateAPIDoc(ctx, serviceId, info.Name, orgPath, apiInfo.Path, apiInfo.Name, apiInfo.Description, input.AiPrompt) if err != nil { return err } diff --git a/module/ai-api/schema.go b/module/ai-api/schema.go index aaa26bee..71dbefab 100644 --- a/module/ai-api/schema.go +++ b/module/ai-api/schema.go @@ -21,7 +21,6 @@ func genOpenAPI3Template(title string, description string) *openapi3.T { func genOperation(summary string, description string, variables []*ai_api_dto.AiPromptVariable) *openapi3.Operation { operation := openapi3.NewOperation() - //operation.Parameters = genRequestParameters(variables) operation.Summary = summary operation.Description = description operation.RequestBody = genRequestBody(variables) diff --git a/module/service/iml.go b/module/service/iml.go index 25a51694..bbab2cf3 100644 --- a/module/service/iml.go +++ b/module/service/iml.go @@ -297,6 +297,13 @@ func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *ser if input.Id == "" { input.Id = uuid.New().String() } + if teamID == "" { + item, err := i.teamService.DefaultTeam(ctx) + if err != nil { + return nil, err + } + teamID = item.Id + } mo := &service.Create{ Id: input.Id, Name: input.Name, diff --git a/service/team/iml.go b/service/team/iml.go index 0f469fc6..cba876c6 100644 --- a/service/team/iml.go +++ b/service/team/iml.go @@ -24,6 +24,15 @@ type imlTeamService struct { universally.IServiceEdit[EditTeam] } +func (s *imlTeamService) DefaultTeam(ctx context.Context) (*Team, error) { + item, err := s.teamStore.First(ctx, nil, "id asc") + if err != nil { + return nil, err + + } + return FromEntity(item), nil +} + func (s *imlTeamService) OnComplete() { s.IServiceGet = universally.NewGetSoftDelete[Team, team.Team](s.teamStore, FromEntity) diff --git a/service/team/service.go b/service/team/service.go index 1408733e..e5278d94 100644 --- a/service/team/service.go +++ b/service/team/service.go @@ -1,8 +1,9 @@ package team import ( + "context" "reflect" - + "github.com/APIParkLab/APIPark/service/universally" "github.com/eolinker/go-common/autowire" ) @@ -12,6 +13,7 @@ type ITeamService interface { universally.IServiceDelete universally.IServiceCreate[CreateTeam] universally.IServiceEdit[EditTeam] + DefaultTeam(ctx context.Context) (*Team, error) } func init() { diff --git a/stores/ai/model.go b/stores/ai/model.go index 6b909b04..a532704a 100644 --- a/stores/ai/model.go +++ b/stores/ai/model.go @@ -72,9 +72,9 @@ func (i *Key) IdValue() int64 { type Balance struct { Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"` Uuid string `gorm:"type:varchar(36);not null;column:uuid;uniqueIndex:uuid;comment:UUID;"` - Provider string `gorm:"type:varchar(100);not null;column:provider;comment:供应商ID"` + Provider string `gorm:"type:varchar(100);not null;column:provider;comment:供应商ID;uniqueIndex:provider_model" aovalue:"provider` ProviderName string `gorm:"type:varchar(100);not null;column:provider_name;comment:供应商名称"` - Model string `gorm:"type:varchar(100);not null;column:model;comment:模型ID"` + Model string `gorm:"type:varchar(100);not null;column:model;comment:模型ID;uniqueIndex:provider_model"` ModelName string `gorm:"type:varchar(100);not null;column:model_name;comment:模型名称"` Type int `gorm:"type:tinyint(1);not null;column:type;comment:类型,0:online,1:local"` State int `gorm:"type:tinyint(1);not null;column:state;comment:状态,0:异常,1:正常;default:1"`