omniai-openai 1.2.0 → 1.2.1

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: 01d9c9144c74769c3eed7d8ec37f4cab63885057d5f16b02727e8c26e94414a0
4
- data.tar.gz: 98e56e503c8ba01d3822d448dab53c94fef16d08c3f7896884e381f0b10b54fb
3
+ metadata.gz: e3afb339ec2a0e69d5a268fd134aae4119e3140ccad493f22d7db43b817145a4
4
+ data.tar.gz: f49c3cfd25228e49555981cc93e05e6702d3ce4edde9fa07277bc68c83312361
5
5
  SHA512:
6
- metadata.gz: 652b78a11ffb57f7b884d39fd08222fd4a87a0105a32ec0304d7d09efde5988b7f6058d3fbed46b6b3b8e8d44fec5191ffe925804f953456502020ea9cc8ef6f
7
- data.tar.gz: 41c3516078e9a9411eebea6a0eaf3424b6a756d8b714697e51817e02f7faa9c4f170dc38c2fadb21c325a7576c5ae615468e3fb5d1438014532ae1be4c43d37b
6
+ metadata.gz: 4455db3523b81301793b936528312394cb0f98b8f51ad7a49f5f6fe5811c2969dcaf679649deb0cb90bfec5fdf5838f3ba6444eea645d560ceaaaf96b9c15f5f
7
+ data.tar.gz: 804f70fd6067cba057aaa7dbbe7d65f5edaa389e5315fb4a107f154fbafa1139d33ad637439e8b838036767c02e4e2cfed0d69c43c0a36cb805bb4dfe21eb907
data/README.md CHANGED
@@ -25,7 +25,7 @@ A client may also be passed the following options:
25
25
  - `api_key` (required - default is `ENV['OPENAI_API_KEY']`)
26
26
  - `organization` (optional)
27
27
  - `project` (optional)
28
- - `host` (optional)
28
+ - `host` (optional) useful for usage with Ollama or LocalAI
29
29
 
30
30
  ### Configuration
31
31
 
@@ -36,10 +36,30 @@ OmniAI::OpenAI.configure do |config|
36
36
  config.api_key = 'sk-...' # default: ENV['OPENAI_API_KEY']
37
37
  config.organization = '...' # default: ENV['OPENAI_ORGANIZATION']
38
38
  config.project = '...' # default: ENV['OPENAI_PROJECT']
39
- config.host = '...' # default: 'https://api.openai.com'
39
+ config.host = '...' # default: 'https://api.openai.com' - override for usage with LocalAI / Ollama
40
40
  end
41
41
  ```
42
42
 
43
+ #### Usage with [LocalAI](https://localai.io/)
44
+
45
+ LocalAI offers [built in compatability with the OpenAI specification](https://localai.io/). To initialize a client that points to a Ollama change the host accordingly:
46
+
47
+ ```ruby
48
+ client = OmniAI::OpenAI::Client.new(host: 'http://localhost:8080', api_key: nil)
49
+ ```
50
+
51
+ _For details on installation or running LocalAI see the [getting started tutorial](https://localai.io/basics/getting_started/)._
52
+
53
+ #### Usage with [Ollama](https://www.ollama.com/)
54
+
55
+ Ollama offers [built in compatability with the OpenAI specification](https://ollama.com/blog/openai-compatibility). To initialize a client that points to a Ollama change the host accordingly:
56
+
57
+ ```ruby
58
+ client = OmniAI::OpenAI::Client.new(host: 'http://localhost:11434', api_key: nil)
59
+ ```
60
+
61
+ _For details on installation or running Ollama checkout [the project README](https://github.com/ollama/ollama)._
62
+
43
63
  ### Chat
44
64
 
45
65
  A chat completion is generated by passing in prompts using any a variety of formats:
@@ -33,19 +33,24 @@ module OmniAI
33
33
  logger: OmniAI::OpenAI.config.logger,
34
34
  host: OmniAI::OpenAI.config.host
35
35
  )
36
- raise(ArgumentError, %(ENV['OPENAI_API_KEY'] must be defined or `api_key` must be passed)) if api_key.nil?
36
+ if api_key.nil? && host.eql?(Config::DEFAULT_HOST)
37
+ raise(
38
+ ArgumentError,
39
+ %(ENV['OPENAI_API_KEY'] must be defined or `api_key` must be passed when using #{Config::DEFAULT_HOST})
40
+ )
41
+ end
37
42
 
38
- super(api_key:, logger:)
43
+ super(api_key:, host:, logger:)
39
44
 
40
45
  @organization = organization
41
46
  @project = project
42
- @host = host
43
47
  end
44
48
 
45
49
  # @return [HTTP::Client]
46
50
  def connection
47
51
  @connection ||= begin
48
- http = HTTP.auth("Bearer #{api_key}").persistent(@host)
52
+ http = HTTP.persistent(@host)
53
+ http = http.auth("Bearer #{@api_key}") if @api_key
49
54
  http = http.headers('OpenAI-Organization': @organization) if @organization
50
55
  http = http.headers('OpenAI-Project': @project) if @project
51
56
  http
@@ -6,12 +6,14 @@ module OmniAI
6
6
  class Config < OmniAI::Config
7
7
  attr_accessor :organization, :project, :chat_options, :transcribe_options, :speak_options
8
8
 
9
+ DEFAULT_HOST = 'https://api.openai.com'
10
+
9
11
  def initialize
10
12
  super
11
13
  @api_key = ENV.fetch('OPENAI_API_KEY', nil)
12
14
  @organization = ENV.fetch('OPENAI_ORGANIZATION', nil)
13
15
  @project = ENV.fetch('OPENAI_PROJECT', nil)
14
- @host = ENV.fetch('OPENAI_HOST', 'https://api.openai.com')
16
+ @host = ENV.fetch('OPENAI_HOST', DEFAULT_HOST)
15
17
  @chat_options = {}
16
18
  @transcribe_options = {}
17
19
  @speak_options = {}
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module OpenAI
5
- VERSION = '1.2.0'
5
+ VERSION = '1.2.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-openai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre