omniai 0.1.2 → 0.1.4

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: '08e84fed0ec1535369239cec24e1ba320714b006d63c41c70a3fab4ad9b27448'
4
- data.tar.gz: 1b1c8c415873efad649481e9a54b2377e4a1aa3081c1fe17c03615f59d6c82e8
3
+ metadata.gz: 5d90d000047c670a17478146fa35fca9c993127067b01b11113cc46e739d15e2
4
+ data.tar.gz: d025855eb6ea4ae79bc7c126a2853fff7a6a0e21d597fa86b2efb6b8d1c3ddf1
5
5
  SHA512:
6
- metadata.gz: bcebbc73ba9c7fc02aac3c49485bca5c9beea176e53d160fbddfb787442bac4dca7d643b220ee67a156fd9b464af273a8bedcf8201e3120c6671caf5fc9740a8
7
- data.tar.gz: aa4a0d58e825d950b8241dfc1fb1da789a1efa3f81f7b7e67d09f8126696624f4a5d4f34dc50d913001ef1ee4f5b00e71f1ac6a478620aa8e0b38ed60d5f20b5
6
+ metadata.gz: 77247cd74f88fdaa527b377940f32cfaad187c26f8ae4c6f373c708c866ce5c956c0436194786acb474ae07f423ea83511df6bbd5029c91247aff4b5d8ee2891
7
+ data.tar.gz: c7d3a40a6c21fe1827b162e94eae0dd0d2f66014797e4d878fa6c7aacf17c443412fcefa2f4bc0ad008f7b64b41ab4e2d583109990d6418d77451f1ba67b4fbd
data/README.md CHANGED
@@ -60,19 +60,57 @@ client = OmniAI::OpenAI::Client.new
60
60
 
61
61
  ### Chat
62
62
 
63
- Clients that support chat (e.g. Anthropic w/ "Claude", Google w/ "Gemini", Mistral w/ "LeChat", OpenAI w/ "ChatGPT", etc) can generate completions using either a basic or streaming API:
63
+ Clients that support chat (e.g. Anthropic w/ "Claude", Google w/ "Gemini", Mistral w/ "LeChat", OpenAI w/ "ChatGPT", etc) generate completions using the following calls:
64
64
 
65
- #### Basic
65
+ #### w/ a Simple Prompt
66
66
 
67
67
  ```ruby
68
68
  completion = client.chat.completion('Tell me a joke.')
69
69
  puts(completion.choice.message.content) # '...'
70
70
  ```
71
71
 
72
+ #### w/ a Collection of Messages
73
+
74
+ ```ruby
75
+ messages = [
76
+ {
77
+ role: 'system',
78
+ content: 'You are a helpful assistant with an expertise in geography.',
79
+ },
80
+ {
81
+ role: 'user',
82
+ content: 'What is the capital of Canada?',
83
+ },
84
+ ]
85
+ completion = client.chat.completion(messages, model: '...', temperature: 0.7, format: :json)
86
+ puts(completion.choice.message.content) # '...'
87
+ ```
88
+
89
+ #### w/ a Collection of Files
90
+
91
+ ```ruby
92
+
93
+ image_a_url = "https://images.unsplash.com/photo-1517849845537-4d257902454a?w=800&h=800&format=jpeg&fit=crop"
94
+ image_b_url = "https://images.unsplash.com/photo-1537151625747-768eb6cf92b2?q=80&w=1024&h=1024&format=jpeg"
95
+
96
+ message = {
97
+ role: 'user',
98
+ content: [
99
+ OmniAI::Chat::Content.new('What are in these images and are they different?'),
100
+ OmniAI::Chat::Content.new(image_a_url, type: :image),
101
+ OmniAI::Chat::Content.new(image_b_url, type: :image),
102
+ ]
103
+ }
104
+
105
+ completion = client.chat.completion(message)
106
+ puts(completion.choice.message.content) # '...'
107
+ ```
108
+
72
109
  #### Streaming
73
110
 
74
111
  ```ruby
75
- client.chat.completion 'Tell me a joke.', stream: proc do |chunk|
112
+ stream = proc do |chunk|
76
113
  print(chunk.choice.delta.content) # '...'
77
114
  end
115
+ client.chat.completion('Tell me a joke.', stream:)
78
116
  ```
@@ -31,6 +31,11 @@ module OmniAI
31
31
  @data['model']
32
32
  end
33
33
 
34
+ # @return [Array<OmniAI::Chat::Choice>]
35
+ def choices
36
+ @choices ||= @data['choices'].map { |data| Choice.new(data:) }
37
+ end
38
+
34
39
  # @param [index] [Integer]
35
40
  # @return [OmniAI::Chat::Delta]
36
41
  def choice(index: 0)
@@ -38,7 +38,7 @@ module OmniAI
38
38
 
39
39
  # @return [Array<OmniAI::Chat::Choice>]
40
40
  def choices
41
- @choices ||= @data['choices'].map { |choice| Choice.new(data: choice) }
41
+ @choices ||= @data['choices'].map { |data| Choice.new(data:) }
42
42
  end
43
43
 
44
44
  # @param [index] [Integer] optional - default is 0
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class Chat
5
+ # A file used for analysis.
6
+ class Content
7
+ attr_accessor :type, :value
8
+
9
+ # @param url [String]
10
+ # @param text [String]
11
+ # @param type [Symbol] :image / :video / :audio / :text
12
+ def initialize(value, type: :text)
13
+ @value = value
14
+ @type = type
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ module OmniAI
2
+ # A configuration for each agent w/ `api_key` / `host` / `logger`.
3
+ class Config
4
+ attr_accessor :api_key, :host, :logger
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.4'
5
5
  end
data/lib/omniai.rb CHANGED
@@ -16,7 +16,7 @@ module OmniAI
16
16
 
17
17
  # @param response [HTTP::Response]
18
18
  def initialize(response)
19
- super("status=#{response.status.inspect} headers=#{response.headers.inspect} body=#{response.body.inspect}")
19
+ super("status=#{response.status.inspect} headers=#{response.headers.inspect} body=#{response.body}")
20
20
  @response = response
21
21
  end
22
22
  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: 0.1.2
4
+ version: 0.1.4
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-06-12 00:00:00.000000000 Z
11
+ date: 2024-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -69,11 +69,13 @@ files:
69
69
  - lib/omniai/chat/choice.rb
70
70
  - lib/omniai/chat/chunk.rb
71
71
  - lib/omniai/chat/completion.rb
72
+ - lib/omniai/chat/content.rb
72
73
  - lib/omniai/chat/delta.rb
73
74
  - lib/omniai/chat/message.rb
74
75
  - lib/omniai/chat/request.rb
75
76
  - lib/omniai/chat/usage.rb
76
77
  - lib/omniai/client.rb
78
+ - lib/omniai/config.rb
77
79
  - lib/omniai/version.rb
78
80
  homepage: https://github.com/ksylvest/omniai
79
81
  licenses: []