omniai-openai 1.8.2 → 1.8.4

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: 8e2977b31559860cd16a54dca1b749d917f9a5146110b4bf6f0b42b8d11eab60
4
- data.tar.gz: 30463a38bcea6ae3b95490fb9a7e8a3ed2b4d48b75a597ca1ab4476b1fe4ec5d
3
+ metadata.gz: a854e09772f9bbb85c5888f17118c935de8638c451e40f0e9991e48c334ee9eb
4
+ data.tar.gz: e83aa0301a4ace180898d86ddd1cddeccece1f9fca8da97316430ad2aebb5170
5
5
  SHA512:
6
- metadata.gz: 17cac920b1ed4f0cbe8097cb86c98e9a5b26d3835d495f1609fb15b0a72169b5566d00f1cc41fbba491a9f0b2b0117f3b9d408e70062920529da7d94e7096d56
7
- data.tar.gz: 9c7b2bb17652e13df0642648fb6927d9467999375c9532a780d95958f59cd1c66c41900fabd16467074003ed9701ecebcd4c8ba8eaef4694758bdbe23ef8715b
6
+ metadata.gz: d63e04ffdd27bc4d362d15bd6415a8101a87f973f259b034617168a5e1196505198a59c812782e3d94087a54ebf434eb959f4afb06dbba9add6d40152674e58a
7
+ data.tar.gz: 971dfa467e7276b0eab4495f18f343884f8f5fd3894227e8ac4643f0860d2761b6c3d9938a58ca637d8544fbeb963710b0012b1b66c588d48baf7ee282b1324e
data/README.md CHANGED
@@ -23,9 +23,10 @@ client = OmniAI::OpenAI::Client.new
23
23
  A client may also be passed the following options:
24
24
 
25
25
  - `api_key` (required - default is `ENV['OPENAI_API_KEY']`)
26
+ - `api_prefix` (optional) - used with a host when necessary
26
27
  - `organization` (optional)
27
28
  - `project` (optional)
28
- - `host` (optional) useful for usage with Ollama or LocalAI
29
+ - `host` (optional) useful for usage with Ollama, LocalAI or other OpenAI API compatible services
29
30
 
30
31
  ### Configuration
31
32
 
@@ -60,6 +61,17 @@ client = OmniAI::OpenAI::Client.new(host: 'http://localhost:11434', api_key: nil
60
61
 
61
62
  _For details on installation or running Ollama checkout [the project README](https://github.com/ollama/ollama)._
62
63
 
64
+ #### Usage with [OpenRouter](https://open_router.ai/)
65
+
66
+ Other fee-based systems/services have adopted all or some of the OpenAI API. For example [open_router.ai](https://open_router.ai) is a web-services that provides access to many models and providers using their own as well as an OpenAI API.
67
+
68
+ ```ruby
69
+ client = OmniAI::OpenAI::Client.new(
70
+ host: 'https://open_router.ai',
71
+ api_key: ENV['OPENROUTER_API_KEY'],
72
+ api_prefix: '/api')
73
+ ```
74
+
63
75
  ### Chat
64
76
 
65
77
  A chat completion is generated by passing in a simple text prompt:
@@ -22,6 +22,7 @@ module OmniAI
22
22
  GPT_3_5_TURBO = 'gpt-3.5-turbo'
23
23
  O1_MINI = 'o1-mini'
24
24
  O1_PREVIEW = 'o1-preview'
25
+ O1 = O1_PREVIEW
25
26
  end
26
27
 
27
28
  DEFAULT_MODEL = Model::GPT_4O
@@ -42,7 +43,7 @@ module OmniAI
42
43
 
43
44
  # @return [String]
44
45
  def path
45
- "/#{OmniAI::OpenAI::Client::VERSION}/chat/completions"
46
+ "#{@client.api_prefix}/#{OmniAI::OpenAI::Client::VERSION}/chat/completions"
46
47
  end
47
48
  end
48
49
  end
@@ -22,7 +22,10 @@ module OmniAI
22
22
  class Client < OmniAI::Client
23
23
  VERSION = 'v1'
24
24
 
25
+ attr_reader :api_prefix
26
+
25
27
  # @param api_key [String, nil] optional - defaults to `OmniAI::OpenAI.config.api_key`
28
+ # @param api_prefix [String, nil] optional - defaults to empty string
26
29
  # @param host [String] optional - defaults to `OmniAI::OpenAI.config.host`
27
30
  # @param project [String, nil] optional - defaults to `OmniAI::OpenAI.config.project`
28
31
  # @param organization [String, nil] optional - defaults to `OmniAI::OpenAI.config.organization`
@@ -30,6 +33,7 @@ module OmniAI
30
33
  # @param timeout [Integer, nil] optional - defaults to `OmniAI::OpenAI.config.timeout`
31
34
  def initialize(
32
35
  api_key: OmniAI::OpenAI.config.api_key,
36
+ api_prefix: '',
33
37
  host: OmniAI::OpenAI.config.host,
34
38
  organization: OmniAI::OpenAI.config.organization,
35
39
  project: OmniAI::OpenAI.config.project,
@@ -47,6 +51,11 @@ module OmniAI
47
51
 
48
52
  @organization = organization
49
53
  @project = project
54
+
55
+ @api_prefix = api_prefix
56
+ return if @api_prefix.empty? || @api_prefix.start_with?('/')
57
+
58
+ @api_prefix.prepend('/')
50
59
  end
51
60
 
52
61
  # @return [HTTP::Client]
@@ -27,7 +27,7 @@ module OmniAI
27
27
 
28
28
  # @return [String]
29
29
  def path
30
- "/#{OmniAI::OpenAI::Client::VERSION}/embeddings"
30
+ "#{@client.api_prefix}/#{OmniAI::OpenAI::Client::VERSION}/embeddings"
31
31
  end
32
32
 
33
33
  # @param [Object] value
@@ -30,7 +30,7 @@ module OmniAI
30
30
 
31
31
  # @return [String]
32
32
  def path
33
- "/#{OmniAI::OpenAI::Client::VERSION}/audio/speech"
33
+ "#{@client.api_prefix}/#{OmniAI::OpenAI::Client::VERSION}/audio/speech"
34
34
  end
35
35
  end
36
36
  end
@@ -199,7 +199,7 @@ module OmniAI
199
199
 
200
200
  # @return [String]
201
201
  def path
202
- "/#{OmniAI::OpenAI::Client::VERSION}/threads/#{@thread_id}/messages#{"/#{@id}" if @id}"
202
+ "#{@client.api_prefix}/#{OmniAI::OpenAI::Client::VERSION}/threads/#{@thread_id}/messages#{"/#{@id}" if @id}"
203
203
  end
204
204
  end
205
205
  end
@@ -252,7 +252,7 @@ module OmniAI
252
252
 
253
253
  # @return [String]
254
254
  def path
255
- "/#{OmniAI::OpenAI::Client::VERSION}/threads/#{@thread_id}/runs#{"/#{@id}" if @id}"
255
+ "#{@client.api_prefix}/#{OmniAI::OpenAI::Client::VERSION}/threads/#{@thread_id}/runs#{"/#{@id}" if @id}"
256
256
  end
257
257
  end
258
258
  end
@@ -21,7 +21,7 @@ module OmniAI
21
21
 
22
22
  # @return [String]
23
23
  def path
24
- "/#{OmniAI::OpenAI::Client::VERSION}/audio/transcriptions"
24
+ "#{@client.api_prefix}/#{OmniAI::OpenAI::Client::VERSION}/audio/transcriptions"
25
25
  end
26
26
  end
27
27
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module OpenAI
5
- VERSION = '1.8.2'
5
+ VERSION = '1.8.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-openai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.4
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-09-12 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.5.14
109
+ rubygems_version: 3.5.18
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: A generalized framework for interacting with OpenAI