Class: OmniAI::Chat::Content
- Inherits:
-
Object
- Object
- OmniAI::Chat::Content
- Defined in:
- lib/omniai/chat/content.rb
Overview
A placeholder for parts of a message. Any subclass must implement the serializable interface.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.deserialize(data, context: nil) ⇒ Content
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/omniai/chat/content.rb', line 26 def self.deserialize(data, context: nil) return data if data.nil? return data.map { |data| deserialize(data, context:) } if data.is_a?(Array) deserialize = context&.deserializer(:content) return deserialize.call(data, context:) if deserialize return data if data.is_a?(String) raise ArgumentError, "untyped data=#{data.inspect}" unless data.key?('type') case data['type'] when 'text' then Text.deserialize(data, context:) when /(.*)_url/ then URL.deserialize(data, context:) else raise ArgumentError, "unknown type=#{data['type'].inspect}" end end |
.summarize(content) ⇒ String
8 9 10 11 12 13 |
# File 'lib/omniai/chat/content.rb', line 8 def self.summarize(content) return content.map { |entry| summarize(entry) }.join("\n\n") if content.is_a?(Array) return content if content.is_a?(String) content.summarize end |
Instance Method Details
#serialize(context: nil) ⇒ String
18 19 20 |
# File 'lib/omniai/chat/content.rb', line 18 def serialize(context: nil) raise NotImplementedError, "#{self.class}#serialize undefined" end |