omniai 0.1.3 → 0.1.5

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: 7214249d8bda8299971c31dace84132a52f64b1464ff4d28af27f4a0f93221f8
4
- data.tar.gz: c52f1ef0038da9fc26901f1838d2497e26febcf564548101a96acf03c49c6aa4
3
+ metadata.gz: 4e387dddb26068bab8b4aa35a8e990d6db7aed7f034ae4593105b680282e5d43
4
+ data.tar.gz: 20f9b49d315dea539937521507058a16b8d6f8b0aaeea26f1b6be2cacf07122c
5
5
  SHA512:
6
- metadata.gz: a922ecde2f712428565fa4b0f4544c26249f9c0a85f5801c2b4029d15650d80edca3fae70fb81356c5c66ddce681ffca544c77d3255ac02c335071d9a5b7db4b
7
- data.tar.gz: 53756ecbb1aa2cdbad35c36f9f8b25803e7065661ab2e02716f28f44d7cab3dd9e253bcf6d1fc94dcfaa8d57a27b5f25ed8447c3e50b9d884d1d08fae72ddc75
6
+ metadata.gz: 8c3f503fe81921c2d690f169bc22d3d55b00b590920dc31c47c625a93dd142c995e369a9ffa3675c82bf7d04d3861e3b6e09b98b6e3afbd72bfed91b606e8473
7
+ data.tar.gz: 443d264b0f4c39058fd759b379e604cb631435334fff5fe7528b06cf8502af40c2fbfdca86300e5135029e90ab6104bb0c2b86e5198bd69fcd9c8071e6fbc07a
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
  ```
@@ -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
@@ -6,7 +6,7 @@ module OmniAI
6
6
  #
7
7
  # Usage:
8
8
  #
9
- # class OmniAI::OpenAI::ChatGPT::Completion < OmniAI::Chat::Completion
9
+ # class OmniAI::OpenAI::ChatGPT::Request < OmniAI::Chat::Request
10
10
  # module Model
11
11
  # CHAT = "davinci"
12
12
  # end
@@ -23,7 +23,7 @@ module OmniAI
23
23
  # @param model [String] required
24
24
  # @param temperature [Float, nil] optional
25
25
  # @param stream [Proc, nil] optional
26
- # @param format [Symbol, nil] optional - :text or :json
26
+ # @param format [Symbol, nil] optional - :json
27
27
  def initialize(client:, messages:, model:, temperature: nil, stream: nil, format: nil)
28
28
  @client = client
29
29
  @messages = messages
@@ -44,12 +44,12 @@ module OmniAI
44
44
  protected
45
45
 
46
46
  # @param response [HTTP::Response]
47
- # @return [OmniAI::Chat::Completion::Response]
47
+ # @return [OmniAI::Chat::Completion]
48
48
  def parse!(response:)
49
49
  if @stream
50
50
  stream!(response:)
51
51
  else
52
- OmniAI::OpenAI::Chat::Completion.new(data: response.parse)
52
+ OmniAI::Chat::Completion.new(data: response.parse)
53
53
  end
54
54
  end
55
55
 
@@ -62,7 +62,7 @@ module OmniAI
62
62
  parser.feed(chunk) do |_, data|
63
63
  break if data.eql?('[DONE]')
64
64
 
65
- chunk = OmniAI::OpenAI::Chat::Chunk.new(data: JSON.parse(data))
65
+ chunk = OmniAI::Chat::Chunk.new(data: JSON.parse(data))
66
66
  @stream.call(chunk)
67
67
  end
68
68
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ # A configuration for each agent w/ `api_key` / `host` / `logger`.
5
+ class Config
6
+ attr_accessor :api_key, :host, :logger
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.5'
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.3
4
+ version: 0.1.5
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: []