Skip to content

Commit c78ea0f

Browse files
fix: make a typo for FilePart.content
1 parent 513acd8 commit c78ea0f

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

lib/openai/file_part.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class FilePart
1515
#
1616
# @return [String]
1717
private def read
18-
case contents
18+
case content
1919
in Pathname
20-
contents.read(binmode: true)
20+
content.read(binmode: true)
2121
in StringIO
22-
contents.string
22+
content.string
2323
in IO
24-
contents.read
24+
content.read
2525
in String
26-
contents
26+
content
2727
end
2828
end
2929

lib/openai/internal/type/converter.rb

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def dump(value, state:)
4444
in Pathname | IO
4545
state[:can_retry] = false if value.is_a?(IO)
4646
OpenAI::FilePart.new(value)
47+
in OpenAI::FilePart
48+
state[:can_retry] = false if value.content.is_a?(IO)
49+
value
4750
else
4851
value
4952
end

lib/openai/internal/type/file_input.rb

+22-11
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,28 @@ def coerce(value, state:)
6767
end
6868
end
6969

70-
# @!parse
71-
# # @api private
72-
# #
73-
# # @param value [Pathname, StringIO, IO, String, Object]
74-
# #
75-
# # @param state [Hash{Symbol=>Object}] .
76-
# #
77-
# # @option state [Boolean] :can_retry
78-
# #
79-
# # @return [Pathname, StringIO, IO, String, Object]
80-
# def dump(value, state:) = super
70+
# @api private
71+
#
72+
# @param value [Pathname, StringIO, IO, String, Object]
73+
#
74+
# @param state [Hash{Symbol=>Object}] .
75+
#
76+
# @option state [Boolean] :can_retry
77+
#
78+
# @return [Pathname, StringIO, IO, String, Object]
79+
def dump(value, state:)
80+
# rubocop:disable Lint/DuplicateBranch
81+
case value
82+
in IO
83+
state[:can_retry] = false
84+
in OpenAI::FilePart if value.content.is_a?(IO)
85+
state[:can_retry] = false
86+
else
87+
end
88+
# rubocop:enable Lint/DuplicateBranch
89+
90+
value
91+
end
8192
end
8293
end
8394
end

test/openai/file_part_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "test_helper"
4+
5+
class OpenAI::Test::FilePartTest < Minitest::Test
6+
def test_to_json
7+
text = "gray"
8+
filepart = OpenAI::FilePart.new(StringIO.new(text))
9+
10+
assert_equal(text.to_json, filepart.to_json)
11+
end
12+
end

0 commit comments

Comments
 (0)