Module: OpenTelemetry::Instrumentation::RubyLLM::MessageFormatter
- Defined in:
- lib/opentelemetry/instrumentation/ruby_llm/message_formatter.rb
Overview
Converts RubyLLM messages and content into the JSON shape defined by
the GenAI semantic conventions for input/output messages and system
instructions:
https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/gen-ai-input-.json
https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/gen-ai-output-.json
https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/gen-ai-system-instructions.json
Kept separate from the RubyLLM::Chat patch so the formatting logic
does not pollute the patched class.
Class Method Summary collapse
- .format_input_messages(messages) ⇒ Object
- .format_output_messages(messages) ⇒ Object
- .format_system_instructions(messages) ⇒ Object
Class Method Details
.format_input_messages(messages) ⇒ Object
17 18 19 |
# File 'lib/opentelemetry/instrumentation/ruby_llm/message_formatter.rb', line 17 def self.() .map { |m| (m) }.to_json end |
.format_output_messages(messages) ⇒ Object
21 22 23 |
# File 'lib/opentelemetry/instrumentation/ruby_llm/message_formatter.rb', line 21 def self.() .map { |m| (m) }.to_json end |
.format_system_instructions(messages) ⇒ Object
25 26 27 |
# File 'lib/opentelemetry/instrumentation/ruby_llm/message_formatter.rb', line 25 def self.format_system_instructions() .flat_map { |m| format_content(m.content) }.to_json end |