omniai 2.4.2 → 2.5.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: 4bc8ae7e913581cbec89c7942594654b86902edf17ff08ecd531cb14b9edaeb9
4
- data.tar.gz: 53dfc81815745d635a000e24c74c88b2fed6bdde42fe6aa80155995506fe055c
3
+ metadata.gz: 89f3eb0b1c62e35bc437833ad64c2c48504ead7bab049b1fc13cbdde30f5c6fe
4
+ data.tar.gz: bd8f3e7692996e622e245bd82f4fccc86df703836062d9542d59ec8119e09fe7
5
5
  SHA512:
6
- metadata.gz: 5768837dd4a72433a385b7f59b851c7f29d6dc8cc0f09bcdcbbe305e8e35eda3a2c0bca7e2c06ad29133def22e588b8d3a1a7ab0f5fe65dcc38c3707759e0d6f
7
- data.tar.gz: 69628cb125a5fa86b752277b3403ed54ff4008fb37b0a6ff20ea5818eb51ea5509ada51ab814f4e1c2d8654312053b192a2614a2f9f7db8eacc000410af6fc00
6
+ metadata.gz: eb4748a2dc375e1e36dc096605adacd9822e9f7217ffb5a5c0516bbd21f18228dfdcc329346308ccc9b7a114bc24ee2a5abf04e3c09e06ee50cceac72f8f6d09
7
+ data.tar.gz: 6c814845c8fed1e20a042abe94c9ba74227f671a00b9551c79b1b12faedac2a7a998e9a325c942e8b07bdc1ebe55f62ef13563eb982b07ef27b9046695b00295
@@ -4,13 +4,15 @@ module OmniAI
4
4
  class Chat
5
5
  # The result of a tool call.
6
6
  class ToolCallResult
7
- # @return [Object]
7
+ # @!attribute [rw] content
8
+ # @return [Object]
8
9
  attr_accessor :content
9
10
 
10
- # @return [ToolCall]
11
+ # @!attribute [rw] tool_call_id
12
+ # @return [ToolCall]
11
13
  attr_accessor :tool_call_id
12
14
 
13
- # @param content [Object]
15
+ # @param content [Object] e.g. a string, hash, array, boolean, numeric, etc.
14
16
  # @param tool_call_id [String]
15
17
  def initialize(content:, tool_call_id:)
16
18
  @content = content
@@ -22,13 +24,23 @@ module OmniAI
22
24
  "#<#{self.class.name} content=#{content.inspect} tool_call_id=#{tool_call_id.inspect}>"
23
25
  end
24
26
 
27
+ # Converts the content of a tool call result to JSON unless the result is a string.
28
+ #
29
+ # @return [String, nil]
30
+ def text
31
+ return content if content.nil? || content.is_a?(String)
32
+
33
+ JSON.generate(@content)
34
+ end
35
+
25
36
  # @param context [Context] optional
37
+ #
26
38
  # @return [Hash]
27
39
  def serialize(context: nil)
28
40
  serializer = context&.serializer(:tool_call_result)
29
41
  return serializer.call(self, context:) if serializer
30
42
 
31
- content = JSON.generate(@content)
43
+ content = text
32
44
  tool_call_id = @tool_call_id
33
45
 
34
46
  { content:, tool_call_id: }
@@ -36,12 +48,13 @@ module OmniAI
36
48
 
37
49
  # @param data [Hash]
38
50
  # @param context [Context] optional
51
+ #
39
52
  # @return [ToolCallResult]
40
53
  def self.deserialize(data, context: nil)
41
54
  deserialize = context&.deserializer(:tool_call_result)
42
55
  return deserialize.call(data, context:) if deserialize
43
56
 
44
- content = JSON.parse(data["content"])
57
+ content = data["content"]
45
58
  tool_call_id = data["tool_call_id"]
46
59
 
47
60
  new(content:, tool_call_id:)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = "2.4.2"
4
+ VERSION = "2.5.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: 2.4.2
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre