Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.13.0"
".": "0.13.1"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 109
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-2d116cda53321baa3479e628512def723207a81eb1cdaebb542bd0555e563bda.yml
openapi_spec_hash: 809d958fec261a32004a4b026b718793
config_hash: e74d6791681e3af1b548748ff47a22c2
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-79dcb0ae501ac17004f50aecb112a798290ab3727fbe7c7d1b34299e38ed4f8e.yml
openapi_spec_hash: c8d54bd1ae3d704f6b6f72ffd2f876d8
config_hash: 167ad0ca036d0f023c78e6496b4311e8
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.13.1 (2025-07-15)

Full Changelog: [v0.13.0...v0.13.1](https://github.com/openai/openai-ruby/compare/v0.13.0...v0.13.1)

### Bug Fixes

* ensure openapi refs are correctly linked ([#746](https://github.com/openai/openai-ruby/issues/746)) ([ea3fccd](https://github.com/openai/openai-ruby/commit/ea3fccdc4f433e4e8a07ae6b47f8ef546b90d24b))


### Chores

* **api:** update realtime specs, build config ([8ccc35e](https://github.com/openai/openai-ruby/commit/8ccc35e04788eb52be853db6eafa585a9fd5140a))

## 0.13.0 (2025-07-10)

Full Changelog: [v0.12.0...v0.13.0](https://github.com/openai/openai-ruby/compare/v0.12.0...v0.13.0)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT
PATH
remote: .
specs:
openai (0.13.0)
openai (0.13.1)
connection_pool

GEM
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application
<!-- x-release-please-start-version -->

```ruby
gem "openai", "~> 0.13.0"
gem "openai", "~> 0.13.1"
```

<!-- x-release-please-end -->
Expand Down
1 change: 1 addition & 0 deletions examples/structured_outputs_chat_completions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CalendarEvent < OpenAI::BaseModel
required :name, String
required :date, String
required :participants, OpenAI::ArrayOf[Participant]
required :optional_participants, OpenAI::ArrayOf[Participant], nil?: true
required :is_virtual, OpenAI::Boolean
required :location,
OpenAI::UnionOf[String, Location],
Expand Down
1 change: 1 addition & 0 deletions examples/structured_outputs_responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CalendarEvent < OpenAI::BaseModel
required :name, String
required :date, String
required :participants, OpenAI::ArrayOf[Participant]
required :optional_participants, OpenAI::ArrayOf[Participant], nil?: true
required :is_virtual, OpenAI::Boolean
required :location,
OpenAI::UnionOf[String, Location],
Expand Down
44 changes: 34 additions & 10 deletions lib/openai/helpers/structured_output/json_schema_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,24 @@ module Helpers
module StructuredOutput
# To customize the JSON schema conversion for a type, implement the `JsonSchemaConverter` interface.
module JsonSchemaConverter
POINTER = Object.new.freeze
COUNTER = Object.new.freeze
# @api private
POINTER = Object.new.tap do
_1.define_singleton_method(:inspect) do
"#<#{OpenAI::Helpers::StructuredOutput::JsonSchemaConverter}::POINTER>"
end
end.freeze
# @api private
COUNTER = Object.new.tap do
_1.define_singleton_method(:inspect) do
"#<#{OpenAI::Helpers::StructuredOutput::JsonSchemaConverter}::COUNTER>"
end
end.freeze
# @api private
NO_REF = Object.new.tap do
_1.define_singleton_method(:inspect) do
"#<#{OpenAI::Helpers::StructuredOutput::JsonSchemaConverter}::NO_REF>"
end
end.freeze

# rubocop:disable Lint/UnusedMethodArgument

Expand Down Expand Up @@ -34,7 +50,12 @@ def to_nilable(schema)
null = "null"
case schema
in {"$ref": String}
{anyOf: [schema, {type: null}]}
{
anyOf: [
schema.update(OpenAI::Helpers::StructuredOutput::JsonSchemaConverter::NO_REF => true),
{type: null}
]
}
in {anyOf: schemas}
null = {type: null}
schemas.any? { _1 == null || _1 == {type: ["null"]} } ? schema : {anyOf: [*schemas, null]}
Expand Down Expand Up @@ -71,7 +92,7 @@ def cache_def!(state, type:, &blk)
}
defs.store(type, stored)
schema = blk.call
ref_path.replace("#/definitions/#{path.join('/')}")
ref_path.replace("#/$defs/#{path.join('/')}")
stored.update(schema)
ref
end
Expand All @@ -92,17 +113,20 @@ def to_json_schema(type)
reused_defs = {}
defs.each_value do |acc|
ref = acc.fetch(OpenAI::Helpers::StructuredOutput::JsonSchemaConverter::POINTER)
if (no_ref = ref.delete(OpenAI::Helpers::StructuredOutput::JsonSchemaConverter::NO_REF))
acc[OpenAI::Helpers::StructuredOutput::JsonSchemaConverter::COUNTER] -= 1
end
cnt = acc.fetch(OpenAI::Helpers::StructuredOutput::JsonSchemaConverter::COUNTER)

sch = acc.except(
OpenAI::Helpers::StructuredOutput::JsonSchemaConverter::POINTER,
OpenAI::Helpers::StructuredOutput::JsonSchemaConverter::COUNTER
)
if acc.fetch(OpenAI::Helpers::StructuredOutput::JsonSchemaConverter::COUNTER) > 1
reused_defs.store(ref.fetch(:$ref), sch)
else
ref.replace(sch)
end
cnt > 1 && !no_ref ? reused_defs.store(ref.fetch(:$ref), sch) : ref.replace(sch)
end
reused_defs.empty? ? schema : {"$defs": reused_defs}.update(schema)

xformed = reused_defs.transform_keys { _1.delete_prefix("#/$defs/") }
xformed.empty? ? schema : {"$defs": xformed}.update(schema)
end

# @api private
Expand Down
55 changes: 50 additions & 5 deletions lib/openai/models/eval_create_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ class SimpleInputMessage < OpenAI::Internal::Type::BaseModel

class EvalItem < OpenAI::Internal::Type::BaseModel
# @!attribute content
# Text inputs to the model - can contain template strings.
# Inputs to the model - can contain template strings.
#
# @return [String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::OutputText]
# @return [String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::OutputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::InputImage, Array<Object>]
required :content,
union: -> {
OpenAI::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content
Expand Down Expand Up @@ -318,13 +318,13 @@ class EvalItem < OpenAI::Internal::Type::BaseModel
# `assistant` role are presumed to have been generated by the model in previous
# interactions.
#
# @param content [String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::OutputText] Text inputs to the model - can contain template strings.
# @param content [String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::OutputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::InputImage, Array<Object>] Inputs to the model - can contain template strings.
#
# @param role [Symbol, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Role] The role of the message input. One of `user`, `assistant`, `system`, or
#
# @param type [Symbol, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Type] The type of the message input. Always `message`.

# Text inputs to the model - can contain template strings.
# Inputs to the model - can contain template strings.
#
# @see OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem#content
module Content
Expand All @@ -341,6 +341,14 @@ module Content
OpenAI::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::OutputText
}

# An image input to the model.
variant -> {
OpenAI::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::InputImage
}

# A list of inputs, each of which may be either an input text or input image object.
variant -> { OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::AnArrayOfInputTextAndInputImageArray }

class OutputText < OpenAI::Internal::Type::BaseModel
# @!attribute text
# The text output from the model.
Expand All @@ -366,8 +374,45 @@ class OutputText < OpenAI::Internal::Type::BaseModel
# @param type [Symbol, :output_text] The type of the output text. Always `output_text`.
end

class InputImage < OpenAI::Internal::Type::BaseModel
# @!attribute image_url
# The URL of the image input.
#
# @return [String]
required :image_url, String

# @!attribute type
# The type of the image input. Always `input_image`.
#
# @return [Symbol, :input_image]
required :type, const: :input_image

# @!attribute detail
# The detail level of the image to be sent to the model. One of `high`, `low`, or
# `auto`. Defaults to `auto`.
#
# @return [String, nil]
optional :detail, String

# @!method initialize(image_url:, detail: nil, type: :input_image)
# Some parameter documentations has been truncated, see
# {OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::InputImage}
# for more details.
#
# An image input to the model.
#
# @param image_url [String] The URL of the image input.
#
# @param detail [String] The detail level of the image to be sent to the model. One of `high`, `low`, or
#
# @param type [Symbol, :input_image] The type of the image input. Always `input_image`.
end

# @!method self.variants
# @return [Array(String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::OutputText)]
# @return [Array(String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::OutputText, OpenAI::Models::EvalCreateParams::TestingCriterion::LabelModel::Input::EvalItem::Content::InputImage, Array<Object>)]

# @type [OpenAI::Internal::Type::Converter]
AnArrayOfInputTextAndInputImageArray = OpenAI::Internal::Type::ArrayOf[OpenAI::Internal::Type::Unknown]
end

# The role of the message input. One of `user`, `assistant`, `system`, or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ module Template

class Message < OpenAI::Internal::Type::BaseModel
# @!attribute content
# Text inputs to the model - can contain template strings.
# Inputs to the model - can contain template strings.
#
# @return [String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::OutputText]
# @return [String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::OutputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::InputImage, Array<Object>]
required :content,
union: -> {
OpenAI::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content
Expand Down Expand Up @@ -315,13 +315,13 @@ class Message < OpenAI::Internal::Type::BaseModel
# `assistant` role are presumed to have been generated by the model in previous
# interactions.
#
# @param content [String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::OutputText] Text inputs to the model - can contain template strings.
# @param content [String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::OutputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::InputImage, Array<Object>] Inputs to the model - can contain template strings.
#
# @param role [Symbol, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Role] The role of the message input. One of `user`, `assistant`, `system`, or
#
# @param type [Symbol, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Type] The type of the message input. Always `message`.

# Text inputs to the model - can contain template strings.
# Inputs to the model - can contain template strings.
#
# @see OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message#content
module Content
Expand All @@ -338,6 +338,14 @@ module Content
OpenAI::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::OutputText
}

# An image input to the model.
variant -> {
OpenAI::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::InputImage
}

# A list of inputs, each of which may be either an input text or input image object.
variant -> { OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::AnArrayOfInputTextAndInputImageArray }

class OutputText < OpenAI::Internal::Type::BaseModel
# @!attribute text
# The text output from the model.
Expand All @@ -363,8 +371,45 @@ class OutputText < OpenAI::Internal::Type::BaseModel
# @param type [Symbol, :output_text] The type of the output text. Always `output_text`.
end

class InputImage < OpenAI::Internal::Type::BaseModel
# @!attribute image_url
# The URL of the image input.
#
# @return [String]
required :image_url, String

# @!attribute type
# The type of the image input. Always `input_image`.
#
# @return [Symbol, :input_image]
required :type, const: :input_image

# @!attribute detail
# The detail level of the image to be sent to the model. One of `high`, `low`, or
# `auto`. Defaults to `auto`.
#
# @return [String, nil]
optional :detail, String

# @!method initialize(image_url:, detail: nil, type: :input_image)
# Some parameter documentations has been truncated, see
# {OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::InputImage}
# for more details.
#
# An image input to the model.
#
# @param image_url [String] The URL of the image input.
#
# @param detail [String] The detail level of the image to be sent to the model. One of `high`, `low`, or
#
# @param type [Symbol, :input_image] The type of the image input. Always `input_image`.
end

# @!method self.variants
# @return [Array(String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::OutputText)]
# @return [Array(String, OpenAI::Models::Responses::ResponseInputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::OutputText, OpenAI::Models::Evals::CreateEvalCompletionsRunDataSource::InputMessages::Template::Template::Message::Content::InputImage, Array<Object>)]

# @type [OpenAI::Internal::Type::Converter]
AnArrayOfInputTextAndInputImageArray = OpenAI::Internal::Type::ArrayOf[OpenAI::Internal::Type::Unknown]
end

# The role of the message input. One of `user`, `assistant`, `system`, or
Expand Down
Loading