Class: Geminai::Interaction
- Inherits:
-
Object
- Object
- Geminai::Interaction
- Defined in:
- lib/geminai/interaction.rb
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
- #base64(type = nil) ⇒ Object (also: #base64_file)
- #files ⇒ Object (also: #output_files)
- #grounding_metadata ⇒ Object
-
#initialize(data) ⇒ Interaction
constructor
A new instance of Interaction.
- #output_audio ⇒ Object
-
#output_images ⇒ Object
Deprecated specific helpers kept for compatibility but powered by generic methods.
- #output_text ⇒ Object
- #output_video ⇒ Object
- #output_videos ⇒ Object
- #uri(type = nil) ⇒ Object (also: #uri_file)
Constructor Details
#initialize(data) ⇒ Interaction
Returns a new instance of Interaction.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/geminai/interaction.rb', line 5 def initialize(data) @raw_data = data @id = data[:id] @status = data[:status] @usage = data[:usage] @created = data[:created] @updated = data[:updated] @model = data[:model] @steps = (data[:steps] || []).map { |step_data| Step.new(step_data) } end |
Instance Attribute Details
#created ⇒ Object (readonly)
Returns the value of attribute created.
3 4 5 |
# File 'lib/geminai/interaction.rb', line 3 def created @created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/geminai/interaction.rb', line 3 def id @id end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/geminai/interaction.rb', line 3 def model @model end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
3 4 5 |
# File 'lib/geminai/interaction.rb', line 3 def raw_data @raw_data end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
3 4 5 |
# File 'lib/geminai/interaction.rb', line 3 def status @status end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
3 4 5 |
# File 'lib/geminai/interaction.rb', line 3 def steps @steps end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
3 4 5 |
# File 'lib/geminai/interaction.rb', line 3 def updated @updated end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
3 4 5 |
# File 'lib/geminai/interaction.rb', line 3 def usage @usage end |
Instance Method Details
#base64(type = nil) ⇒ Object Also known as: base64_file
51 52 53 54 55 56 57 58 59 |
# File 'lib/geminai/interaction.rb', line 51 def base64(type = nil) file = if type files.find { |f| f[:type] == type.to_s && f[:data] } else files.find { |f| f[:data] } end file ? file[:data] : nil end |
#files ⇒ Object Also known as: output_files
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/geminai/interaction.rb', line 29 def files files = [] @steps.each do |step| next unless step.model_output? (step.content || []).each do |part| file_data = extract_file_data(part) files << file_data if file_data end end # Also include top-level outputs (like output_audio) if present in raw data @raw_data.each do |key, value| if key.to_s.start_with?("output_") && value.is_a?(Hash) && (value[:data] || value[:uri]) files << value.merge(type: key.to_s.sub("output_", "")) end end files end |
#grounding_metadata ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/geminai/interaction.rb', line 92 def queries = [] citations = [] suggestions = nil @steps.each do |step| if step.google_search_call? if step.arguments && step.arguments[:queries] queries.concat(step.arguments[:queries]) end elsif step.google_search_result? if step.result (step.result || []).each do |res| if res[:search_suggestions] suggestions = res[:search_suggestions] end end end elsif step.model_output? (step.content || []).each do |part| if part[:type] == "text" && part[:annotations] part[:annotations].each do |ann| citations << { start_index: ann[:start_index], end_index: ann[:end_index], url: ann[:url], title: ann[:title], type: ann[:type] } end end end end end GroundingMetadata.new( web_search_queries: queries.uniq, citations: citations, search_suggestions: suggestions ) end |
#output_audio ⇒ Object
88 89 90 |
# File 'lib/geminai/interaction.rb', line 88 def output_audio files.select { |f| f[:type] == "audio" }.first end |
#output_images ⇒ Object
Deprecated specific helpers kept for compatibility but powered by generic methods
76 77 78 |
# File 'lib/geminai/interaction.rb', line 76 def output_images files.select { |f| f[:type] == "image" } end |
#output_text ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/geminai/interaction.rb', line 17 def output_text text_parts = [] @steps.each do |step| next unless step.model_output? (step.content || []).each do |part| text_parts << part[:text] if part[:type] == "text" && part[:text] end end text_parts.join("") end |
#output_video ⇒ Object
84 85 86 |
# File 'lib/geminai/interaction.rb', line 84 def output_video output_videos.first end |
#output_videos ⇒ Object
80 81 82 |
# File 'lib/geminai/interaction.rb', line 80 def output_videos files.select { |f| f[:type] == "video" } end |
#uri(type = nil) ⇒ Object Also known as: uri_file
63 64 65 66 67 68 69 70 71 |
# File 'lib/geminai/interaction.rb', line 63 def uri(type = nil) file = if type files.find { |f| f[:type] == type.to_s && f[:uri] } else files.find { |f| f[:uri] } end file ? file[:uri] : nil end |