omniai 0.0.9 → 0.1.1

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: bab309e1be1b9acc7671c341b8e50cd0ec257ac22b254899b3661e428432f290
4
- data.tar.gz: 7968c811a16cf77172b087a03693641dbca83f2ba683e5eff30eda05ad4817e4
3
+ metadata.gz: ba57f22a167440e6c6606d9bd1cf098673a11164b088a21f2a0e4d5b05b9689d
4
+ data.tar.gz: 2adbbf886759d517634f99e95670a532747afec94630e6df226d2d52c52f4330
5
5
  SHA512:
6
- metadata.gz: b22be38a54e83cb76c45e94d739290ee2530e51d81fd892e8a749deba3a54f88d9f7ec99a159df2688dadd7f5be9ce0a6ad03acfc7d0344e7ae4910e910f3bce
7
- data.tar.gz: a5a11dd87da47b2f5ee4a49d9a37bbfe55ccb1ff3b0a6da48544d076eb850e925343775ea90cbdf6a30f309bcb2d3e783be21798d7deecfc2762dca80a886393
6
+ metadata.gz: f08050fdae89870b429b70f0ebd4c8ed422beecdca7a201fd41bc9653b3f25dc277a9d25a6a9ca95a2abd7d95e7595a4b00e1282bf31e811b51a898eb38a5c0f
7
+ data.tar.gz: 5e256941913b412d2c7025cd20cfe836c786cf9556d8341b2b8106728eed0798236b64bacd06933127737a0bc69fae8e1d4b1cd42b2c3664091b25036e325a24
data/README.md CHANGED
@@ -22,9 +22,11 @@ gem install omniai-openai
22
22
 
23
23
  ## Usage
24
24
 
25
+ OmniAI implements APIs for a number of popular clients by default. A client can be initialized using the specific gem (e.g. `omniai-openai` for `OmniAI::OpenAI`). Vendor specific docs can be found within each repo.
26
+
25
27
  ### Client
26
28
 
27
- #### Anthropic (Claude)
29
+ #### [OmniAI::Anthropic](https://github.com/ksylvest/omniai-anthropic)
28
30
 
29
31
  ```ruby
30
32
  require 'omniai-anthropic'
@@ -32,7 +34,7 @@ require 'omniai-anthropic'
32
34
  client = OmniAI::Anthropic::Client.new
33
35
  ```
34
36
 
35
- #### Google (Gemini)
37
+ #### [OmniAI::Google](https://github.com/ksylvest/omniai-google)
36
38
 
37
39
  ```ruby
38
40
  require 'omniai-google'
@@ -40,7 +42,7 @@ require 'omniai-google'
40
42
  client = OmniAI::Google::Client.new
41
43
  ```
42
44
 
43
- #### Mistral (LeChat)
45
+ #### [OmniAI::Mistral](https://github.com/ksylvest/omniai-mistral)
44
46
 
45
47
  ```ruby
46
48
  require 'omniai-mistral'
@@ -48,18 +50,18 @@ require 'omniai-mistral'
48
50
  client = OmniAI::Mistral::Client.new
49
51
  ```
50
52
 
51
- #### OpenAI (ChatGPT)
53
+ #### [OmniAI::OpenAI](https://github.com/ksylvest/omniai-openai)
52
54
 
53
55
  ```ruby
54
56
  require 'omniai-openai'
55
57
 
56
58
  client = OmniAI::OpenAI::Client.new
57
- completion = client.chat.completion('Tell me a joke.')
58
- completion.choice.message.content # '...'
59
59
  ```
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:
64
+
63
65
  #### Basic
64
66
 
65
67
  ```ruby
@@ -70,7 +72,7 @@ puts(completion.choice.message.content) # '...'
70
72
  #### Streaming
71
73
 
72
74
  ```ruby
73
- stream = proc do |chunk|
75
+ client.chat.completion 'Tell me a joke.', stream: proc do |chunk|
74
76
  print(chunk.choice.delta.content) # '...'
75
77
  end
76
78
  ```
@@ -2,8 +2,8 @@
2
2
 
3
3
  module OmniAI
4
4
  class Chat
5
- # A delta returned by the API.
6
- class CompletionChunk
5
+ # A chunk returned by the API.
6
+ class Chunk
7
7
  attr_accessor :data
8
8
 
9
9
  # @param data [Hash]
@@ -2,7 +2,7 @@
2
2
 
3
3
  module OmniAI
4
4
  class Chat
5
- # An class wrapping the response completion. A vendor may override if custom behavior is required.
5
+ # A completion returned by the API.
6
6
  class Completion
7
7
  attr_accessor :data
8
8
 
@@ -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: data.parse)
65
+ chunk = OmniAI::OpenAI::Chat::Chunk.new(data: JSON.parse(data))
66
66
  @stream.call(chunk)
67
67
  end
68
68
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module OmniAI
4
4
  class Chat
5
- # An class wrapping the response usage. A vendor may override if custom behavior is required.
5
+ # A usage returned by the API.
6
6
  class Completion
7
7
  attr_accessor :data
8
8
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '0.0.9'
4
+ VERSION = '0.1.1'
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: 0.0.9
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
@@ -72,7 +72,6 @@ files:
72
72
  - lib/omniai/chat/delta.rb
73
73
  - lib/omniai/chat/message.rb
74
74
  - lib/omniai/chat/request.rb
75
- - lib/omniai/chat/stream.rb
76
75
  - lib/omniai/chat/usage.rb
77
76
  - lib/omniai/client.rb
78
77
  - lib/omniai/version.rb
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Chat
5
- # A processor for streaming back events in chunks.
6
- class Stream
7
- LINE_REGEX = /data:\s*(?<data>.*)\n\n/
8
-
9
- def initialize
10
- @buffer = String.new
11
- end
12
-
13
- # @yield [data] a parsed hash
14
- # @param [String] chunk
15
- def process!(chunk)
16
- @buffer << chunk
17
-
18
- while (line = @buffer.slice!(LINE_REGEX))
19
- match = LINE_REGEX.match(line)
20
- data = match[:data]
21
- break if data.eql?('[DONE]')
22
-
23
- yield JSON.parse(data)
24
- end
25
- end
26
- end
27
- end
28
- end