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 +4 -4
- data/lib/omniai/chat/response.rb +23 -46
- data/lib/omniai/chat/tool_call_list.rb +5 -1
- data/lib/omniai/schema/array.rb +1 -1
- data/lib/omniai/schema/format.rb +1 -1
- data/lib/omniai/schema/object.rb +1 -1
- data/lib/omniai/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ab654a67cbbe8a0fca968721a942c14a0e70a1bc0b0ca894c3b63c737e75bde
|
|
4
|
+
data.tar.gz: 7cea942027a5864ff5a62c7eeb9b53295fc8729d8b167360aff15b1c641ee8cb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8053636d067f6c1a09d746a3fcaa4b4d1a873d89ed105149a7eb9fa5a370c21f13bece4b7edf83f0529f442aa7abaaef860bb2e81309d25313c53eef92fbb32e
|
|
7
|
+
data.tar.gz: 4d59606ebee19692a25f68b58542105260770dc73ff97b4b96bd6171758b1c3981533e8b6b8e114310f1cc2de1a91be2978a2a7bf39bf77a3d0986e8bb39da5f
|
data/lib/omniai/chat/response.rb
CHANGED
|
@@ -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
|
-
#
|
|
7
|
+
# @!attribute [data]
|
|
8
|
+
# @return [Hash]
|
|
8
9
|
attr_accessor :data
|
|
9
10
|
|
|
10
|
-
#
|
|
11
|
-
|
|
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
|
-
# @
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
81
|
-
|
|
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
|
|
93
|
-
|
|
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?
|
|
100
|
-
|
|
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
|
|
58
|
+
# @param other [ToolCallList]
|
|
59
|
+
#
|
|
60
|
+
# @return [ToolCallList]
|
|
57
61
|
def +(other)
|
|
58
62
|
self.class.new(entries: entries + other.entries)
|
|
59
63
|
end
|
data/lib/omniai/schema/array.rb
CHANGED
|
@@ -71,7 +71,7 @@ module OmniAI
|
|
|
71
71
|
# @example
|
|
72
72
|
# array.serialize # => { type: "array", items: { type: "string" } }
|
|
73
73
|
#
|
|
74
|
-
# @param
|
|
74
|
+
# @param additional_properties [Boolean, nil] optional
|
|
75
75
|
#
|
|
76
76
|
# @return [Hash]
|
|
77
77
|
def serialize(additional_properties: false)
|
data/lib/omniai/schema/format.rb
CHANGED
|
@@ -51,7 +51,7 @@ module OmniAI
|
|
|
51
51
|
# @example
|
|
52
52
|
# format.serialize # => { name: "...", schema: { ... } }
|
|
53
53
|
#
|
|
54
|
-
# @param
|
|
54
|
+
# @param additional_properties [Boolean, nil] optional
|
|
55
55
|
#
|
|
56
56
|
# @return [Hash]
|
|
57
57
|
def serialize(additional_properties: false)
|
data/lib/omniai/schema/object.rb
CHANGED
data/lib/omniai/version.rb
CHANGED