Module: RubyLLM::Protocols::Mistral::Conversations::Images
- Defined in:
- lib/ruby_llm/protocols/mistral/conversations/images.rb
Overview
:nodoc:
Instance Method Summary collapse
- #images_url ⇒ Object
- #parse_image_response(response, model:) ⇒ Object
- #parse_image_responses(response, model:) ⇒ Object
- #render_image_payload(prompt, model:, size:, count: nil, with: nil, mask: nil, provider_options: {}) ⇒ Object
Instance Method Details
#images_url ⇒ Object
8 9 10 |
# File 'lib/ruby_llm/protocols/mistral/conversations/images.rb', line 8 def images_url(**) 'conversations' end |
#parse_image_response(response, model:) ⇒ Object
23 24 25 |
# File 'lib/ruby_llm/protocols/mistral/conversations/images.rb', line 23 def parse_image_response(response, model:) parse_image_responses(response, model:).first end |
#parse_image_responses(response, model:) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_llm/protocols/mistral/conversations/images.rb', line 27 def parse_image_responses(response, model:) data = response.body = parse_conversation_content(data.fetch('outputs'))[:attachments] raise Error.new('Mistral returned no generated image', response:) if .empty? usage = parse_conversation_usage(data['usage'] || {}).transform_keys(&:to_s) .each_with_index.map do |, index| bytes = @provider.download_file(.provider_file_id) Image.new(data: Base64.strict_encode64(bytes), mime_type: RubyLLM::Files::MimeType.for(StringIO.new(bytes)), model: model, usage: index.zero? ? usage : {}) end end |
#render_image_payload(prompt, model:, size:, count: nil, with: nil, mask: nil, provider_options: {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby_llm/protocols/mistral/conversations/images.rb', line 12 def render_image_payload(prompt, model:, size:, count: nil, with: nil, mask: nil, provider_options: {}) if size || (count && count != 1) raise ArgumentError, 'Mistral image generation does not accept size or count options' end raise UnsupportedAttachmentError, 'image editing' if with || mask payload = { model: model, store: false, inputs: prompt, tools: [{ type: 'image_generation' }] } Support::Utils.deep_merge(payload, ) end |