omniai 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d531aa6fb65bf379e80e1ee381a9e0bcdc593ff50368023284516b1d63c12d2e
4
- data.tar.gz: cfb766bb5a41be87fa2a24766f1a14ce03fb48bda3aeb5bf747f6f6d23cecc55
3
+ metadata.gz: 0ab654a67cbbe8a0fca968721a942c14a0e70a1bc0b0ca894c3b63c737e75bde
4
+ data.tar.gz: 7cea942027a5864ff5a62c7eeb9b53295fc8729d8b167360aff15b1c641ee8cb
5
5
  SHA512:
6
- metadata.gz: 4128c986161424706af7cdd57ef1d2a23541761cebd94e798e15fcd5959d8e55b79c7c7bac3aa7a69efe6c65ebb24b47154f37077a28cc233f22e0ec7c7af1f9
7
- data.tar.gz: e4d043eb1ca554d3da937b0a72b45ef659125f7d7e52adc855ffa4ee446f2735a3981f00e361fc75c55573bfc72e46c98403d459acc7b732579fe06f2bdaa658
6
+ metadata.gz: 8053636d067f6c1a09d746a3fcaa4b4d1a873d89ed105149a7eb9fa5a370c21f13bece4b7edf83f0529f442aa7abaaef860bb2e81309d25313c53eef92fbb32e
7
+ data.tar.gz: 4d59606ebee19692a25f68b58542105260770dc73ff97b4b96bd6171758b1c3981533e8b6b8e114310f1cc2de1a91be2978a2a7bf39bf77a3d0986e8bb39da5f
@@ -4,15 +4,18 @@ module OmniAI
4
4
  class Chat
5
5
  # An `OmniAI::Chat::Response` encapsulates the result of generating a chat completion.
6
6
  class Response
7
- # @return [Hash]
7
+ # @!attribute [data]
8
+ # @return [Hash]
8
9
  attr_accessor :data
9
10
 
10
- # @return [Array<Choice>]
11
- attr_accessor :choices
12
-
13
- # @return [Usage, nil]
11
+ # @!attribute [usage]
12
+ # @return [Usage, nil]
14
13
  attr_accessor :usage
15
14
 
15
+ # @!attribute [choices]
16
+ # @return [Array<Choice>]
17
+ attr_accessor :choices
18
+
16
19
  # @param data [Hash]
17
20
  # @param choices [Array<Choice>]
18
21
  # @param usage [Usage, nil]
@@ -24,7 +27,7 @@ module OmniAI
24
27
 
25
28
  # @return [String]
26
29
  def inspect
27
- "#<#{self.class.name} choices=#{choices.inspect} usage=#{usage.inspect}>"
30
+ "#<#{self.class.name} choices=#{@choices.inspect} usage=#{@usage.inspect}>"
28
31
  end
29
32
 
30
33
  # @param data [Hash]
@@ -42,64 +45,38 @@ module OmniAI
42
45
  end
43
46
 
44
47
  # @param context [OmniAI::Context] optional
48
+ #
45
49
  # @return [Hash]
46
50
  def serialize(context:)
47
51
  serialize = context&.serializer(:response)
48
52
  return serialize.call(self, context:) if serialize
49
53
 
50
54
  {
51
- choices: choices.map { |choice| choice.serialize(context:) },
52
- usage: usage&.serialize(context:),
55
+ choices: @choices.map { |choice| choice.serialize(context:) },
56
+ usage: @usage&.serialize(context:),
53
57
  }
54
58
  end
55
59
 
56
- # @param index [Integer]
57
- #
58
- # @return [Choice, nil]
59
- def choice(index: 0)
60
- @choices[index]
61
- end
62
-
63
- # @param index [Integer]
64
- #
65
- # @return [Boolean]
66
- def choice?(index: 0)
67
- !choice(index:).nil?
68
- end
69
-
70
- # @param index [Integer]
71
- #
72
- # @return [Message, nil]
73
- def message(index: 0)
74
- choice(index:)&.message
60
+ # @return [Array<Message>]
61
+ def messages
62
+ @choices.map(&:message).compact
75
63
  end
76
64
 
77
- # @param index [Integer]
78
- #
79
65
  # @return [Boolean]
80
- def message?(index: 0)
81
- !message(index:).nil?
82
- end
83
-
84
- # @return [Array<Message>]
85
- def messages
86
- @choices.map(&:message)
66
+ def messages?
67
+ messages.any?
87
68
  end
88
69
 
89
- # @param index [Integer]
90
- #
91
70
  # @return [String, nil]
92
- def text(index: 0)
93
- message(index:)&.text
71
+ def text
72
+ return unless text?
73
+
74
+ messages.filter(&:text?).map(&:text).join("\n\n")
94
75
  end
95
76
 
96
- # @param index [Integer]
97
- #
98
77
  # @return [Boolean]
99
- def text?(index: 0)
100
- message = message(index:)
101
-
102
- !message.nil? && message.text?
78
+ def text?
79
+ messages.any?(&:text?)
103
80
  end
104
81
 
105
82
  # @return [ToolCallList, nil]
@@ -48,12 +48,16 @@ module OmniAI
48
48
  @entries.each(&)
49
49
  end
50
50
 
51
+ # @param index [Integer]
52
+ #
51
53
  # @return [ToolCall]
52
54
  def [](index)
53
55
  @entries[index]
54
56
  end
55
57
 
56
- # @param [other] [ToolCallList]
58
+ # @param other [ToolCallList]
59
+ #
60
+ # @return [ToolCallList]
57
61
  def +(other)
58
62
  self.class.new(entries: entries + other.entries)
59
63
  end
@@ -71,7 +71,7 @@ module OmniAI
71
71
  # @example
72
72
  # array.serialize # => { type: "array", items: { type: "string" } }
73
73
  #
74
- # @param options [Hash] optional
74
+ # @param additional_properties [Boolean, nil] optional
75
75
  #
76
76
  # @return [Hash]
77
77
  def serialize(additional_properties: false)
@@ -51,7 +51,7 @@ module OmniAI
51
51
  # @example
52
52
  # format.serialize # => { name: "...", schema: { ... } }
53
53
  #
54
- # @param options [Hash] optional (e.g. `{ additional_properties: nil }``)
54
+ # @param additional_properties [Boolean, nil] optional
55
55
  #
56
56
  # @return [Hash]
57
57
  def serialize(additional_properties: false)
@@ -74,7 +74,7 @@ module OmniAI
74
74
  )
75
75
  end
76
76
 
77
- # @param options [Hash] optional
77
+ # @param additional_properties [Boolean, nil] optional
78
78
  #
79
79
  # @return [Hash]
80
80
  def serialize(additional_properties: false)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = "3.0.1"
4
+ VERSION = "3.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre