Skip to content

API Reference parrot_pipelines.planogram.identification.vision

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_pipelines.planogram.identification.vision

View source

Provider-neutral vision adapter — the only caller of ask_to_image in the new planogram cycle.

Attribute KNOWN_KWARGS

Type: FrozenSet[str]

Alias ResolvedBackend

Re-exported from parrot_pipelines.planogram.backend.ResolvedBackend.

Attribute SUPPORTED_KWARGS

Type: Dict[str, FrozenSet[str]]

Attribute T

Class VisionAdapter

Prompt + images + Pydantic schema → validated instance, on any client exposing ask_to_image.

Parameter Type Default Description
client Any An LLM client exposing ask_to_image.
backend ResolvedBackend The resolved backend (the model kwarg is sent only when pinned).
semaphore asyncio.Semaphore Bounds concurrent provider calls (shared per pipeline run).
cache_dir Optional[Path] None Response cache directory; None disables the cache.
max_tokens int 8192 Output budget of every call.
timeout float 120.0 Per-call timeout in seconds.
repair_retries int 1 Repair prompts after an invalid answer (0 disables).
truncation_retries int 1 Identical re-sends after an answer cut at the output-token limit (0 disables). A truncated answer is a runaway generation far more often than a real lack of budget.

Method VisionAdapter.ask

Ask one structured question about images.

images[0] is the main image, the rest go as reference_images.

ask(prompt: str, images: Sequence[bytes], schema: Type[T], *, stage: str, prompt_version: str, system_prompt: Optional[str] = None) -> T

Parameter Type Default Description
prompt str The prompt.
images Sequence[bytes] Encoded images (at least one).
schema Type[T] Pydantic schema the answer must validate into.
stage str Stage name (cache key + logs).
prompt_version str Prompt template version (cache key).
system_prompt Optional[str] None Optional system prompt (native or folded into the prompt).

Returns: T — A validated schema instance.

Raises:

  • ValueError — images is empty.
  • VisionError — provider failure, timeout, or an answer still invalid after the repair retries.

Class VisionError

Vision call failed, timed out, or stayed invalid after the repair retry.

Class VisionTruncatedError

The provider cut the answer at the output-token limit.

Function cache_key

sha256 over a canonical JSON of all arguments incl. schema.model_json_schema() and image digests.

cache_key(backend: str, max_tokens: int, stage: str, prompt_version: str, prompt: str, schema: Type[BaseModel], images: Sequence[bytes]) -> str

Parameter Type Default Description
backend str ResolvedBackend.as_string().
max_tokens int Output budget.
stage str Pipeline stage name.
prompt_version str Prompt template version.
prompt str The final prompt text.
schema Type[BaseModel] Structured-output schema.
images Sequence[bytes] Encoded images (main first).

Returns: str — The hex digest.

Function encode_png

PNG-encode a BGR array. Module-level and picklable — run it through the CPU executor, never inline.

encode_png(image: np.ndarray) -> bytes

Parameter Type Default Description
image np.ndarray BGR (or gray) uint8 array.

Returns: bytes — PNG bytes.

Raises:

  • ValueError — OpenCV could not encode the array.

Attribute logger

Function normalise_kwargs

Keep the kwargs client_name supports (unknown provider ⇒ common subset); drop None values.

normalise_kwargs(client_name: str, requested: Dict[str, Any]) -> Dict[str, Any]

Parameter Type Default Description
client_name str The client's client_name (lower-cased by the caller).
requested Dict[str, Any] Requested keyword arguments.

Returns: Dict[str, Any] — The kwargs the provider accepts, without None values.

Raises:

  • VisionError — a key outside KNOWN_KWARGS — unknown kwargs are never dropped silently.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally