Class: LLM::Multipart
- Inherits:
-
Object
- Object
- LLM::Multipart
- Defined in:
- lib/llm/multipart.rb
Instance Attribute Summary collapse
- #boundary ⇒ String readonly
Instance Method Summary collapse
-
#body ⇒ String
Returns the multipart request body.
-
#content_type ⇒ String
Returns the multipart content type.
- #initialize(params) ⇒ LLM::Multipart constructor
-
#parts ⇒ Array<String>
Returns the multipart request body parts.
Constructor Details
#initialize(params) ⇒ LLM::Multipart
18 19 20 21 |
# File 'lib/llm/multipart.rb', line 18 def initialize(params) @boundary = "BOUNDARY__#{SecureRandom.hex(16)}" @params = params end |
Instance Attribute Details
#boundary ⇒ String (readonly)
12 13 14 |
# File 'lib/llm/multipart.rb', line 12 def boundary @boundary end |
Instance Method Details
#body ⇒ String
Returns the multipart request body
47 48 49 50 51 |
# File 'lib/llm/multipart.rb', line 47 def body io = StringIO.new("".b) [*parts, StringIO.new("--#{@boundary}--\r\n".b)].each { IO.copy_stream(_1.tap(&:rewind), io) } io.tap(&:rewind) end |
#content_type ⇒ String
Returns the multipart content type
26 27 28 |
# File 'lib/llm/multipart.rb', line 26 def content_type "multipart/form-data; boundary=#{@boundary}" end |
#parts ⇒ Array<String>
Returns the multipart request body parts
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/llm/multipart.rb', line 33 def parts params.map do |key, value| locals = {key: key.to_s.b, boundary: boundary.to_s.b} if value.respond_to?(:path) file_part(key, value, locals) else data_part(key, value, locals) end end end |