Module: RubyLLM::Protocols::ChatCompletions::Moderation
- Defined in:
- lib/ruby_llm/protocols/chat_completions/moderation.rb
Overview
Moderation methods of the OpenAI API integration
Class Method Summary collapse
- .format_moderation_attachment(attachment) ⇒ Object
- .moderation_input(input, attachments) ⇒ Object
- .moderation_url ⇒ Object
- .parse_moderation_response(response, model:) ⇒ Object
- .render_moderation_payload(input, model:, with: [], provider_options: {}) ⇒ Object
Class Method Details
.format_moderation_attachment(attachment) ⇒ Object
44 45 46 47 48 |
# File 'lib/ruby_llm/protocols/chat_completions/moderation.rb', line 44 def () raise UnsupportedAttachmentError, .mime_type unless .image? Media.format_image() end |
.moderation_input(input, attachments) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/ruby_llm/protocols/chat_completions/moderation.rb', line 35 def moderation_input(input, ) return input if .empty? parts = [] parts << Media.format_text(input) if input parts.concat(.map { || () }) parts end |
.moderation_url ⇒ Object
10 11 12 |
# File 'lib/ruby_llm/protocols/chat_completions/moderation.rb', line 10 def moderation_url 'moderations' end |
.parse_moderation_response(response, model:) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_llm/protocols/chat_completions/moderation.rb', line 23 def parse_moderation_response(response, model:) data = response.body raise Error.new(data.dig('error', 'message'), response:) if data.dig('error', 'message') RubyLLM::Moderation.new( id: data['id'], model: model, results: Array(data['results']).map { |result| RubyLLM::Moderation::Result.from_h(result) }, raw: data ) end |
.render_moderation_payload(input, model:, with: [], provider_options: {}) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/ruby_llm/protocols/chat_completions/moderation.rb', line 14 def render_moderation_payload(input, model:, with: [], provider_options: {}) = Attachment.wrap(with) { model: model, input: moderation_input(input, ) }.merge() end |