omniai 0.0.4 → 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: f06b4a4287ce5c0b893d4a961aee12b76b11e305908b158fc343ef0213fb7d61
4
- data.tar.gz: c4d39d0ea4525c5b364692789b84ebe46897273afdeccab54be7375d76f0b990
3
+ metadata.gz: eb51f64b3514f196e07be3b77f2ca538878602af864f5c2c49e5e2506f05bfaf
4
+ data.tar.gz: f4069c9f19fbcc6f2caf90ab28e32ed83c8700b2ea8c686059afc612997b1ea6
5
5
  SHA512:
6
- metadata.gz: 68c97d0af47fe1d7e61ead17e59f0bd116296d50fde4859cb2293df3f728295da04b1216764d258185e46fef85a2fea03a8466d84268900bde1024b376899fa1
7
- data.tar.gz: 52bf6be629df472d71f51270f7c2534b1ec926a278801806cf062dc62eef912bda3f4af937a7f81f9db964c78fd738dd9678ca2353ec1eb3481febf354cf8021
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
+ ```
@@ -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.4'
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
@@ -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