Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat: add Azure OpenAI support for VLM models

liweixin3cfd034eecb0
diff --git a/internal/application/service/model.go b/internal/application/service/model.go
index 750ff301d..da2ac7731 100644
--- a/internal/application/service/model.go
+++ b/internal/application/service/model.go
@@ -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{}{
diff --git a/internal/models/vlm/remote_api.go b/internal/models/vlm/remote_api.go
index 8187a08e9..8452de313 100644
--- a/internal/models/vlm/remote_api.go
+++ b/internal/models/vlm/remote_api.go
@@ -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}
diff --git a/internal/models/vlm/vlm.go b/internal/models/vlm/vlm.go
index c1dc609b2..bdf862868 100644
--- a/internal/models/vlm/vlm.go
+++ b/internal/models/vlm/vlm.go
@@ -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.