omniai-openai 1.8.1 → 1.8.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c4800d2a0c330c63c41ce1fd81e0826be57d5e2c1476561ab10f24164340b16
4
- data.tar.gz: 86f73a45fb4a7bd21b2610514375c9a05a89e133a9a9e9706200435f401e09be
3
+ metadata.gz: bd5c0c0055668349c161b1bcc599bf4c3f581dcdf25ec5c4c15084d2125686e3
4
+ data.tar.gz: 6402cb51f542d42fd567e4ee2d9b07ad5527e6d0c47f82ab2cfe608ea113341f
5
5
  SHA512:
6
- metadata.gz: '0541865c105629a0ac61914e89dce488e776f0c4a26638cab5b0c921530a63eeb44cfa371773dea408aa6b0c052969437437bb02f6ba02f3e3104b4f2c709a3b'
7
- data.tar.gz: 471c8f8321841b33e31246f73bf3773b4f384075d2b4277166fa629763bbeabc03e7ec34d9bcb2e2591085db71468e1ee3e0026744bba7def21e14c100bae236
6
+ metadata.gz: 426395b6eefdce402f20992b2ed3e10b80de32aa756dd32975c035422eeba4c1d7d1fd47ebbf7f79bc98ea92b6b468d4dc16886f6e59cb0a23490f0adfd0af22
7
+ data.tar.gz: 980902dfefe3a523d03c12f037ba3d5b92cdf894b12f7d42d94246879648d3ba6f32538a6f72ff1549882cbca78fbf7e5eb4ffe607948ce59e793206e3edb83b
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:
@@ -20,6 +20,8 @@ module OmniAI
20
20
  GPT_4 = 'gpt-4'
21
21
  GPT_4_TURBO = 'gpt-4-turbo'
22
22
  GPT_3_5_TURBO = 'gpt-3.5-turbo'
23
+ O1_MINI = 'o1-mini'
24
+ O1_PREVIEW = 'o1-preview'
23
25
  end
24
26
 
25
27
  DEFAULT_MODEL = Model::GPT_4O
@@ -40,7 +42,7 @@ module OmniAI
40
42
 
41
43
  # @return [String]
42
44
  def path
43
- "/#{OmniAI::OpenAI::Client::VERSION}/chat/completions"
45
+ "#{@client.api_prefix}/#{OmniAI::OpenAI::Client::VERSION}/chat/completions"
44
46
  end
45
47
  end
46
48
  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.1'
5
+ VERSION = '1.8.3'
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.1
4
+ version: 1.8.3
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-08-23 00:00:00.000000000 Z
11
+ date: 2024-10-10 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