mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-12 18:11:34 +08:00
Fix the issue of duplicate custom suppliers and built-in suppliers
This commit is contained in:
@@ -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{
|
||||
{
|
||||
|
||||
@@ -17,5 +17,4 @@ type Sort struct {
|
||||
|
||||
type NewProvider struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
+4
-7
@@ -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)
|
||||
}
|
||||
|
||||
+27
-6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user