omniai 3.0.0 → 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: 498fab4d1dc0776ca9b28f970145e9184dd503b7d3032fc45617c0459a442dee
4
- data.tar.gz: b0ba0873060444dc59ceb5fe946eaa7b087eb0709a0bd47b80f22bfcc1d5a30c
3
+ metadata.gz: 0ab654a67cbbe8a0fca968721a942c14a0e70a1bc0b0ca894c3b63c737e75bde
4
+ data.tar.gz: 7cea942027a5864ff5a62c7eeb9b53295fc8729d8b167360aff15b1c641ee8cb
5
5
  SHA512:
6
- metadata.gz: 820e63cbc2a5e4f2cc5d6729ae2d3a0fff1950a16bd22d80eab5fec420975ab79992a6cba1fb332dc0643f4ace515ed389d45be225774b7ae59f5ca911b77b12
7
- data.tar.gz: 965a88b9114ee0b215d25a98bcdf4354ac60931154fe2d87859cf423b8d953fc679bdcdb3cb51d82a0118fab926553dffb19eb140cb43ff973e946b76f294549
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,12 +71,14 @@ module OmniAI
71
71
  # @example
72
72
  # array.serialize # => { type: "array", items: { type: "string" } }
73
73
  #
74
+ # @param additional_properties [Boolean, nil] optional
75
+ #
74
76
  # @return [Hash]
75
- def serialize
77
+ def serialize(additional_properties: false)
76
78
  {
77
79
  type: TYPE,
78
80
  description: @description,
79
- items: @items.serialize,
81
+ items: @items.serialize(additional_properties:),
80
82
  maxItems: @max_items,
81
83
  minItems: @min_items,
82
84
  }.compact
@@ -51,11 +51,13 @@ module OmniAI
51
51
  # @example
52
52
  # format.serialize # => { name: "...", schema: { ... } }
53
53
  #
54
+ # @param additional_properties [Boolean, nil] optional
55
+ #
54
56
  # @return [Hash]
55
- def serialize
57
+ def serialize(additional_properties: false)
56
58
  {
57
59
  name:,
58
- schema: schema.serialize,
60
+ schema: schema.serialize(additional_properties:),
59
61
  }
60
62
  end
61
63
 
@@ -74,15 +74,17 @@ module OmniAI
74
74
  )
75
75
  end
76
76
 
77
+ # @param additional_properties [Boolean, nil] optional
78
+ #
77
79
  # @return [Hash]
78
- def serialize
80
+ def serialize(additional_properties: false)
79
81
  {
80
82
  type: TYPE,
81
83
  title: @title,
82
84
  description: @description,
83
- properties: @properties.transform_values(&:serialize),
85
+ properties: @properties.transform_values { |value| value.serialize(additional_properties:) },
84
86
  required: @required,
85
- additionalProperties: false,
87
+ additionalProperties: additional_properties,
86
88
  }.compact
87
89
  end
88
90
 
@@ -91,7 +91,7 @@ module OmniAI
91
91
  # property.serialize #=> { type: "string" }
92
92
  #
93
93
  # @return [Hash]
94
- def serialize
94
+ def serialize(*)
95
95
  {
96
96
  type: @type,
97
97
  description: @description,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = "3.0.0"
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.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre