LLMVisionClient

org.llm4s.imageprocessing.LLMVisionClient

An ImageProcessingClient over any vision-capable LLMClient (#3155): the image goes to the model as a ContentPart.Image beside the prompt, through the provider's own client, so the call honours its config, credentials, retries and tracing, and the result carries the provider's token usage.

The image's media type is read from its bytes; BMP and TIFF, which no vendor takes, are converted to PNG, and WebP is sent as it is. An image part is at most ContentPart.MaxInlineBytes (5 MiB): a larger file is refused before any call, so resize it first with preprocessImage or resizeImage.

A reply cut at the output limit (FinishReason.Length) is a ProcessingError: raise maxTokens in options. A reply with no text is a ServiceError (status 200). A filtered reply is the client's ContentFilteredError.

preprocessImage, convertFormat and resizeImage run locally, with no call.

Value parameters

llm

the client the image is sent through; its model must accept image input

local

the processor that reads, converts and transforms the image

options

the options of every call, for example CompletionOptions().withMaxTokens(4096)

Attributes

Source
LLMVisionClient.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def analyzeImage(imagePath: String, prompt: Option[String]): Result[ImageAnalysisResult]

Analyzes an image and returns a description.

Analyzes an image and returns a description.

Value parameters

imagePath

Path to the image file

prompt

Optional prompt to guide the analysis

Attributes

Returns

Either error or image analysis result

Definition Classes
Source
LLMVisionClient.scala
override def convertFormat(imagePath: String, targetFormat: ImageMediaType): Result[ProcessedImage]

Converts image format.

Converts image format.

Value parameters

imagePath

Path to the input image

targetFormat

Target image format

Attributes

Returns

Either error or converted image

Definition Classes
Source
LLMVisionClient.scala

The names of a fixed list of objects (person, car, dog, cat, building, tree, table, chair) that the model's reply mentions as whole words. Their confidence and bounding box are None: the reply is not parsed for them.

The names of a fixed list of objects (person, car, dog, cat, building, tree, table, chair) that the model's reply mentions as whole words. Their confidence and bounding box are None: the reply is not parsed for them.

Attributes

Source
LLMVisionClient.scala

Transcribes the text visible in the image: the model's reply itself, also in the result's text.

Transcribes the text visible in the image: the model's reply itself, also in the result's text.

Value parameters

imagePath

the image file

Attributes

Returns

the analysis, whose description and text are the transcription

Source
LLMVisionClient.scala
def generateTags(imagePath: String): Result[List[String]]

The words of a fixed tag list that the model's reply to a tagging prompt contains as whole words.

The words of a fixed tag list that the model's reply to a tagging prompt contains as whole words.

Attributes

Source
LLMVisionClient.scala
override def preprocessImage(imagePath: String, operations: List[ImageOperation]): Result[ProcessedImage]

Preprocesses an image with specified operations.

Preprocesses an image with specified operations.

Value parameters

imagePath

Path to the input image

operations

List of preprocessing operations to apply

Attributes

Returns

Either error or processed image

Definition Classes
Source
LLMVisionClient.scala
override def resizeImage(imagePath: String, width: Int, height: Int, maintainAspectRatio: Boolean): Result[ProcessedImage]

Resizes an image to specified dimensions.

Resizes an image to specified dimensions.

Value parameters

height

Target height

imagePath

Path to the input image

maintainAspectRatio

Whether to maintain aspect ratio

width

Target width

Attributes

Returns

Either error or resized image

Definition Classes
Source
LLMVisionClient.scala

Inherited methods

Asynchronously analyzes an image and returns a description.

Asynchronously analyzes an image and returns a description.

Default implementation wraps the synchronous call in a Future with an explicit blocking boundary to avoid starving compute pools.

Value parameters

ec

ExecutionContext for async execution

imagePath

Path to the image file

prompt

Optional prompt to guide the analysis

Attributes

Returns

Future containing either error or image analysis result

Inherited from:
ImageProcessingClient
Source
ImageProcessing.scala