omniai 1.0.6 → 1.0.8

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: 172ad18b8fbe97f2e8d23bf8624efea92591910f6d05eed5295789555f60e6d7
4
- data.tar.gz: dc415cd3f63f293bc2d64cff39c3ee3c094f734d7a0fb330a1b25adf772f7016
3
+ metadata.gz: 1971cb590311266b342596c44ff56398999b8657e9f6cf2b8d2afffb8b91257b
4
+ data.tar.gz: 7866818c3dd9c1af3b03a351ecdc38c527ef1d08bb877533a9f9159bce8d5ed5
5
5
  SHA512:
6
- metadata.gz: 1dc885877d697bf3c2053e8facbdc1a7329a8b3ae0804753e0e1daefcc9f37bcc7dd19de11c748fccdf4cc9be032cbbb1128558a8d437a125ab41ca44402d7ce
7
- data.tar.gz: cb96cde1ff5203f08646217bfae1c0032a25f492cbb6b1565f34ea9a5a905c0626b6bfab5e651793cd853b34eaf0a95130ad8a41e2f8a77429c9faf0feb58cc5
6
+ metadata.gz: 2c93b8a97fc2ca09765e9c2c537c15491a7344cc505e6204addd972dbb2c7ee2219213d2892745df48bdd4c0193bf3d80391142da2462de437290fc3a6d442db
7
+ data.tar.gz: 0b7d13dfde39f89c78a57ea3b03549262fb7b9962d127a01e89ca3785402098b6c0e34fc957145615d279a14f4d644769c25a2d3f833aa9c1136397d6b7384b3
data/Gemfile CHANGED
@@ -11,3 +11,5 @@ gem 'rspec_junit_formatter'
11
11
  gem 'rubocop'
12
12
  gem 'rubocop-rake'
13
13
  gem 'rubocop-rspec'
14
+ gem 'simplecov'
15
+ gem 'webmock'
data/README.md CHANGED
@@ -66,7 +66,7 @@ Clients that support chat (e.g. Anthropic w/ "Claude", Google w/ "Gemini", Mistr
66
66
 
67
67
  ```ruby
68
68
  completion = client.chat('Tell me a joke.')
69
- puts(completion.choice.message.content) # '...'
69
+ completion.choice.message.content # '...'
70
70
  ```
71
71
 
72
72
  #### w/ a Collection of Messages
@@ -77,13 +77,10 @@ messages = [
77
77
  role: 'system',
78
78
  content: 'You are a helpful assistant with an expertise in geography.',
79
79
  },
80
- {
81
- role: 'user',
82
- content: 'What is the capital of Canada?',
83
- },
80
+ 'What is the capital of Canada?'
84
81
  ]
85
82
  completion = client.chat(messages, model: '...', temperature: 0.7, format: :json)
86
- puts(completion.choice.message.content) # '...'
83
+ completion.choice.message.content
87
84
  ```
88
85
 
89
86
  #### w/ a Collection of Files
@@ -103,7 +100,7 @@ message = {
103
100
  }
104
101
 
105
102
  completion = client.chat(message)
106
- puts(completion.choice.message.content) # '...'
103
+ completion.choice.message.content
107
104
  ```
108
105
 
109
106
  #### Streaming
@@ -4,28 +4,23 @@ module OmniAI
4
4
  class Chat
5
5
  # A choice returned by the API.
6
6
  class Choice
7
- attr_accessor :data
7
+ attr_accessor :index, :delta, :message
8
8
 
9
9
  # @param data [Hash]
10
- def initialize(data:)
11
- @data = data
12
- end
13
-
14
- # @return [Integer]
15
- def index
16
- @data['index']
17
- end
10
+ # @return [OmniAI::Chat::Choice]
11
+ def self.for(data:)
12
+ index = data['index']
13
+ delta = Delta.for(data: data['delta']) if data['delta']
14
+ message = Message.for(data: data['message']) if data['message']
18
15
 
19
- # @return [OmniAI::Chat::Delta]
20
- def delta
21
- Delta.new(data: @data['delta']) if @data['delta']
16
+ new(index:, delta:, message:)
22
17
  end
23
18
 
24
- # @return [OmniAI::Chat::Message]
25
- def message
26
- return unless @data['message']
27
-
28
- @message ||= Message.for(role: @data['message'])
19
+ # @param data [Hash]
20
+ def initialize(index:, delta:, message:)
21
+ @index = index
22
+ @delta = delta
23
+ @message = message
29
24
  end
30
25
  end
31
26
  end
@@ -40,7 +40,7 @@ module OmniAI
40
40
 
41
41
  # @return [Array<OmniAI::Chat::Choice>]
42
42
  def choices
43
- @choices ||= @data['choices'].map { |data| Choice.new(data:) }
43
+ @choices ||= @data['choices'].map { |data| Choice.for(data:) }
44
44
  end
45
45
 
46
46
  # @param [index] [Integer] optional - default is 0
@@ -4,22 +4,27 @@ module OmniAI
4
4
  class Chat
5
5
  # A delta returned by the API.
6
6
  class Delta
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, nil]
16
- def role
17
- @data['role']
18
+ # @param content [String]
19
+ # @param role [String]
20
+ def initialize(content:, role: nil)
21
+ @content = content
22
+ @role = role
18
23
  end
19
24
 
20
- # @return [String, nil]
21
- def content
22
- @data['content']
25
+ # @return [String]
26
+ def inspect
27
+ "#<#{self.class.name} role=#{role.inspect} content=#{content.inspect}>"
23
28
  end
24
29
  end
25
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.0.6'
4
+ VERSION = '1.0.8'
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.6
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre