Module: OpenApiOpenAIClient::CreateChatCompletionRequestResponseFormat

Defined in:
lib/openapi_openai/models/create_chat_completion_request_response_format.rb

Overview

An object specifying the format that the model must output. Setting to ‘{ "type": "json_schema", "json_schema": … }` enables Structured Outputs which ensures the model will match your supplied JSON schema. Learn more in the [Structured Outputs guide](/docs/guides/structured-outputs). Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model generates is valid JSON. Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded max_tokens or the conversation exceeded the max context length.

Class Method Summary collapse

Class Method Details

.build(data) ⇒ Object

Builds the object

Parameters:

  • Data (Mixed)

    to be matched against the list of oneOf items

Returns:

  • (Object)

    Returns the model or the data itself



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/openapi_openai/models/create_chat_completion_request_response_format.rb', line 32

def build(data)
  # Go through the list of oneOf items and attempt to identify the appropriate one.
  # Note:
  # - We do not attempt to check whether exactly one item matches.
  # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
  #   due to the way the deserialization is made in the base_object template (it just casts without verifying).
  # - TODO: scalar values are de facto behaving as if they were nullable.
  # - TODO: logging when debugging is set.
  openapi_one_of.each do |klass|
    begin
      next if klass == :AnyType # "nullable: true"
      return find_and_cast_into_type(klass, data)
    rescue # rescue all errors so we keep iterating even if the current item lookup raises
    end
  end

  openapi_one_of.include?(:AnyType) ? data : nil
end

.openapi_one_ofObject

List of class defined in oneOf (OpenAPI v3)



21
22
23
24
25
26
27
# File 'lib/openapi_openai/models/create_chat_completion_request_response_format.rb', line 21

def openapi_one_of
  [
    :'ResponseFormatJsonObject',
    :'ResponseFormatJsonSchema',
    :'ResponseFormatText'
  ]
end