RequestTransformer

org.llm4s.model.RequestTransformer
See theRequestTransformer companion object
@Stable

Handles model-specific parameter validation and transformation.

Uses ModelCapabilities from ModelRegistryService to apply constraints based on what each model supports, as LiteLLM does. Rules a vendor knows but the registry does not record live in that vendor's provider module, layered on with RequestTransformer.adjusted.

Example usage:

 val transformer = RequestTransformer.default(registryService)
 val result = transformer.transformOptions("gpt-4o", options, dropUnsupported = true)
 result match {
   case Right(transformed) => // use transformed options
   case Left(error) => // handle validation error
 }

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def disallowedParams(modelId: String): Set[String]

Get the set of parameters that are not supported by this model.

Get the set of parameters that are not supported by this model.

Value parameters

modelId

The model identifier

Attributes

Returns

Set of disallowed parameter names, empty if all are allowed

def requiresFakeStreaming(modelId: String): Boolean

Check if streaming needs to be faked for this model.

Check if streaming needs to be faked for this model.

A model whose capabilities say it does not support native streaming requires the client to simulate streaming by returning the full response as a single chunk.

Value parameters

modelId

The model identifier

Attributes

Returns

true if the model requires fake streaming

def transformMessages(modelId: String, messages: Seq[Message]): Seq[Message]

Transform messages for model-specific requirements.

Transform messages for model-specific requirements.

For example, a model whose capabilities say it does not support system messages will have its system messages converted to user messages with a "[System]:" prefix.

Value parameters

messages

The messages to transform

modelId

The model identifier

Attributes

Returns

Transformed messages

def transformOptions(modelId: String, options: CompletionOptions, dropUnsupported: Boolean): Result[CompletionOptions]

Validate and transform completion options for a specific model.

Validate and transform completion options for a specific model.

Checks model capabilities and either drops unsupported parameters or returns validation errors, depending on the dropUnsupported flag.

Value parameters

dropUnsupported

If true, silently drop/adjust unsupported params; if false, return error

modelId

The model identifier (e.g., "o1", "gpt-4o", "claude-3-7-sonnet")

options

The completion options to transform

Attributes

Returns

Transformed options or validation error