implement generic provider for vendor-agnostic passthrough (#3175)

This commit is contained in:
woody
2025-12-03 09:52:47 +08:00
committed by jingze
parent 48433a6549
commit 2b49fd5b26
6 changed files with 360 additions and 0 deletions

View File

@@ -144,6 +144,7 @@ const (
providerTypeLongcat = "longcat"
providerTypeFireworks = "fireworks"
providerTypeVllm = "vllm"
providerTypeGeneric = "generic"
protocolOpenAI = "openai"
protocolOriginal = "original"
@@ -227,6 +228,7 @@ var (
providerTypeLongcat: &longcatProviderInitializer{},
providerTypeFireworks: &fireworksProviderInitializer{},
providerTypeVllm: &vllmProviderInitializer{},
providerTypeGeneric: &genericProviderInitializer{},
}
)
@@ -409,6 +411,9 @@ type ProviderConfig struct {
basePath string `required:"false" yaml:"basePath" json:"basePath"`
// @Title zh-CN basePathHandling用于指定basePath的处理方式可选值removePrefix、prepend
basePathHandling basePathHandling `required:"false" yaml:"basePathHandling" json:"basePathHandling"`
// @Title zh-CN generic Provider 对应的Host
// @Description zh-CN 仅适用于generic provider用于覆盖请求转发的目标Host
genericHost string `required:"false" yaml:"genericHost" json:"genericHost"`
// @Title zh-CN 首包超时
// @Description zh-CN 流式请求中收到上游服务第一个响应包的超时时间,单位为毫秒。默认值为 0表示不开启首包超时
firstByteTimeout uint32 `required:"false" yaml:"firstByteTimeout" json:"firstByteTimeout"`
@@ -619,6 +624,7 @@ func (c *ProviderConfig) FromJson(json gjson.Result) {
if c.basePath != "" && c.basePathHandling == "" {
c.basePathHandling = basePathHandlingRemovePrefix
}
c.genericHost = json.Get("genericHost").String()
c.vllmServerHost = json.Get("vllmServerHost").String()
c.vllmCustomUrl = json.Get("vllmCustomUrl").String()
}