omniai 1.5.0 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c05ed0777b6e88c023738b43e5188d722ca9bf372a7cabda61a800ae5a7a13a7
4
- data.tar.gz: e2f0220221030ce99bc81dfd456a7505bce557594ba03336d5445ff4a7188b7d
3
+ metadata.gz: 81c34e7c05b90e85fe99ba87f0b462f4322a0dd14c74afdb5f951faccdc698d6
4
+ data.tar.gz: 551b238e17c909abbe3b08ecf630a2f6aa0047a17413c7966d23ca9ccbf0d26d
5
5
  SHA512:
6
- metadata.gz: 9ec41c146e0052129894ad17fdcbd8768b96d76114f85604098153c901a842b4d59cc78121ad5e77a7a7501c17c3caf060ed2bcf4c05fea3523fc8c081f8479b
7
- data.tar.gz: 11c641f64597f09bff8d67dd00b5599701868c7b31bbb12675191cd554e94b051c97e6f7251e355dcf849b9693f34dc0f29c8b8b0ac92a77fa0ff00ca6c2d05e
6
+ metadata.gz: 0c291e2840cd9782046d7011e7becc77b2d9c64da427d6785ed121ae430a4153f7fb3d6f28f4f4c9cb943f18a0b8d7c20e345fc8c6d0097faa83eb205a302132
7
+ data.tar.gz: d592b529340cacdcf458295a9914589806f6c568469c0c9548cdbd63fa639d64dcb04982dc2f7f68506e2207809a2b1b689b6267dabe262f3847c298785f5ba7
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # For use with MessageChoice or DeltaChoice.
7
+ class Choice < Resource
8
+ # @return [Integer]
9
+ def index
10
+ @data['index']
11
+ end
12
+
13
+ # @return [OmniAI::Chat::Response::Part]
14
+ def part
15
+ raise NotImplementedError, "#{self.class.name}#part undefined"
16
+ end
17
+
18
+ # @return [OmniAI::Chat::Response::ToolCallList]
19
+ def tool_call_list
20
+ part.tool_call_list
21
+ end
22
+
23
+ # @return [String, nil]
24
+ def content
25
+ part.content
26
+ end
27
+
28
+ # @return [Boolean]
29
+ def content?
30
+ !content.nil?
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A chunk returned by the API.
7
+ class Chunk < Payload
8
+ # @return [Array<OmniAI::Chat::Response::DeltaChoice>]
9
+ def choices
10
+ @choices ||= @data['choices'].map { |data| DeltaChoice.new(data:) }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A completion returned by the API.
7
+ class Completion < Payload
8
+ # @return [Array<OmniAI::Chat:Response:::MessageChoice>]
9
+ def choices
10
+ @choices ||= @data['choices'].map { |data| MessageChoice.new(data:) }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A delta returned by the API.
7
+ class Delta < Part
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A delta choice returned by the API.
7
+ class DeltaChoice < Choice
8
+ # @return [String]
9
+ def inspect
10
+ "#<#{self.class.name} index=#{index} delta=#{delta.inspect}>"
11
+ end
12
+
13
+ # @return [OmniAI::Chat::Response::Delta]
14
+ def delta
15
+ @delta ||= Delta.new(data: @data['delta'])
16
+ end
17
+
18
+ # @return [OmniAI::Chat::Response::Delta]
19
+ def part
20
+ delta
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A function returned by the API.
7
+ class Function < Resource
8
+ # @return [String]
9
+ def inspect
10
+ "#<#{self.class.name} name=#{name.inspect} arguments=#{arguments.inspect}>"
11
+ end
12
+
13
+ # @return [String]
14
+ def name
15
+ @data['name']
16
+ end
17
+
18
+ # @return [Hash, nil]
19
+ def arguments
20
+ JSON.parse(@data['arguments']) if @data['arguments']
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A message returned by the API.
7
+ class Message < Part
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A choice returned by the API.
7
+ class MessageChoice < Choice
8
+ # @return [String]
9
+ def inspect
10
+ "#<#{self.class.name} index=#{index} message=#{message.inspect}>"
11
+ end
12
+
13
+ # @return [OmniAI::Chat::Response::Message]
14
+ def message
15
+ @message ||= Message.new(data: @data['message'])
16
+ end
17
+
18
+ # @return [OmniAI::Chat::Response::Message]
19
+ def part
20
+ message
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # Either a delta or message.
7
+ class Part < Resource
8
+ # @return [String]
9
+ def inspect
10
+ "#<#{self.class.name} role=#{role.inspect} content=#{content.inspect}>"
11
+ end
12
+
13
+ # @return [String]
14
+ def role
15
+ @data['role'] || Role::USER
16
+ end
17
+
18
+ # @return [String, nil]
19
+ def content
20
+ @data['content']
21
+ end
22
+
23
+ # @return [Array<OmniAI::Chat::Response::ToolCall>]
24
+ def tool_call_list
25
+ return [] unless @data['tool_calls']
26
+
27
+ @tool_call_list ||= @data['tool_calls'].map { |tool_call_data| ToolCall.new(data: tool_call_data) }
28
+ end
29
+
30
+ # @param index [Integer]
31
+ # @return [OmniAI::Chat::Response::ToolCall, nil]
32
+ def tool_call(index: 0)
33
+ tool_call_list[index]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A chunk or completion.
7
+ class Payload < Resource
8
+ # @return [String]
9
+ def inspect
10
+ "#<#{self.class.name} id=#{id.inspect} choices=#{choices.inspect}>"
11
+ end
12
+
13
+ # @return [String]
14
+ def id
15
+ @data['id']
16
+ end
17
+
18
+ # @return [Time]
19
+ def created
20
+ Time.at(@data['created']) if @data['created']
21
+ end
22
+
23
+ # @return [Time]
24
+ def updated
25
+ Time.at(@data['updated']) if @data['updated']
26
+ end
27
+
28
+ # @return [String]
29
+ def model
30
+ @data['model']
31
+ end
32
+
33
+ # @return [Array<OmniAI::Chat::Response::Choice>]
34
+ def choices
35
+ raise NotImplementedError, "#{self.class.name}#choices undefined"
36
+ end
37
+
38
+ # @param index [Integer]
39
+ # @return [OmniAI::Chat::Response::DeltaChoice]
40
+ def choice(index: 0)
41
+ choices[index]
42
+ end
43
+
44
+ # @param index [Integer]
45
+ # @return [OmniAI::Chat::Response::Part]
46
+ def part(index: 0)
47
+ choice(index:).part
48
+ end
49
+
50
+ # @return [OmniAI::Chat::Response::Usage]
51
+ def usage
52
+ @usage ||= Usage.new(data: @data['usage']) if @data['usage']
53
+ end
54
+
55
+ # @return [String, nil]
56
+ def content
57
+ choice.content
58
+ end
59
+
60
+ # @return [Boolean]
61
+ def content?
62
+ choice.content?
63
+ end
64
+
65
+ # @return [Array<OmniAI::Chat::Response:ToolCall>]
66
+ def tool_call_list
67
+ choice.tool_call_list
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A generic data to handle response.
7
+ class Resource
8
+ attr_accessor :data
9
+
10
+ # @param data [Hash]
11
+ def initialize(data:)
12
+ @data = data
13
+ end
14
+
15
+ # @return [String]
16
+ def inspect
17
+ "#<#{self.class.name} data=#{@data.inspect}>"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A stream given when streaming.
7
+ class Stream
8
+ # @param response [HTTP::Response]
9
+ def initialize(response:)
10
+ @response = response
11
+ @parser = EventStreamParser::Parser.new
12
+ end
13
+
14
+ # @yield [OmniAI::Chat::Chunk]
15
+ def stream!
16
+ @response.body.each do |chunk|
17
+ @parser.feed(chunk) do |_, data|
18
+ next if data.eql?('[DONE]')
19
+
20
+ yield(Chunk.new(data: JSON.parse(data)))
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A tool-call returned by the API.
7
+ class ToolCall < Resource
8
+ # @return [String]
9
+ def inspect
10
+ "#<#{self.class.name} id=#{id.inspect} type=#{type.inspect}>"
11
+ end
12
+
13
+ # @return [String]
14
+ def id
15
+ @data['id']
16
+ end
17
+
18
+ # @return [String]
19
+ def type
20
+ @data['type']
21
+ end
22
+
23
+ # @return [OmniAI::Chat::Response::Function]
24
+ def function
25
+ @function ||= Function.new(data: @data['function']) if @data['function']
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ module Response
6
+ # A usage returned by the API.
7
+ class Usage < Resource
8
+ # @return [String]
9
+ def inspect
10
+ properties = [
11
+ "input_tokens=#{input_tokens}",
12
+ "output_tokens=#{output_tokens}",
13
+ "total_tokens=#{total_tokens}",
14
+ ]
15
+ "#<#{self.class.name} #{properties.join(' ')}>"
16
+ end
17
+
18
+ # @return [Integer]
19
+ def input_tokens
20
+ @data['input_tokens'] || @data['prompt_tokens']
21
+ end
22
+
23
+ # @return [Integer]
24
+ def output_tokens
25
+ @data['output_tokens'] || @data['completion_tokens']
26
+ end
27
+
28
+ # @return [Integer]
29
+ def total_tokens
30
+ @data['total_tokens'] || (input_tokens + output_tokens)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
data/lib/omniai/chat.rb CHANGED
@@ -98,12 +98,12 @@ module OmniAI
98
98
  end
99
99
  end
100
100
 
101
- # @param response [OmniAI::Chat::Completion]
102
- # @return [OmniAI::Chat::Completion]
101
+ # @param response [HTTP::Response]
102
+ # @return [OmniAI::Chat::Response::Completion]
103
103
  def complete!(response:)
104
- completion = self.class::Completion.new(data: response.parse)
104
+ completion = self.class::Response::Completion.new(data: response.parse)
105
105
 
106
- if @tools && completion.tool_call_required?
106
+ if @tools && completion.tool_call_list.any?
107
107
  @messages = [
108
108
  *@messages,
109
109
  *completion.choices.map(&:message).map(&:data),
@@ -120,11 +120,13 @@ module OmniAI
120
120
  def stream!(response:)
121
121
  raise Error, "#{self.class.name}#stream! unstreamable" unless @stream
122
122
 
123
- self.class::Stream.new(response:).stream! do |chunk|
123
+ self.class::Response::Stream.new(response:).stream! do |chunk|
124
124
  case @stream
125
125
  when IO, StringIO
126
- @stream << chunk.choice.delta.content
127
- @stream.flush
126
+ if chunk.content?
127
+ @stream << chunk.content
128
+ @stream.flush
129
+ end
128
130
  else @stream.call(chunk)
129
131
  end
130
132
  end
data/lib/omniai/config.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- # A configuration for each agent w/ `api_key` / `host` / `logger`. Usage:
4
+ # A configuration for each agent w/ `api_key` / `host` / `logger`.
5
+ #
6
+ # Usage:
5
7
  #
6
8
  # OmniAI::OpenAI.config do |config|
7
9
  # config.api_key = '...'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.5.0'
4
+ VERSION = '1.5.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-11 00:00:00.000000000 Z
11
+ date: 2024-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -68,20 +68,24 @@ files:
68
68
  - exe/omniai
69
69
  - lib/omniai.rb
70
70
  - lib/omniai/chat.rb
71
- - lib/omniai/chat/chunk.rb
72
- - lib/omniai/chat/completion.rb
73
71
  - lib/omniai/chat/content/file.rb
74
72
  - lib/omniai/chat/content/media.rb
75
73
  - lib/omniai/chat/content/text.rb
76
74
  - lib/omniai/chat/content/url.rb
77
- - lib/omniai/chat/delta.rb
78
- - lib/omniai/chat/delta_choice.rb
79
- - lib/omniai/chat/function.rb
80
- - lib/omniai/chat/message.rb
81
- - lib/omniai/chat/message_choice.rb
82
- - lib/omniai/chat/stream.rb
83
- - lib/omniai/chat/tool_call.rb
84
- - lib/omniai/chat/usage.rb
75
+ - lib/omniai/chat/response/choice.rb
76
+ - lib/omniai/chat/response/chunk.rb
77
+ - lib/omniai/chat/response/completion.rb
78
+ - lib/omniai/chat/response/delta.rb
79
+ - lib/omniai/chat/response/delta_choice.rb
80
+ - lib/omniai/chat/response/function.rb
81
+ - lib/omniai/chat/response/message.rb
82
+ - lib/omniai/chat/response/message_choice.rb
83
+ - lib/omniai/chat/response/part.rb
84
+ - lib/omniai/chat/response/payload.rb
85
+ - lib/omniai/chat/response/resource.rb
86
+ - lib/omniai/chat/response/stream.rb
87
+ - lib/omniai/chat/response/tool_call.rb
88
+ - lib/omniai/chat/response/usage.rb
85
89
  - lib/omniai/cli.rb
86
90
  - lib/omniai/cli/base_handler.rb
87
91
  - lib/omniai/cli/chat_handler.rb
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A chunk returned by the API.
6
- class Chunk
7
- attr_accessor :data
8
-
9
- # @param data [Hash]
10
- def initialize(data:)
11
- @data = data
12
- end
13
-
14
- # @return [String]
15
- def id
16
- @data['id']
17
- end
18
-
19
- # @return [Time]
20
- def created
21
- Time.at(@data['created']) if @data['created']
22
- end
23
-
24
- # @return [Time]
25
- def updated
26
- Time.at(@data['updated']) if @data['updated']
27
- end
28
-
29
- # @return [String]
30
- def model
31
- @data['model']
32
- end
33
-
34
- # @return [Array<OmniAI::Chat::DeltaChoice>]
35
- def choices
36
- @choices ||= @data['choices'].map { |data| DeltaChoice.new(data:) }
37
- end
38
-
39
- # @param index [Integer]
40
- # @return [OmniAI::Chat::Delta]
41
- def choice(index: 0)
42
- choices[index]
43
- end
44
- end
45
- end
46
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A completion returned by the API.
6
- class Completion
7
- attr_accessor :data
8
-
9
- # @param data [Hash]
10
- def initialize(data:)
11
- @data = data
12
- end
13
-
14
- # @return [String]
15
- def inspect
16
- "#<#{self.class.name} id=#{id.inspect} choices=#{choices.inspect}"
17
- end
18
-
19
- # @return [String]
20
- def id
21
- @data['id']
22
- end
23
-
24
- # @return [Time]
25
- def created
26
- Time.at(@data['created']) if @data['created']
27
- end
28
-
29
- # @return [Time]
30
- def updated
31
- Time.at(@data['updated']) if @data['updated']
32
- end
33
-
34
- # @return [String]
35
- def model
36
- @data['model']
37
- end
38
-
39
- # @return [OmniAI::Chat::Usage]
40
- def usage
41
- @usage ||= Usage.new(data: @data['usage']) if @data['usage']
42
- end
43
-
44
- # @return [Array<OmniAI::Chat::MessageChoice>]
45
- def choices
46
- @choices ||= @data['choices'].map { |data| MessageChoice.new(data:) }
47
- end
48
-
49
- # @param index [Integer] optional - default is 0
50
- # @return [OmniAI::Chat::MessageChoice]
51
- def choice(index: 0)
52
- choices[index]
53
- end
54
-
55
- # @return [Boolean]
56
- def tool_call_required?
57
- choices.any? { |choice| choice.message.tool_call_list.any? }
58
- end
59
-
60
- # @return [Array<OmniAI::Chat::ToolCall>]
61
- def tool_call_list
62
- list = []
63
- choices.each do |choice|
64
- list += choice.message.tool_call_list
65
- end
66
- list
67
- end
68
- end
69
- end
70
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A delta returned by the API.
6
- class Delta
7
- # @param data [Hash]
8
- def initialize(data:)
9
- @data = data
10
- end
11
-
12
- # @return [String]
13
- def inspect
14
- "#<#{self.class.name} role=#{role.inspect} content=#{content.inspect}>"
15
- end
16
-
17
- # @return [String, nil]
18
- def content
19
- @data['content']
20
- end
21
-
22
- # @return [String]
23
- def role
24
- @data['role'] || Role::USER
25
- end
26
- end
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A delta choice returned by the API.
6
- class DeltaChoice
7
- # @param data [Hash]
8
- def initialize(data:)
9
- @data = data
10
- end
11
-
12
- # @return [Integer]
13
- def index
14
- @data['index']
15
- end
16
-
17
- # @return [OmniAI::Chat::Delta]
18
- def delta
19
- @delta ||= Delta.new(data: @data['delta'])
20
- end
21
-
22
- # @return [String]
23
- def inspect
24
- "#<#{self.class.name} index=#{index} delta=#{delta.inspect}>"
25
- end
26
- end
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A function returned by the API.
6
- class Function
7
- # @param data [Hash]
8
- def initialize(data:)
9
- @data = data
10
- end
11
-
12
- # @return [String]
13
- def name
14
- @data['name']
15
- end
16
-
17
- # @return [Hash, nil]
18
- def arguments
19
- JSON.parse(@data['arguments']) if @data['arguments']
20
- end
21
-
22
- # @return [String]
23
- def inspect
24
- "#<#{self.class.name} name=#{name.inspect} arguments=#{arguments.inspect}>"
25
- end
26
- end
27
- end
28
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A message returned by the API.
6
- class Message
7
- # @return [Hash]
8
- attr_accessor :data
9
-
10
- # @param data [Hash]
11
- def initialize(data:)
12
- @data = data
13
- end
14
-
15
- # @return [String]
16
- def inspect
17
- "#<#{self.class.name} role=#{role.inspect} content=#{content.inspect}>"
18
- end
19
-
20
- # @return [String]
21
- def role
22
- @data['role'] || Role::USER
23
- end
24
-
25
- # @return [String, nil]
26
- def content
27
- @data['content']
28
- end
29
-
30
- # @return [Array<OmniAI::Chat::ToolCall>]
31
- def tool_call_list
32
- @tool_call_list ||=
33
- @data['tool_calls'] ? @data['tool_calls'].map { |tool_call_data| ToolCall.new(data: tool_call_data) } : []
34
- end
35
- end
36
- end
37
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A choice returned by the API.
6
- class MessageChoice
7
- # @param data [Hash]
8
- def initialize(data:)
9
- @data = data
10
- end
11
-
12
- # @return [Integer]
13
- def index
14
- @data['index']
15
- end
16
-
17
- # @return [OmniAI::Chat::Message]
18
- def message
19
- @message ||= Message.new(data: @data['message'])
20
- end
21
-
22
- # @return [String]
23
- def inspect
24
- "#<#{self.class.name} index=#{index} message=#{message.inspect}>"
25
- end
26
- end
27
- end
28
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A stream given when streaming.
6
- class Stream
7
- # @param response [HTTP::Response]
8
- def initialize(response:)
9
- @response = response
10
- @parser = EventStreamParser::Parser.new
11
- end
12
-
13
- # @yield [OmniAI::Chat::Chunk]
14
- def stream!
15
- @response.body.each do |chunk|
16
- @parser.feed(chunk) do |_, data|
17
- next if data.eql?('[DONE]')
18
-
19
- yield(Chunk.new(data: JSON.parse(data)))
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A tool-call returned by the API.
6
- class ToolCall
7
- # @param data [Hash]
8
- def initialize(data:)
9
- @data = data
10
- end
11
-
12
- # @return [String]
13
- def id
14
- @data['id']
15
- end
16
-
17
- # @return [String]
18
- def type
19
- @data['type']
20
- end
21
-
22
- # @return [OmniAI::Chat::Function]
23
- def function
24
- @function ||= Function.new(data: @data['function']) if @data['function']
25
- end
26
-
27
- # @return [String]
28
- def inspect
29
- "#<#{self.class.name} id=#{id.inspect} type=#{type.inspect}>"
30
- end
31
- end
32
- end
33
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A usage returned by the API.
6
- class Usage
7
- attr_accessor :data
8
-
9
- # @param data [Hash]
10
- def initialize(data:)
11
- @data = data
12
- end
13
-
14
- # @return [Integer]
15
- def input_tokens
16
- @data['input_tokens'] || @data['prompt_tokens']
17
- end
18
-
19
- # @return [Integer]
20
- def output_tokens
21
- @data['output_tokens'] || @data['completion_tokens']
22
- end
23
-
24
- def total_tokens
25
- @data['total_tokens'] || (input_tokens + output_tokens)
26
- end
27
-
28
- # @return [String]
29
- def inspect
30
- "#<#{self.class.name} input_tokens=#{input_tokens} output_tokens=#{output_tokens} total_tokens=#{total_tokens}>"
31
- end
32
- end
33
- end
34
- end