Module: LiterLlm::ResponseFormat

Extended by:
T::Helpers, T::Sig
Included in:
ResponseFormatJsonObject, ResponseFormatJsonSchema, ResponseFormatText
Defined in:
lib/liter_llm/native.rb

Overview

Wire format for the chat completions ‘response_format` field.

# Provider mapping

  • OpenAI (and OpenAI-compatible providers): emitted verbatim as ‘“json_schema”, “json_schema”: {…}` per the chat-completions spec.

  • **Gemini / Vertex AI**: translated to ‘generationConfig.responseMimeType = “application/json”` and `generationConfig.responseSchema = <schema>`. The `name`, `description`, and `strict` fields are dropped — Gemini’s structured-output API does not consume them.

  • Anthropic: no native JSON mode. A system instruction is prepended asking the model to respond with valid JSON. ‘strict` is advisory only; callers should still validate the returned JSON if the schema is load-bearing.

Class Method Summary collapse

Class Method Details

.from_hash(hash) ⇒ Object



463
464
465
466
467
468
469
470
471
# File 'lib/liter_llm/native.rb', line 463

def self.from_hash(hash)
  discriminator = hash[:type] || hash["type"]
  case discriminator
  when "text" then ResponseFormatText.from_hash(hash)
  when "json_object" then ResponseFormatJsonObject.from_hash(hash)
  when "json_schema" then ResponseFormatJsonSchema.from_hash(hash)
  else raise "Unknown discriminator: #{discriminator}"
  end
end