omniai 1.0.3 → 1.0.5

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: 9ef66e140869ad45643072513852d7ed06439fb6a7fecda4f552ecb34c14ddb1
4
- data.tar.gz: 55740c3bdc98c9d83330b1a45b1b83d760b279d388830e83fce8a671f635d26d
3
+ metadata.gz: dddfc4d4ac08e936e1b2443e37ff93b4256428579aa1280b6ede769a01365f04
4
+ data.tar.gz: 235c5f109e0e3526d2abfa2cf7d6c3a3d1e00749da70beaf884a2a1bcb9ba8c6
5
5
  SHA512:
6
- metadata.gz: f335ee44a2460431d3f7bf83991448569f451930102ba1d3714c79af225db08d22467269c1543434a987de2d0f70bbe33faece99c4f291cc67032e7a5121721b
7
- data.tar.gz: 33ca9dbf52c1a7af1c60683db4fd31680f4e3230da6c139591c6c62796616767b67109862963d8b1b7b93c6af46143e140471a606b20f0a6457b3f1989c87030
6
+ metadata.gz: fae66992c4f0a399ecbe795a39901e73caea1554861e23894fd005daab9b26e23cd6a110cca9cde9b9c9ce73af174037626b3505074bb4bd23477677a286b3ef
7
+ data.tar.gz: 5f604bcdc4ca4b748e523eff6cb4b383cd9211188673c768d2295a7f9e43c1f043ac9c8b14ff86b9dabb85a99b50a005ce40b920cdbcdf19f9f1ef05b4f33ca5
@@ -23,7 +23,9 @@ module OmniAI
23
23
 
24
24
  # @return [OmniAI::Chat::Message]
25
25
  def message
26
- Message.new(data: @data['message']) if @data['message']
26
+ return unless @data['message']
27
+
28
+ @message ||= Message.for(role: @data['message'])
27
29
  end
28
30
  end
29
31
  end
@@ -35,15 +35,7 @@ module OmniAI
35
35
  def usage
36
36
  return unless @data['usage']
37
37
 
38
- input_tokens = @data['usage']['input_tokens'] || @data['usage']['prompt_tokens']
39
- output_tokens = @data['usage']['output_tokens'] || @data['usage']['completion_tokens']
40
- total_tokens = @data['usage']['total_tokens'] || (input_tokens + output_tokens)
41
-
42
- @usage ||= Usage.new(
43
- input_tokens:,
44
- output_tokens:,
45
- total_tokens:
46
- )
38
+ @usage ||= Usage.for(data: @data['usage'])
47
39
  end
48
40
 
49
41
  # @return [Array<OmniAI::Chat::Choice>]
@@ -4,22 +4,27 @@ module OmniAI
4
4
  class Chat
5
5
  # A message returned by the API.
6
6
  class Message
7
- attr_accessor :data
7
+ attr_accessor :role, :content
8
8
 
9
- # @param content [Integer]
10
- # @param role [String]
11
- def initialize(data:)
12
- @data = data
9
+ # @param data [Hash]
10
+ # @return [OmniAI::Chat::Message]
11
+ def self.for(data:)
12
+ content = data['content'] || data[:content]
13
+ role = data['role'] || data[:role]
14
+
15
+ new(content:, role: role || Role::USER)
13
16
  end
14
17
 
15
- # @return [String]
16
- def role
17
- @data['role']
18
+ # @param content [String]
19
+ # @param role [String] optional (default to "user") e.g. "assistant" / "user" / "system"
20
+ def initialize(content:, role: OmniAI::Chat::Role::USER)
21
+ @role = role
22
+ @content = content
18
23
  end
19
24
 
20
25
  # @return [String]
21
- def content
22
- @data['content']
26
+ def inspect
27
+ "#<#{self.class.name} role=#{role.inspect} content=#{content.inspect}>"
23
28
  end
24
29
  end
25
30
  end
@@ -6,6 +6,20 @@ module OmniAI
6
6
  class Usage
7
7
  attr_accessor :input_tokens, :output_tokens, :total_tokens
8
8
 
9
+ # @param data [Hash]
10
+ # @return [OmniAI::Chat::Usage]
11
+ def self.for(data:)
12
+ input_tokens = data['input_tokens'] || data['prompt_tokens']
13
+ output_tokens = data['output_tokens'] || data['completion_tokens']
14
+ total_tokens = data['total_tokens'] || (input_tokens + output_tokens)
15
+
16
+ new(
17
+ input_tokens:,
18
+ output_tokens:,
19
+ total_tokens:
20
+ )
21
+ end
22
+
9
23
  # @param input_tokens [Integer]
10
24
  # @param output_tokens [Integer]
11
25
  # @param total_tokens [Integer]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.5'
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: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre