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 +4 -4
- data/README.md +9 -7
- data/lib/omniai/chat/chunk.rb +2 -2
- data/lib/omniai/chat/completion.rb +1 -1
- data/lib/omniai/chat/request.rb +1 -1
- data/lib/omniai/chat/usage.rb +1 -1
- data/lib/omniai/version.rb +1 -1
- metadata +1 -2
- data/lib/omniai/chat/stream.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba57f22a167440e6c6606d9bd1cf098673a11164b088a21f2a0e4d5b05b9689d
|
4
|
+
data.tar.gz: 2adbbf886759d517634f99e95670a532747afec94630e6df226d2d52c52f4330
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
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
|
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
|
75
|
+
client.chat.completion 'Tell me a joke.', stream: proc do |chunk|
|
74
76
|
print(chunk.choice.delta.content) # '...'
|
75
77
|
end
|
76
78
|
```
|
data/lib/omniai/chat/chunk.rb
CHANGED
data/lib/omniai/chat/request.rb
CHANGED
data/lib/omniai/chat/usage.rb
CHANGED
data/lib/omniai/version.rb
CHANGED
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.
|
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
|
data/lib/omniai/chat/stream.rb
DELETED
@@ -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
|