omniai 0.0.3 → 0.0.6
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 +49 -15
- data/lib/omniai/chat/message.rb +1 -1
- data/lib/omniai/chat/stream.rb +28 -0
- data/lib/omniai/version.rb +1 -1
- data/lib/omniai.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb51f64b3514f196e07be3b77f2ca538878602af864f5c2c49e5e2506f05bfaf
|
4
|
+
data.tar.gz: f4069c9f19fbcc6f2caf90ab28e32ed83c8700b2ea8c686059afc612997b1ea6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ece9d4bd7db17c57bff05f3323ba2ddd5e10803a5e5b460d8f5c66ffad932880230270d5a3e5e3653e46c6aaeec0926cff740414c9bb8d0e799062e4ce3139
|
7
|
+
data.tar.gz: 8443711ec0a65da572ce47a2da284ef63e277bdffc64663ab0577c4ded90105faaa666819f09b9d8ac2d2e457db8f4c07303b987ebb96e719648dd8624e419c0
|
data/README.md
CHANGED
@@ -1,31 +1,65 @@
|
|
1
|
-
#
|
1
|
+
# OmniAI
|
2
2
|
|
3
|
-
|
3
|
+
OmniAI is a flexible AI library that standardizes the APIs for multipe AI providers:
|
4
4
|
|
5
|
-
|
5
|
+
- [OmniAI::Anthropic](https://github.com/ksylvest/omniai-anthropic)
|
6
|
+
- [OmniAI::Google](https://github.com/ksylvest/omniai-google)
|
7
|
+
- [OmniAI::Mistral](https://github.com/ksylvest/omniai-mistral)
|
8
|
+
- [OmniAI::OpenAI](https://github.com/ksylvest/omniai-openai)
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
9
|
-
|
12
|
+
```sh
|
13
|
+
gem install omniai
|
14
|
+
```
|
10
15
|
|
11
|
-
|
16
|
+
```sh
|
17
|
+
gem install omniai-anthropic
|
18
|
+
gem install omniai-mistral
|
19
|
+
gem install omniai-google
|
20
|
+
gem install omniai-openai
|
21
|
+
```
|
12
22
|
|
13
|
-
|
23
|
+
## Usage
|
14
24
|
|
15
|
-
|
25
|
+
### Chat
|
16
26
|
|
17
|
-
|
27
|
+
#### Anthropic (Claude)
|
18
28
|
|
19
|
-
|
29
|
+
```ruby
|
30
|
+
require 'omniai-anthropic'
|
31
|
+
|
32
|
+
client = OmniAI::Anthropic::Client.new
|
33
|
+
completion = client.chat.completion('Tell me a joke.')
|
34
|
+
completion.choice.message.content # '...'
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Google (Gemini)
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'omniai-google'
|
41
|
+
|
42
|
+
client = OmniAI::Google::Client.new
|
43
|
+
completion = client.chat.completion('Tell me a joke.')
|
44
|
+
completion.choice.message.content # '...'
|
45
|
+
```
|
20
46
|
|
21
|
-
|
47
|
+
#### Mistral (LeChat)
|
22
48
|
|
23
|
-
|
49
|
+
```ruby
|
50
|
+
require 'omniai-mistral'
|
24
51
|
|
25
|
-
|
52
|
+
client = OmniAI::Mistral::Client.new
|
53
|
+
completion = client.chat.completion('Tell me a joke.')
|
54
|
+
completion.choice.message.content # '...'
|
55
|
+
```
|
26
56
|
|
27
|
-
|
57
|
+
#### OpenAI (ChatGPT)
|
28
58
|
|
29
|
-
|
59
|
+
```ruby
|
60
|
+
require 'omniai-openai'
|
30
61
|
|
31
|
-
|
62
|
+
client = OmniAI::OpenAI::Client.new
|
63
|
+
completion = client.chat.completion('Tell me a joke.')
|
64
|
+
completion.choice.message.content # '...'
|
65
|
+
```
|
data/lib/omniai/chat/message.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
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
|
data/lib/omniai/version.rb
CHANGED
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} headers=#{response.headers} body=#{response.body}")
|
19
|
+
super("status=#{response.status.inspect} headers=#{response.headers.inspect} body=#{response.body.inspect}")
|
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.0.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2024-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/omniai/chat/message.rb
|
57
57
|
- lib/omniai/chat/request.rb
|
58
58
|
- lib/omniai/chat/response.rb
|
59
|
+
- lib/omniai/chat/stream.rb
|
59
60
|
- lib/omniai/client.rb
|
60
61
|
- lib/omniai/version.rb
|
61
62
|
homepage: https://github.com/ksylvest/omniai
|