This commit is contained in:
Liujian
2025-03-14 15:51:33 +08:00
parent 33c61f6131
commit bc85e59352
5 changed files with 33 additions and 26 deletions
@@ -1,7 +1,7 @@
provider: bailian provider: bailian
label: label:
zh_Hans: 阿里云百炼 zh_Hans: 阿里云百炼
en_US: bailian en_US: BaiLian
icon_small: icon_small:
en_US: icon_s_en.svg en_US: icon_s_en.svg
icon_large: icon_large:
+21 -21
View File
@@ -395,36 +395,36 @@ func (i *imlInitController) createAIService(ctx context.Context, teamID string,
if err != nil { if err != nil {
return err return err
} }
path := fmt.Sprintf("/%s/demo_translation_api", strings.Trim(input.Prefix, "/")) path := fmt.Sprintf("/%s/chat/completions", strings.Trim(input.Prefix, "/"))
timeout := 300000 timeout := 300000
retry := 0 retry := 0
aiPrompt := &ai_api_dto.AiPrompt{ aiPrompt := &ai_api_dto.AiPrompt{
Variables: []*ai_api_dto.AiPromptVariable{ //Variables: []*ai_api_dto.AiPromptVariable{
{ // {
Key: "source_lang", // Key: "source_lang",
Description: "", // Description: "",
Require: true, // Require: true,
}, // },
{ // {
Key: "target_lang", // Key: "target_lang",
Description: "", // Description: "",
Require: true, // Require: true,
}, // },
{ // {
Key: "text", // Key: "text",
Description: "", // Description: "",
Require: true, // 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}}", //Prompt: "You need to translate {{source_lang}} into {{target_lang}}, and the following is the content that needs to be translated.\n---\n{{text}}",
} }
aiModel := &ai_api_dto.AiModel{ aiModel := &ai_api_dto.AiModel{
Id: m.ID(), Id: m.ID(),
Config: m.DefaultConfig(), Config: m.DefaultConfig(),
Provider: providerId, Provider: providerId,
} }
name := "Demo Translation API" name := "Demo Chat API"
description := "A demo that shows you how to use a prompt to create a Translation API." description := "A demo that shows you how to use a prompt to create a Chat API."
apiId := uuid.New().String() apiId := uuid.New().String()
err = i.aiAPIModule.Create( err = i.aiAPIModule.Create(
ctx, ctx,
+8 -2
View File
@@ -268,7 +268,8 @@ func (i *imlBalanceModule) getLocalBalances(ctx context.Context, v string) ([]*g
var has bool var has bool
v, has = i.settingService.Get(ctx, "system.ai_model.ollama_address") v, has = i.settingService.Get(ctx, "system.ai_model.ollama_address")
if !has { if !has {
return nil, fmt.Errorf("ollama address not found") //return nil, fmt.Errorf("ollama address not found")
return nil, nil
} }
} }
@@ -294,7 +295,8 @@ func (i *imlBalanceModule) getBalances(ctx context.Context) ([]*gateway.DynamicR
} }
v, has := i.settingService.Get(ctx, "system.ai_model.ollama_address") v, has := i.settingService.Get(ctx, "system.ai_model.ollama_address")
if !has { if !has {
return nil, fmt.Errorf("ollama address not found") //return nil, fmt.Errorf("ollama address not found")
return nil, nil
} }
releases := make([]*gateway.DynamicRelease, 0, len(balances)) releases := make([]*gateway.DynamicRelease, 0, len(balances))
for _, item := range balances { for _, item := range balances {
@@ -305,6 +307,10 @@ func (i *imlBalanceModule) getBalances(ctx context.Context) ([]*gateway.DynamicR
continue continue
} }
base = fmt.Sprintf("%s://%s%s", p.URI().Scheme(), p.URI().Host(), p.URI().Path()) base = fmt.Sprintf("%s://%s%s", p.URI().Scheme(), p.URI().Host(), p.URI().Path())
} else {
if v == "" {
continue
}
} }
releases = append(releases, newRelease(item, base)) releases = append(releases, newRelease(item, base))
} }
+2 -1
View File
@@ -614,7 +614,8 @@ func (i *imlLocalModel) getLocalModels(ctx context.Context, v string) ([]*gatewa
var has bool var has bool
v, has = i.settingService.Get(ctx, "system.ai_model.ollama_address") v, has = i.settingService.Get(ctx, "system.ai_model.ollama_address")
if !has { if !has {
return nil, errors.New("ollama_address not set") //return nil, errors.New("ollama_address not set")
return nil, nil
} }
} }
provider := ai_provider_local.ProviderLocal provider := ai_provider_local.ProviderLocal
+1 -1
View File
@@ -473,7 +473,7 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d
} }
} }
if input.ModelMapping != nil { if input.ModelMapping != nil && *input.ModelMapping != "" {
m := make(map[string]string) m := make(map[string]string)
err = json.Unmarshal([]byte(*input.ModelMapping), &m) err = json.Unmarshal([]byte(*input.ModelMapping), &m)
if err != nil { if err != nil {