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
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ Style/MethodCallWithArgsParentheses:
Exclude:
- "**/*.gemspec"

Style/MultilineBlockChain:
Enabled: false

# Perfectly fine.
Style/MultipleComparison:
Enabled: false
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ Due to limitations with the Sorbet type system, where a method otherwise can tak
Please follow Sorbet's [setup guides](https://sorbet.org/docs/adopting) for best experience.

```ruby
model = OpenAI::Models::Chat::CompletionCreateParams.new(
params = OpenAI::Models::Chat::CompletionCreateParams.new(
messages: [{
role: "user",
content: "Say this is a test"
}],
model: "gpt-4o"
)

openai.chat.completions.create(**model)
openai.chat.completions.create(**params)
```

## Advanced
Expand Down
9 changes: 6 additions & 3 deletions lib/openai/internal/type/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def optional(name_sym, type_info, spec = {})
# @param other [Object]
#
# @return [Boolean]
def ==(other) = other.is_a?(Class) && other <= OpenAI::Internal::Type::BaseModel && other.fields == fields
def ==(other)
other.is_a?(Class) && other <= OpenAI::Internal::Type::BaseModel && other.fields == fields
end
end

# @param other [Object]
Expand Down Expand Up @@ -350,15 +352,16 @@ def initialize(data = {})
in Hash => coerced
@data = coerced
else
raise ArgumentError.new("Expected a #{Hash} or #{OpenAI::Internal::Type::BaseModel}, got #{data.inspect}")
message = "Expected a #{Hash} or #{OpenAI::Internal::Type::BaseModel}, got #{data.inspect}"
raise ArgumentError.new(message)
end
end

# @return [String]
def inspect
rows = self.class.known_fields.keys.map do
"#{_1}=#{@data.key?(_1) ? public_send(_1) : ''}"
rescue OpenAI::ConversionError
rescue OpenAI::Errors::ConversionError
"#{_1}=#{@data.fetch(_1)}"
end
"#<#{self.class.name}:0x#{object_id.to_s(16)} #{rows.join(' ')}>"
Expand Down
2 changes: 2 additions & 0 deletions lib/openai/internal/type/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def coerce(
#
# @return [Object]
def dump(target, value)
# rubocop:disable Layout/LineLength
target.is_a?(OpenAI::Internal::Type::Converter) ? target.dump(value) : OpenAI::Internal::Type::Unknown.dump(value)
# rubocop:enable Layout/LineLength
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/openai/internal/type/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def ===(other) = values.include?(other)
#
# @return [Boolean]
def ==(other)
# rubocop:disable Layout/LineLength
other.is_a?(Module) && other.singleton_class <= OpenAI::Internal::Type::Enum && other.values.to_set == values.to_set
# rubocop:enable Layout/LineLength
end

# @api private
Expand Down