omniai 0.0.9 → 0.1.0
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/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: 7f87f1b50c279a434ef7c23fb84f66321450897a62c9db0eda70659e3ac024a6
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 334d3055c491bb582107b62ff555bba9bd175d9a23d7492cbfb07bdae4a1b876
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c6ed29f063e505bf58ad6ca19f8d4dace1627f73fb3bee8b52fb5f9756d550f3ff322e7ef00d286044eaa9a0b48a16811e62efb70c130948302834e9206a362d
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 512fa19f0b5cb1c67a081d413bdf8e9b964716f08151fc20b048f5c2b46edc4eb8ec891563eb510c98e7ae5749c63afbbb661546718ec219f1287592c1f351da
         
     | 
    
        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/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.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
       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
         
     |