feat(models): add max concurrency setting for background tasks

Introduce a new `max_concurrency` parameter to the model configuration, allowing control over the maximum number of concurrent background tasks (ingestion/enrichment) per model. This feature is applicable to chat, embedding, and VLM models, with a value of 0 or undefined falling back to the global default. Update UI components and localization files to support this new setting, ensuring a seamless user experience.
This commit is contained in:
wizardchen
2026-07-09 19:56:43 +08:00
committed by lyingbug
parent 200c344065
commit 20256287ec
17 changed files with 173 additions and 55 deletions
+17 -13
View File
@@ -29,7 +29,10 @@ type Config struct {
ModelID string
InterfaceType string // "ollama" or "openai" (default)
Provider string
Extra map[string]any
// MaxConcurrency caps concurrent background calls to this model; 0 falls
// back to the process-wide default (see limiter.GateN).
MaxConcurrency int
Extra map[string]any
// CustomHeaders 允许在调用远程 API 时附加自定义 HTTP 请求头(类似 OpenAI Python SDK 的 extra_headers)。
CustomHeaders map[string]string
AppID string
@@ -53,17 +56,18 @@ func ConfigFromModel(m *types.Model, appID, appSecret string) *Config {
}
}
return &Config{
ModelID: m.ID,
APIKey: m.Parameters.APIKey,
BaseURL: m.Parameters.BaseURL,
ModelName: m.Name,
Source: m.Source,
InterfaceType: ifType,
Provider: m.Parameters.Provider,
Extra: stringMapToAnyMap(m.Parameters.ExtraConfig),
CustomHeaders: m.Parameters.CustomHeaders,
AppID: appID,
AppSecret: appSecret,
ModelID: m.ID,
APIKey: m.Parameters.APIKey,
BaseURL: m.Parameters.BaseURL,
ModelName: m.Name,
Source: m.Source,
InterfaceType: ifType,
Provider: m.Parameters.Provider,
MaxConcurrency: m.Parameters.MaxConcurrency,
Extra: stringMapToAnyMap(m.Parameters.ExtraConfig),
CustomHeaders: m.Parameters.CustomHeaders,
AppID: appID,
AppSecret: appSecret,
}
}
@@ -90,7 +94,7 @@ func NewVLM(config *Config, ollamaService *ollama.OllamaService) (VLM, error) {
v, err = wrapVLMLangfuse(v, nil)
// Outermost: hold the per-model concurrency slot only around the real
// provider round-trip, so the wait is excluded from debug/langfuse timing.
return wrapVLMConcurrency(v, err)
return wrapVLMConcurrency(v, config.MaxConcurrency, err)
}
func newVLM(config *Config, ollamaService *ollama.OllamaService) (VLM, error) {