Documentation
¶
Overview ¶
Package visionproxy is the vision proxy plugin: when a downstream model is text-only, it describes image content via a vision-capable upstream and replaces the image blocks with the description so the request still works.
Service (service.go) resolves the effective {provider, model} for a request — rule level wins over scenario level — and hands it to VisionProxyProcessor (vision_proxy.go), which rewrites the typed request in place. See .design/vision-proxy.md for the full design and README.md for the rewrite pipeline.
Package visionproxy is the single entry point for the vision proxy plugin, covering both the rule-level and scenario-level scopes. See .design/vision-proxy.md for the full design.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
Processor *VisionProxyProcessor
}
Service wraps the vision proxy processor and resolves the effective vision service ({provider, model}) for a request before applying it in place.
func NewService ¶
func NewService(p *VisionProxyProcessor) *Service
NewService builds a Service around the given processor. A nil processor makes Apply a no-op.
func NewServiceFromPool ¶
func NewServiceFromPool(pool *client.ClientPool, resolver providerResolver) *Service
NewServiceFromPool builds a Service backed by the production vision client, dispatching describe calls through the shared ClientPool. Called once during server boot after the ClientPool and config (provider resolver) are constructed.
func (*Service) Apply ¶
func (s *Service) Apply(ctx context.Context, cfg *config.Config, scenarioType typ.RuleScenario, rule *typ.Rule, typedRequest any)
Apply runs the vision proxy plugin against typedRequest, covering both the rule-level and scenario-level scopes. It must run before service selection (after the rule is resolved). The effective service is chosen by Resolve — rule level wins over scenario level — and the processor runs at most once per request.
func (*Service) Resolve ¶
func (s *Service) Resolve(cfg *config.Config, scenarioType typ.RuleScenario, rule *typ.Rule) *loadbalance.Service
Resolve picks the effective vision service for this request. Rule level wins over scenario level when both are set — the more specific scope is taken to be the user's intent. Returns nil when neither scope configures a usable {provider, model}, in which case the proxy is skipped.
type VisionClient ¶
type VisionClient interface {
Describe(ctx context.Context, service *loadbalance.Service, mediaType, base64Data, remoteURL string) (string, error)
}
VisionClient is the small dependency VisionProxyProcessor needs to describe an image. The real adapter (NewServiceFromPool wiring in service.go) wraps client.ClientPool and dispatches to the appropriate per-service client based on the chosen service's provider APIStyle. Tests substitute a fake.
service is the upstream Process picked from the services it was given. The adapter uses it to resolve which client/provider to call. The fake ignores it and just returns canned text.
Returning ("", nil) means "no description available" → fail-strip path. Returning a non-nil error is also fail-strip.
Describe may be called concurrently — the processor fans out up to describeConcurrency goroutines per request — so implementations must be safe for concurrent use.
func NewPoolVisionClient ¶
func NewPoolVisionClient(pool *client.ClientPool, resolver providerResolver) VisionClient
NewPoolVisionClient builds the production vision client backed by the shared SDK pool. resolver is typically the routing.ProviderResolver implementation (server config). logger may be nil.
type VisionProxyProcessor ¶
type VisionProxyProcessor struct {
Client VisionClient
Resolver providerResolver
}
VisionProxyProcessor rewrites a typed request in place: every image content block becomes a text block, either the vision upstream's description (latest message) or a fixed omitted-marker (history). It is the image-rewriting engine behind Service.Apply — see service.go for the rule/scenario resolution that picks the upstream and invokes Process.
func (*VisionProxyProcessor) Process ¶
func (p *VisionProxyProcessor) Process(ctx context.Context, req any, services []*loadbalance.Service) error
Process mutates req in place: every image block becomes a text block. On any failure (no usable service, vision client error, empty upstream response) the image is still removed so a downstream text-only model does not choke on an unsupported content block. services is the candidate upstream pool — the first active, resolvable service is used; pass a single already-resolved service for the common case.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package visionproxytest provides shared test doubles for the vision proxy plugin, reused both by internal/server/module/visionproxy's own tests and by internal/server tests that need a real Service wired through a visionproxy.VisionProxyProcessor (e.g.
|
Package visionproxytest provides shared test doubles for the vision proxy plugin, reused both by internal/server/module/visionproxy's own tests and by internal/server tests that need a real Service wired through a visionproxy.VisionProxyProcessor (e.g. |