omniai 2.9.2 → 3.0.1

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: 92012d7a509078046f920380845855721e2a27124604d65a27b5e6eaeb8b66b0
4
- data.tar.gz: 2a2bcd66dbf8a9f86932ecec620bd30933e19d31c4c87ff6767db6ae4facaecf
3
+ metadata.gz: d531aa6fb65bf379e80e1ee381a9e0bcdc593ff50368023284516b1d63c12d2e
4
+ data.tar.gz: cfb766bb5a41be87fa2a24766f1a14ce03fb48bda3aeb5bf747f6f6d23cecc55
5
5
  SHA512:
6
- metadata.gz: 21e52fdd7d754e1c2d1e358d7180a99a3ac12caed8cc26d35b241f73fec6974df07385e60a24b20b836707fb78af916fa3bfe1a9b5588ca2497e6c1df783ab1b
7
- data.tar.gz: f8d2d079bc66b84c242d222825675d9dc5bd74aee4dc7ac1371dd54b5e9a3c971801bb996cb49bb40332407b961695806d791161b0f04da353f0d7cd00d87aba
6
+ metadata.gz: 4128c986161424706af7cdd57ef1d2a23541761cebd94e798e15fcd5959d8e55b79c7c7bac3aa7a69efe6c65ebb24b47154f37077a28cc233f22e0ec7c7af1f9
7
+ data.tar.gz: e4d043eb1ca554d3da937b0a72b45ef659125f7d7e52adc855ffa4ee446f2735a3981f00e361fc75c55573bfc72e46c98403d459acc7b732579fe06f2bdaa658
@@ -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
 
@@ -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
@@ -157,6 +157,14 @@ module OmniAI
157
157
 
158
158
  [object]
159
159
  end
160
+
161
+ # @return [String] either "input" or "output"
162
+ def direction
163
+ case role
164
+ when Role::ASSISTANT then "output"
165
+ else "input"
166
+ end
167
+ end
160
168
  end
161
169
  end
162
170
  end
@@ -102,18 +102,17 @@ module OmniAI
102
102
  !message.nil? && message.text?
103
103
  end
104
104
 
105
- # @param index [Integer]
106
- #
107
- # @return [ToolCallList]
108
- def tool_call_list(index: 0)
109
- message(index:)&.tool_call_list
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?(index: 0)
114
- tool_call_list = tool_call_list(index:)
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
@@ -23,7 +23,8 @@ module OmniAI
23
23
  @text
24
24
  end
25
25
 
26
- # @param data [Hash]
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: :user, content: 'Hello!' }
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
  #
@@ -26,7 +26,8 @@ module OmniAI
26
26
  "#<#{self.class} uri=#{@uri.inspect}>"
27
27
  end
28
28
 
29
- # @param data [Hash]
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,22 +60,29 @@ module OmniAI
60
60
  end
61
61
 
62
62
  # @param prompt [OmniAI::Chat::Prompt, String, nil] optional
63
- # @param client [OmniAI::Client] the 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>] optional
67
+ # @param tools [Array<OmniAI::Tool>, nil] optional
68
68
  # @param format [:json, :text, OmniAI::Schema::Object, nil] optional
69
- # @param reasoning [Hash, nil] optional reasoning configuration (provider-specific)
70
- # @param verbosity [Hash, nil] optional verbosity configuration (provider-specific)
71
- # @param kwargs [Hash] additional provider-specific options
69
+ # @param options [Hash] optional (used for vendor specific options)
72
70
  #
73
71
  # @yield [prompt] optional
74
72
  # @yieldparam prompt [OmniAI::Chat::Prompt]
75
73
  #
76
74
  # @return [OmniAi::Chat]
77
- def initialize(prompt = nil, client:, model:, temperature: nil, stream: nil, tools: nil, format: nil,
78
- reasoning: nil, verbosity: nil, **kwargs, &block)
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
+ )
79
86
  raise ArgumentError, "prompt or block is required" if !prompt && !block
80
87
 
81
88
  @prompt = prompt ? Prompt.parse(prompt) : Prompt.new
@@ -87,9 +94,7 @@ module OmniAI
87
94
  @stream = stream
88
95
  @tools = tools
89
96
  @format = format
90
- @reasoning = reasoning
91
- @verbosity = verbosity
92
- @kwargs = kwargs
97
+ @options = options || {}
93
98
  end
94
99
 
95
100
  # @raise [HTTPError]
@@ -151,9 +156,7 @@ module OmniAI
151
156
  stream: @stream,
152
157
  tools: @tools,
153
158
  format: @format,
154
- reasoning: @reasoning,
155
- verbosity: @verbosity,
156
- **@kwargs
159
+ options: @options
157
160
  )
158
161
  end
159
162
 
data/lib/omniai/client.rb CHANGED
@@ -185,18 +185,19 @@ module OmniAI
185
185
 
186
186
  # @raise [OmniAI::Error]
187
187
  #
188
- # @param messages [String] optional
189
- # @param model [String] optional
190
- # @param format [Symbol] optional :text or :json
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(messages = nil, model:, temperature: nil, format: nil, stream: nil, tools: nil, &)
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
 
@@ -71,12 +71,14 @@ module OmniAI
71
71
  # @example
72
72
  # array.serialize # => { type: "array", items: { type: "string" } }
73
73
  #
74
+ # @param options [Hash] 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 options [Hash] optional (e.g. `{ additional_properties: nil }``)
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,14 +74,17 @@ module OmniAI
74
74
  )
75
75
  end
76
76
 
77
+ # @param options [Hash] 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,
87
+ additionalProperties: additional_properties,
85
88
  }.compact
86
89
  end
87
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 = "2.9.2"
4
+ VERSION = "3.0.1"
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: 2.9.2
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre