omniai 2.9.1 → 3.0.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/content.rb +2 -1
- data/lib/omniai/chat/file.rb +4 -2
- data/lib/omniai/chat/message.rb +8 -0
- data/lib/omniai/chat/response.rb +8 -9
- data/lib/omniai/chat/text.rb +5 -3
- data/lib/omniai/chat/tool_call_list.rb +10 -0
- data/lib/omniai/chat/tool_call_message.rb +1 -2
- data/lib/omniai/chat/url.rb +5 -3
- data/lib/omniai/chat.rb +17 -4
- data/lib/omniai/client.rb +5 -4
- data/lib/omniai/schema/object.rb +1 -0
- 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: 498fab4d1dc0776ca9b28f970145e9184dd503b7d3032fc45617c0459a442dee
|
|
4
|
+
data.tar.gz: b0ba0873060444dc59ceb5fe946eaa7b087eb0709a0bd47b80f22bfcc1d5a30c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 820e63cbc2a5e4f2cc5d6729ae2d3a0fff1950a16bd22d80eab5fec420975ab79992a6cba1fb332dc0643f4ace515ed389d45be225774b7ae59f5ca911b77b12
|
|
7
|
+
data.tar.gz: 965a88b9114ee0b215d25a98bcdf4354ac60931154fe2d87859cf423b8d953fc679bdcdb3cb51d82a0118fab926553dffb19eb140cb43ff973e946b76f294549
|
data/lib/omniai/chat/content.rb
CHANGED
|
@@ -13,9 +13,10 @@ module OmniAI
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# @param context [Context] optional
|
|
16
|
+
# @param direction [String] optional either "input" or "output"
|
|
16
17
|
#
|
|
17
18
|
# @return [String]
|
|
18
|
-
def serialize(context: nil)
|
|
19
|
+
def serialize(context: nil, direction: nil)
|
|
19
20
|
raise NotImplementedError, "#{self.class}#serialize undefined"
|
|
20
21
|
end
|
|
21
22
|
|
data/lib/omniai/chat/file.rb
CHANGED
|
@@ -29,14 +29,16 @@ module OmniAI
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
# @param context [Context]
|
|
32
|
+
# @param direction [String] optional - either "input" or "output"
|
|
33
|
+
#
|
|
32
34
|
# @return [Hash]
|
|
33
|
-
def serialize(context: nil)
|
|
35
|
+
def serialize(context: nil, direction: nil)
|
|
34
36
|
if text?
|
|
35
37
|
content = fetch!
|
|
36
38
|
Text.new("<file>#{filename}: #{content}</file>").serialize(context:)
|
|
37
39
|
else
|
|
38
40
|
serializer = context&.serializer(:file)
|
|
39
|
-
return serializer.call(self, context:) if serializer
|
|
41
|
+
return serializer.call(self, context:, direction:) if serializer
|
|
40
42
|
|
|
41
43
|
{ type: "#{kind}_url", "#{kind}_url": { url: data_uri } }
|
|
42
44
|
end
|
data/lib/omniai/chat/message.rb
CHANGED
data/lib/omniai/chat/response.rb
CHANGED
|
@@ -102,18 +102,17 @@ module OmniAI
|
|
|
102
102
|
!message.nil? && message.text?
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
# @
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
# @return [ToolCallList, nil]
|
|
106
|
+
def tool_call_list
|
|
107
|
+
tool_call_lists = messages.map(&:tool_call_list).compact
|
|
108
|
+
return if tool_call_lists.empty?
|
|
109
|
+
|
|
110
|
+
tool_call_lists.reduce(&:+)
|
|
110
111
|
end
|
|
111
112
|
|
|
112
113
|
# @return [Boolean]
|
|
113
|
-
def tool_call_list?
|
|
114
|
-
tool_call_list
|
|
115
|
-
|
|
116
|
-
!tool_call_list.nil? && tool_call_list.any?
|
|
114
|
+
def tool_call_list?
|
|
115
|
+
!tool_call_list.nil?
|
|
117
116
|
end
|
|
118
117
|
end
|
|
119
118
|
end
|
data/lib/omniai/chat/text.rb
CHANGED
|
@@ -23,7 +23,8 @@ module OmniAI
|
|
|
23
23
|
@text
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
# @param
|
|
26
|
+
# @param context [Context] optional
|
|
27
|
+
# @param data [Hash] required
|
|
27
28
|
def self.deserialize(data, context: nil)
|
|
28
29
|
deserialize = context&.deserializer(:text)
|
|
29
30
|
return deserialize.call(data, context:) if deserialize
|
|
@@ -32,11 +33,12 @@ module OmniAI
|
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
# @param context [Context] optional
|
|
36
|
+
# @param direction [String] optional - either "input" or "output"
|
|
35
37
|
#
|
|
36
38
|
# @return [Hash]
|
|
37
|
-
def serialize(context: nil)
|
|
39
|
+
def serialize(context: nil, direction: nil)
|
|
38
40
|
serializer = context&.serializer(:text)
|
|
39
|
-
return serializer.call(self, context:) if serializer
|
|
41
|
+
return serializer.call(self, context:, direction:) if serializer
|
|
40
42
|
|
|
41
43
|
{ type: "text", text: @text }
|
|
42
44
|
end
|
|
@@ -47,6 +47,16 @@ module OmniAI
|
|
|
47
47
|
def each(&)
|
|
48
48
|
@entries.each(&)
|
|
49
49
|
end
|
|
50
|
+
|
|
51
|
+
# @return [ToolCall]
|
|
52
|
+
def [](index)
|
|
53
|
+
@entries[index]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @param [other] [ToolCallList]
|
|
57
|
+
def +(other)
|
|
58
|
+
self.class.new(entries: entries + other.entries)
|
|
59
|
+
end
|
|
50
60
|
end
|
|
51
61
|
end
|
|
52
62
|
end
|
|
@@ -40,8 +40,7 @@ module OmniAI
|
|
|
40
40
|
|
|
41
41
|
# Usage:
|
|
42
42
|
#
|
|
43
|
-
# message.serialize # => { role: :
|
|
44
|
-
# message.serialize # => { role: :user, content: [{ type: 'text', text: 'Hello!' }] }
|
|
43
|
+
# message.serialize # => { role: :tool, content: 'Hello!', tool_call_id: '...' }
|
|
45
44
|
#
|
|
46
45
|
# @param context [Context] optional
|
|
47
46
|
#
|
data/lib/omniai/chat/url.rb
CHANGED
|
@@ -26,7 +26,8 @@ module OmniAI
|
|
|
26
26
|
"#<#{self.class} uri=#{@uri.inspect}>"
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
# @param
|
|
29
|
+
# @param context [Context] optional
|
|
30
|
+
# @param data [Hash] required
|
|
30
31
|
def self.deserialize(data, context: nil)
|
|
31
32
|
deserialize = context&.deserializer(:url)
|
|
32
33
|
return deserialize.call(data, context:) if deserialize
|
|
@@ -38,15 +39,16 @@ module OmniAI
|
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
# @param context [Context] optional
|
|
42
|
+
# @param direction [String] optional - either "input" or "output"
|
|
41
43
|
#
|
|
42
44
|
# @return [Hash]
|
|
43
|
-
def serialize(context: nil)
|
|
45
|
+
def serialize(context: nil, direction: nil)
|
|
44
46
|
if text?
|
|
45
47
|
content = fetch!
|
|
46
48
|
Text.new("<file>#{filename}: #{content}</file>").serialize(context:)
|
|
47
49
|
else
|
|
48
50
|
serializer = context&.serializer(:url)
|
|
49
|
-
return serializer.call(self, context:) if serializer
|
|
51
|
+
return serializer.call(self, context:, direction:) if serializer
|
|
50
52
|
|
|
51
53
|
{
|
|
52
54
|
type: "#{kind}_url",
|
data/lib/omniai/chat.rb
CHANGED
|
@@ -60,18 +60,29 @@ module OmniAI
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
# @param prompt [OmniAI::Chat::Prompt, String, nil] optional
|
|
63
|
-
# @param client [OmniAI::Client]
|
|
63
|
+
# @param client [OmniAI::Client] required
|
|
64
64
|
# @param model [String] required
|
|
65
65
|
# @param temperature [Float, nil] optional
|
|
66
66
|
# @param stream [Proc, IO, nil] optional
|
|
67
|
-
# @param tools [Array<OmniAI::Tool
|
|
67
|
+
# @param tools [Array<OmniAI::Tool>, nil] optional
|
|
68
68
|
# @param format [:json, :text, OmniAI::Schema::Object, nil] optional
|
|
69
|
+
# @param options [Hash] optional (used for vendor specific options)
|
|
69
70
|
#
|
|
70
71
|
# @yield [prompt] optional
|
|
71
72
|
# @yieldparam prompt [OmniAI::Chat::Prompt]
|
|
72
73
|
#
|
|
73
74
|
# @return [OmniAi::Chat]
|
|
74
|
-
def initialize(
|
|
75
|
+
def initialize(
|
|
76
|
+
prompt = nil,
|
|
77
|
+
client:,
|
|
78
|
+
model:,
|
|
79
|
+
temperature: nil,
|
|
80
|
+
stream: nil,
|
|
81
|
+
tools: nil,
|
|
82
|
+
format: nil,
|
|
83
|
+
**options,
|
|
84
|
+
&block
|
|
85
|
+
)
|
|
75
86
|
raise ArgumentError, "prompt or block is required" if !prompt && !block
|
|
76
87
|
|
|
77
88
|
@prompt = prompt ? Prompt.parse(prompt) : Prompt.new
|
|
@@ -83,6 +94,7 @@ module OmniAI
|
|
|
83
94
|
@stream = stream
|
|
84
95
|
@tools = tools
|
|
85
96
|
@format = format
|
|
97
|
+
@options = options || {}
|
|
86
98
|
end
|
|
87
99
|
|
|
88
100
|
# @raise [HTTPError]
|
|
@@ -143,7 +155,8 @@ module OmniAI
|
|
|
143
155
|
temperature: @temperature,
|
|
144
156
|
stream: @stream,
|
|
145
157
|
tools: @tools,
|
|
146
|
-
format: @format
|
|
158
|
+
format: @format,
|
|
159
|
+
options: @options
|
|
147
160
|
)
|
|
148
161
|
end
|
|
149
162
|
|
data/lib/omniai/client.rb
CHANGED
|
@@ -185,18 +185,19 @@ module OmniAI
|
|
|
185
185
|
|
|
186
186
|
# @raise [OmniAI::Error]
|
|
187
187
|
#
|
|
188
|
-
# @param
|
|
189
|
-
# @param model [String] optional
|
|
190
|
-
# @param format [Symbol] optional
|
|
188
|
+
# @param prompt [OmniAI::Chat::Prompt, String, nil] optional
|
|
189
|
+
# @param model [String, nil] optional
|
|
190
|
+
# @param format [Symbol, OmniAI::Schema::Format, nil] optional (e.g. `:text`, `:json`, `OmniAI::Schema.format(...)`)
|
|
191
191
|
# @param temperature [Float, nil] optional
|
|
192
192
|
# @param stream [Proc, nil] optional
|
|
193
193
|
# @param tools [Array<OmniAI::Tool>] optional
|
|
194
|
+
# @param options [Hash, nil] optional
|
|
194
195
|
#
|
|
195
196
|
# @yield [prompt] optional
|
|
196
197
|
# @yieldparam prompt [OmniAI::Chat::Prompt]
|
|
197
198
|
#
|
|
198
199
|
# @return [OmniAI::Chat::Response]
|
|
199
|
-
def chat(
|
|
200
|
+
def chat(prompt = nil, model:, temperature: nil, format: nil, stream: nil, tools: nil, options: {}, &)
|
|
200
201
|
raise NotImplementedError, "#{self.class.name}#chat undefined"
|
|
201
202
|
end
|
|
202
203
|
|
data/lib/omniai/schema/object.rb
CHANGED
data/lib/omniai/version.rb
CHANGED