omniai 0.0.3 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d54c88d48becdd4c496114b93841cf6dd32ba294a5cbf9828a0d0d4d28a023e
4
- data.tar.gz: 8f8bb67797a1fa993cd5dc202d60e78c041ec184cf8120eae170e1b821228c62
3
+ metadata.gz: eb51f64b3514f196e07be3b77f2ca538878602af864f5c2c49e5e2506f05bfaf
4
+ data.tar.gz: f4069c9f19fbcc6f2caf90ab28e32ed83c8700b2ea8c686059afc612997b1ea6
5
5
  SHA512:
6
- metadata.gz: 8f0a3651c5eb608d0aba74c8c8ae06d4def73fc519fc4cbef6c8b2a8c3434d00cd469e24eaafc8f07193cb028c93984e459c7ffc65e89e56bfc30e0ebc879a05
7
- data.tar.gz: 21be334bdd435bfb7b9c449556cce86dde4e33dd0d84bcd285cb4b52e438ed93ca387356821f76bce3064f3bc31be3446f43773456156976d0f33fcdceb89243
6
+ metadata.gz: 06ece9d4bd7db17c57bff05f3323ba2ddd5e10803a5e5b460d8f5c66ffad932880230270d5a3e5e3653e46c6aaeec0926cff740414c9bb8d0e799062e4ce3139
7
+ data.tar.gz: 8443711ec0a65da572ce47a2da284ef63e277bdffc64663ab0577c4ded90105faaa666819f09b9d8ac2d2e457db8f4c07303b987ebb96e719648dd8624e419c0
data/README.md CHANGED
@@ -1,31 +1,65 @@
1
- # Omniai
1
+ # OmniAI
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ OmniAI is a flexible AI library that standardizes the APIs for multipe AI providers:
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniai`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
12
+ ```sh
13
+ gem install omniai
14
+ ```
10
15
 
11
- Install the gem and add to the application's Gemfile by executing:
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
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
23
+ ## Usage
14
24
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
25
+ ### Chat
16
26
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
27
+ #### Anthropic (Claude)
18
28
 
19
- ## Usage
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
- TODO: Write usage instructions here
47
+ #### Mistral (LeChat)
22
48
 
23
- ## Development
49
+ ```ruby
50
+ require 'omniai-mistral'
24
51
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+ client = OmniAI::Mistral::Client.new
53
+ completion = client.chat.completion('Tell me a joke.')
54
+ completion.choice.message.content # '...'
55
+ ```
26
56
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+ #### OpenAI (ChatGPT)
28
58
 
29
- ## Contributing
59
+ ```ruby
60
+ require 'omniai-openai'
30
61
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/omniai.
62
+ client = OmniAI::OpenAI::Client.new
63
+ completion = client.chat.completion('Tell me a joke.')
64
+ completion.choice.message.content # '...'
65
+ ```
@@ -4,7 +4,7 @@ module OmniAI
4
4
  class Chat
5
5
  # A message returned by the API.
6
6
  class Message
7
- attr_accessor :index, :message, :role
7
+ attr_accessor :content, :role
8
8
 
9
9
  # @param content [Integer]
10
10
  # @param role [String]
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.6'
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} 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.3
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-10 00:00:00.000000000 Z
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