omniai-openai 1.2.0 → 1.3.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 +23 -3
- data/lib/omniai/openai/client.rb +17 -9
- data/lib/omniai/openai/config.rb +28 -11
- data/lib/omniai/openai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a95f906f1bf54382e8ace7ae6b1622ad22d2502a23c4804038b1ca66ff43086
|
4
|
+
data.tar.gz: 6694a63f7f76e2d41220a18e2ea852a19e956a8258761b71e9a0ec747197c9a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c19cd98191bd1826f24af180bcf87e96670fc162c6555bf368e4eda9305cdf5fa465585c74764d55481181752f563a581b09e3b1583220df70d9b227861a51d8
|
7
|
+
data.tar.gz: b6eb2fdeb33dcf4dda02f2b608e13ae3cc29c687b0c9eb31bdecaf72d07548b0201c68efe3e40cd754b368d2b2f84813e5eeb207878dbc6355fe4a67a8308f3e
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://circleci.com/gh/ksylvest/omniai-openai)
|
4
4
|
|
5
|
-
An OpenAI implementation of the [OmniAI](https://github.com/ksylvest/omniai)
|
5
|
+
An OpenAI implementation of the [OmniAI](https://github.com/ksylvest/omniai) interface supporting ChatGPT, Whisper, Text-to-Voice, Voice-to-Text, and more. This library is community maintained.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -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:
|
data/lib/omniai/openai/client.rb
CHANGED
@@ -22,30 +22,38 @@ module OmniAI
|
|
22
22
|
class Client < OmniAI::Client
|
23
23
|
VERSION = 'v1'
|
24
24
|
|
25
|
-
# @param api_key [String] optional - defaults to `OmniAI::OpenAI.config.api_key`
|
26
|
-
# @param
|
27
|
-
# @param
|
28
|
-
# @param
|
25
|
+
# @param api_key [String, nil] optional - defaults to `OmniAI::OpenAI.config.api_key`
|
26
|
+
# @param host [String] optional - defaults to `OmniAI::OpenAI.config.host`
|
27
|
+
# @param project [String, nil] optional - defaults to `OmniAI::OpenAI.config.project`
|
28
|
+
# @param organization [String, nil] optional - defaults to `OmniAI::OpenAI.config.organization`
|
29
|
+
# @param logger [Logger, nil] optional - defaults to `OmniAI::OpenAI.config.logger`
|
30
|
+
# @param timeout [Integer, nil] optional - defaults to `OmniAI::OpenAI.config.timeout`
|
29
31
|
def initialize(
|
30
32
|
api_key: OmniAI::OpenAI.config.api_key,
|
33
|
+
host: OmniAI::OpenAI.config.host,
|
31
34
|
organization: OmniAI::OpenAI.config.organization,
|
32
35
|
project: OmniAI::OpenAI.config.project,
|
33
36
|
logger: OmniAI::OpenAI.config.logger,
|
34
|
-
|
37
|
+
timeout: OmniAI::OpenAI.config.timeout
|
35
38
|
)
|
36
|
-
|
39
|
+
if api_key.nil? && host.eql?(Config::DEFAULT_HOST)
|
40
|
+
raise(
|
41
|
+
ArgumentError,
|
42
|
+
%(ENV['OPENAI_API_KEY'] must be defined or `api_key` must be passed when using #{Config::DEFAULT_HOST})
|
43
|
+
)
|
44
|
+
end
|
37
45
|
|
38
|
-
super(api_key:, logger:)
|
46
|
+
super(api_key:, host:, logger:, timeout:)
|
39
47
|
|
40
48
|
@organization = organization
|
41
49
|
@project = project
|
42
|
-
@host = host
|
43
50
|
end
|
44
51
|
|
45
52
|
# @return [HTTP::Client]
|
46
53
|
def connection
|
47
54
|
@connection ||= begin
|
48
|
-
http =
|
55
|
+
http = super
|
56
|
+
http = http.auth("Bearer #{@api_key}") if @api_key
|
49
57
|
http = http.headers('OpenAI-Organization': @organization) if @organization
|
50
58
|
http = http.headers('OpenAI-Project': @project) if @project
|
51
59
|
http
|
data/lib/omniai/openai/config.rb
CHANGED
@@ -2,19 +2,36 @@
|
|
2
2
|
|
3
3
|
module OmniAI
|
4
4
|
module OpenAI
|
5
|
-
# Configuration for
|
5
|
+
# Configuration for OpenAI.
|
6
6
|
class Config < OmniAI::Config
|
7
|
-
|
7
|
+
DEFAULT_HOST = 'https://api.openai.com'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
# @!attribute [rw] organization
|
10
|
+
# @return [String, nil] passed as `OpenAI-Organization` if specified
|
11
|
+
attr_accessor :organization
|
12
|
+
|
13
|
+
# @!attribute [rw] project
|
14
|
+
# @return [String, nil] passed as `OpenAI-Organization` if specified
|
15
|
+
attr_accessor :project
|
16
|
+
|
17
|
+
# @param api_key [String, nil] optional - defaults to `ENV['OPENAI_API_KEY']`
|
18
|
+
# @param host [String, nil] optional - defaults to ENV['OPENAI_HOST'] w/ fallback to `DEFAULT_HOST`
|
19
|
+
# @param organization [String, nil] optional - defaults to `ENV['OPENAI_ORGANIZATION']`
|
20
|
+
# @param project [String, nil] optional - defaults to `ENV['OPENAI_PROJECT']`
|
21
|
+
# @param logger [Logger, nil] optional
|
22
|
+
# @param timeout [Integer, Hash, nil] optional
|
23
|
+
def initialize(
|
24
|
+
api_key: ENV.fetch('OPENAI_API_KEY', nil),
|
25
|
+
host: ENV.fetch('OPENAI_HOST', DEFAULT_HOST),
|
26
|
+
organization: ENV.fetch('OPENAI_ORGANIZATION', nil),
|
27
|
+
project: ENV.fetch('OPENAI_PROJECT', nil),
|
28
|
+
logger: nil,
|
29
|
+
timeout: nil
|
30
|
+
)
|
31
|
+
super(api_key:, host:, logger:, timeout:)
|
32
|
+
|
33
|
+
@organization = organization
|
34
|
+
@project = project
|
18
35
|
end
|
19
36
|
end
|
20
37
|
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.
|
4
|
+
version: 1.3.0
|
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-06-
|
11
|
+
date: 2024-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|