From bc85e59352d2969e1caf567e8dcaeb0ad18f7ce8 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Fri, 14 Mar 2025 15:51:33 +0800 Subject: [PATCH] fix bug --- .../model-providers/bailian/bailian.yaml | 2 +- controller/system/iml.go | 42 +++++++++---------- module/ai-balance/iml.go | 10 ++++- module/ai-local/iml.go | 3 +- module/service/iml.go | 2 +- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/ai-provider/model-runtime/model-providers/bailian/bailian.yaml b/ai-provider/model-runtime/model-providers/bailian/bailian.yaml index 9b213760..93bd6a02 100644 --- a/ai-provider/model-runtime/model-providers/bailian/bailian.yaml +++ b/ai-provider/model-runtime/model-providers/bailian/bailian.yaml @@ -1,7 +1,7 @@ provider: bailian label: zh_Hans: 阿里云百炼 - en_US: bailian + en_US: BaiLian icon_small: en_US: icon_s_en.svg icon_large: diff --git a/controller/system/iml.go b/controller/system/iml.go index 44f9e37e..749e73b0 100644 --- a/controller/system/iml.go +++ b/controller/system/iml.go @@ -395,36 +395,36 @@ func (i *imlInitController) createAIService(ctx context.Context, teamID string, if err != nil { 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 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{ + // { + // 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}}", } aiModel := &ai_api_dto.AiModel{ Id: m.ID(), Config: m.DefaultConfig(), Provider: providerId, } - name := "Demo Translation API" - description := "A demo that shows you how to use a prompt to create a Translation API." + name := "Demo Chat API" + description := "A demo that shows you how to use a prompt to create a Chat API." apiId := uuid.New().String() err = i.aiAPIModule.Create( ctx, diff --git a/module/ai-balance/iml.go b/module/ai-balance/iml.go index 81d0c655..aab4c9a0 100644 --- a/module/ai-balance/iml.go +++ b/module/ai-balance/iml.go @@ -268,7 +268,8 @@ func (i *imlBalanceModule) getLocalBalances(ctx context.Context, v string) ([]*g var has bool v, has = i.settingService.Get(ctx, "system.ai_model.ollama_address") 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") 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)) for _, item := range balances { @@ -305,6 +307,10 @@ func (i *imlBalanceModule) getBalances(ctx context.Context) ([]*gateway.DynamicR continue } 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)) } diff --git a/module/ai-local/iml.go b/module/ai-local/iml.go index 3547c84b..c61d3977 100644 --- a/module/ai-local/iml.go +++ b/module/ai-local/iml.go @@ -614,7 +614,8 @@ func (i *imlLocalModel) getLocalModels(ctx context.Context, v string) ([]*gatewa var has bool v, has = i.settingService.Get(ctx, "system.ai_model.ollama_address") 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 diff --git a/module/service/iml.go b/module/service/iml.go index 841e2a09..636b7515 100644 --- a/module/service/iml.go +++ b/module/service/iml.go @@ -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) err = json.Unmarshal([]byte(*input.ModelMapping), &m) if err != nil {