Skip to content

Commit

Permalink
fix: Fix a bug in openaiCustomUrl support (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
CH3CHO authored Feb 22, 2025
1 parent fabc22f commit 2328e19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions plugins/wasm-go/extensions/ai-proxy/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ func (c *PluginConfig) Complete(log wrapper.Log) error {
c.activeProvider = nil
return nil
}

var err error

c.activeProvider, err = provider.CreateProvider(*c.activeProviderConfig)
if err != nil {
return err
}

providerConfig := c.GetProviderConfig()
err = providerConfig.SetApiTokensFailover(log, c.activeProvider)

return err
return providerConfig.SetApiTokensFailover(log, c.activeProvider)
}

func (c *PluginConfig) GetProvider() provider.Provider {
Expand Down
4 changes: 4 additions & 0 deletions plugins/wasm-go/extensions/ai-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ func parseGlobalConfig(json gjson.Result, pluginConfig *config.PluginConfig, log

pluginConfig.FromJson(json)
if err := pluginConfig.Validate(); err != nil {
log.Errorf("global rule config is invalid: %v", err)
return err
}
if err := pluginConfig.Complete(log); err != nil {
log.Errorf("failed to apply global rule config: %v", err)
return err
}

Expand All @@ -56,9 +58,11 @@ func parseOverrideRuleConfig(json gjson.Result, global config.PluginConfig, plug

pluginConfig.FromJson(json)
if err := pluginConfig.Validate(); err != nil {
log.Errorf("overriden rule config is invalid: %v", err)
return err
}
if err := pluginConfig.Complete(log); err != nil {
log.Errorf("failed to apply overriden rule config: %v", err)
return err
}

Expand Down
7 changes: 3 additions & 4 deletions plugins/wasm-go/extensions/ai-proxy/provider/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package provider

import (
"encoding/json"
"fmt"
"net/http"
"path"
"strings"
Expand Down Expand Up @@ -58,10 +57,10 @@ func (m *openaiProviderInitializer) CreateProvider(config ProviderConfig) (Provi
}
customUrl := strings.TrimPrefix(strings.TrimPrefix(config.openaiCustomUrl, "http://"), "https://")
pairs := strings.SplitN(customUrl, "/", 2)
if len(pairs) != 2 {
return nil, fmt.Errorf("invalid openaiCustomUrl:%s", config.openaiCustomUrl)
customPath := "/"
if len(pairs) == 2 {
customPath += pairs[1]
}
customPath := "/" + pairs[1]
isDirectCustomPath := isDirectPath(customPath)
capabilities := m.DefaultCapabilities()
if !isDirectCustomPath {
Expand Down

0 comments on commit 2328e19

Please sign in to comment.