feat(model): 双协议 LLM Provider(AnthropicChNativeAdapter /v1/messages + tool_use.input→Args 直接映射 + 流式重组)+ Provider 感知工厂/路由 + LLM_PROVIDER/anthropic 配置(OpenAI 兼容保留)
This commit is contained in:
1 parent
f9650185f1
commit
3632e04733
11 files changed
+1452
-18
No files matched your search
@@ -2,11 +2,16 @@ package model
|
||||
|
||||
// Router maps roles to model names. An unknown role resolves to the configured
|
||||
// default model. When a request carries image content and a vision model is
|
||||
// configured, the request routes to the vision model.
|
||||
// configured, the request routes to the vision model. A Router also carries a
|
||||
// provider per role (defaulting to the global provider) so a multi-vendor
|
||||
// deployment can pair a role's model with the correct protocol; the provider
|
||||
// selection is surfaced via RouteProvider.
|
||||
type Router struct {
|
||||
defaultModel string
|
||||
byRole map[Role]string
|
||||
visionModel string
|
||||
defaultModel string
|
||||
byRole map[Role]string
|
||||
visionModel string
|
||||
defaultProvider string
|
||||
providerByRole map[Role]string
|
||||
}
|
||||
|
||||
// RouterOption configures a Router.
|
||||
@@ -22,10 +27,28 @@ func WithVisionModel(model string) RouterOption {
|
||||
return func(r *Router) { r.visionModel = model }
|
||||
}
|
||||
|
||||
// WithDefaultProvider sets the provider returned by RouteProvider for roles with
|
||||
// no explicit binding. It defaults to openai.
|
||||
func WithDefaultProvider(provider string) RouterOption {
|
||||
return func(r *Router) { r.defaultProvider = provider }
|
||||
}
|
||||
|
||||
// WithRoleProvider binds a provider to a role, so a multi-vendor deployment can
|
||||
// route a role to a different vendor's protocol (e.g. one role on anthropic, one
|
||||
// on openai). Pair it with WithRoleModel for the role's model name.
|
||||
func WithRoleProvider(role Role, provider string) RouterOption {
|
||||
return func(r *Router) { r.providerByRole[role] = provider }
|
||||
}
|
||||
|
||||
// NewRouter builds a Router with a default model applied to any role that has
|
||||
// no explicit binding.
|
||||
func NewRouter(defaultModel string, opts ...RouterOption) *Router {
|
||||
r := &Router{defaultModel: defaultModel, byRole: map[Role]string{}}
|
||||
r := &Router{
|
||||
defaultModel: defaultModel,
|
||||
byRole: map[Role]string{},
|
||||
defaultProvider: ProviderOpenAI,
|
||||
providerByRole: map[Role]string{},
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(r)
|
||||
}
|
||||
@@ -40,6 +63,18 @@ func (r *Router) Route(role Role) string {
|
||||
return r.defaultModel
|
||||
}
|
||||
|
||||
// RouteProvider returns the provider for a role, falling back to the router's
|
||||
// default provider. It is the routing hook for a multi-vendor deployment: each
|
||||
// role can carry its own provider+model pairing, and roles without a binding fall
|
||||
// back to the global provider. The runtime/loop is expected to build a per-role
|
||||
// adapter or chain from this decision (the provider-aware factory is the builder).
|
||||
func (r *Router) RouteProvider(role Role) string {
|
||||
if p, ok := r.providerByRole[role]; ok && p != "" {
|
||||
return p
|
||||
}
|
||||
return r.defaultProvider
|
||||
}
|
||||
|
||||
// RouteRequest picks the model for a request and reports whether the request
|
||||
// needs a vision model. When the request carries image content and a vision
|
||||
// model is configured, the vision model is returned with needsVision set to
|
||||
|
||||
Reference in new issue
Block a user