Module: RubyLLM::Providers::OpenRouter::Embeddings
- Included in:
- ChatCompletions
- Defined in:
- lib/ruby_llm/providers/openrouter/embeddings.rb
Overview
Text and multimodal embedding requests for OpenRouter.
Constant Summary collapse
- EMBEDDING_MEDIA_TYPES =
{ audio: :input_audio, video: :input_video, pdf: :input_file }.freeze
Class Method Summary collapse
- .format_embedding_attachment(attachment) ⇒ Object
- .format_embedding_content(text, attachments) ⇒ Object
- .render_embedding_payload(text, model:, dimensions:, task_type: nil, title: nil, with: [], provider_options: {}) ⇒ Object
- .supports_embedding_media? ⇒ Boolean
Class Method Details
.format_embedding_attachment(attachment) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_llm/providers/openrouter/embeddings.rb', line 37 def () raise UnsupportedAttachmentError, .mime_type if .provider_file? if (type = EMBEDDING_MEDIA_TYPES[.type]) { type: type.to_s, type => { data: .for_llm, format: .format } } else Protocols::ChatCompletions::Media.( , document_attachments: :none, image_attachments: true, audio_attachments: false ) end end |
.format_embedding_content(text, attachments) ⇒ Object
31 32 33 34 35 |
# File 'lib/ruby_llm/providers/openrouter/embeddings.rb', line 31 def (text, ) Protocols::ChatCompletions::Media.format_parts(text, ) do || () end end |
.render_embedding_payload(text, model:, dimensions:, task_type: nil, title: nil, with: [], provider_options: {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_llm/providers/openrouter/embeddings.rb', line 16 def (text, model:, dimensions:, task_type: nil, title: nil, with: [], provider_options: {}) input = if with.any? raise ArgumentError, 'embed one text at a time when embedding attachments' if text.is_a?(Array) [{ content: (text, with) }] else text end payload = super(input, model:, dimensions:, task_type:, title:, provider_options: {}) payload[:input_type] = task_type if task_type payload.merge() end |
.supports_embedding_media? ⇒ Boolean
12 13 14 |
# File 'lib/ruby_llm/providers/openrouter/embeddings.rb', line 12 def true end |