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,
|
ModelName: model.Name,
|
||||||
Source: model.Source,
|
Source: model.Source,
|
||||||
InterfaceType: ifType,
|
InterfaceType: ifType,
|
||||||
|
Provider: model.Parameters.Provider,
|
||||||
|
Extra: stringMapToAnyMap(model.Parameters.ExtraConfig),
|
||||||
}, s.ollamaService)
|
}, s.ollamaService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{
|
logger.ErrorWithFields(ctx, err, map[string]interface{}{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Tencent/WeKnora/internal/logger"
|
"github.com/Tencent/WeKnora/internal/logger"
|
||||||
|
"github.com/Tencent/WeKnora/internal/models/provider"
|
||||||
openai "github.com/sashabaranov/go-openai"
|
openai "github.com/sashabaranov/go-openai"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,9 +29,26 @@ type RemoteAPIVLM struct {
|
|||||||
|
|
||||||
// NewRemoteAPIVLM creates a remote-API backed VLM instance.
|
// NewRemoteAPIVLM creates a remote-API backed VLM instance.
|
||||||
func NewRemoteAPIVLM(config *Config) (*RemoteAPIVLM, error) {
|
func NewRemoteAPIVLM(config *Config) (*RemoteAPIVLM, error) {
|
||||||
apiCfg := openai.DefaultConfig(config.APIKey)
|
providerName := provider.ProviderName(config.Provider)
|
||||||
if config.BaseURL != "" {
|
if providerName == "" {
|
||||||
apiCfg.BaseURL = config.BaseURL
|
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}
|
apiCfg.HTTPClient = &http.Client{Timeout: defaultTimeout}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ type Config struct {
|
|||||||
APIKey string
|
APIKey string
|
||||||
ModelID string
|
ModelID string
|
||||||
InterfaceType string // "ollama" or "openai" (default)
|
InterfaceType string // "ollama" or "openai" (default)
|
||||||
|
Provider string
|
||||||
|
Extra map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVLM creates a VLM instance based on the provided configuration.
|
// NewVLM creates a VLM instance based on the provided configuration.
|
||||||
|
|||||||
Reference in New Issue
Block a user