feat: add Azure OpenAI support for VLM models
This commit is contained in:
@@ -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{}{
|
||||
|
||||
@@ -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}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user