feat: add Azure OpenAI support for VLM models

This commit is contained in:
liweixin
2026-04-07 19:15:32 +08:00
committed by lyingbug
parent 22ec575727
commit 3cfd034eec
3 changed files with 25 additions and 3 deletions
+2
View File
@@ -447,6 +447,8 @@ func (s *modelService) GetVLMModel(ctx context.Context, modelId string) (vlm.VLM
ModelName: model.Name,
Source: model.Source,
InterfaceType: ifType,
Provider: model.Parameters.Provider,
Extra: stringMapToAnyMap(model.Parameters.ExtraConfig),
}, s.ollamaService)
if err != nil {
logger.ErrorWithFields(ctx, err, map[string]interface{}{
+21 -3
View File
@@ -9,6 +9,7 @@ import (
"time"
"github.com/Tencent/WeKnora/internal/logger"
"github.com/Tencent/WeKnora/internal/models/provider"
openai "github.com/sashabaranov/go-openai"
)
@@ -28,9 +29,26 @@ type RemoteAPIVLM struct {
// NewRemoteAPIVLM creates a remote-API backed VLM instance.
func NewRemoteAPIVLM(config *Config) (*RemoteAPIVLM, error) {
apiCfg := openai.DefaultConfig(config.APIKey)
if config.BaseURL != "" {
apiCfg.BaseURL = config.BaseURL
providerName := provider.ProviderName(config.Provider)
if providerName == "" {
providerName = provider.DetectProvider(config.BaseURL)
}
var apiCfg openai.ClientConfig
if providerName == provider.ProviderAzureOpenAI {
apiCfg = openai.DefaultAzureConfig(config.APIKey, config.BaseURL)
if config.Extra != nil {
if v, ok := config.Extra["api_version"]; ok {
if vs, ok := v.(string); ok && vs != "" {
apiCfg.APIVersion = vs
}
}
}
} else {
apiCfg = openai.DefaultConfig(config.APIKey)
if config.BaseURL != "" {
apiCfg.BaseURL = config.BaseURL
}
}
apiCfg.HTTPClient = &http.Client{Timeout: defaultTimeout}
+2
View File
@@ -26,6 +26,8 @@ type Config struct {
APIKey string
ModelID string
InterfaceType string // "ollama" or "openai" (default)
Provider string
Extra map[string]any
}
// NewVLM creates a VLM instance based on the provided configuration.