RequestTransformer

org.llm4s.model.RequestTransformer
See theRequestTransformer companion object

Handles model-specific parameter validation and transformation.

Uses ModelCapabilities from ModelRegistry to apply constraints based on what each model supports. This mirrors LiteLLM's approach to handling model-specific quirks (e.g., O-series temperature restrictions).

Example usage:

 val transformer = RequestTransformer.default
 val result = transformer.transformOptions("o1", 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
Known subtypes

Members list

Value members

Abstract methods

def getDisallowedParams(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.

Some models (like O1) don't support native streaming and require 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, O-series models that don't support system messages will have their 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