omniai-openai 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/omniai/openai/client.rb +10 -7
- data/lib/omniai/openai/config.rb +27 -12
- 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
|
[![CircleCI](https://circleci.com/gh/ksylvest/omniai-openai.svg?style=svg)](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
|
|
data/lib/omniai/openai/client.rb
CHANGED
@@ -22,16 +22,19 @@ 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)
|
37
40
|
raise(
|
@@ -40,7 +43,7 @@ module OmniAI
|
|
40
43
|
)
|
41
44
|
end
|
42
45
|
|
43
|
-
super(api_key:, host:, logger:)
|
46
|
+
super(api_key:, host:, logger:, timeout:)
|
44
47
|
|
45
48
|
@organization = organization
|
46
49
|
@project = project
|
@@ -49,7 +52,7 @@ module OmniAI
|
|
49
52
|
# @return [HTTP::Client]
|
50
53
|
def connection
|
51
54
|
@connection ||= begin
|
52
|
-
http =
|
55
|
+
http = super
|
53
56
|
http = http.auth("Bearer #{@api_key}") if @api_key
|
54
57
|
http = http.headers('OpenAI-Organization': @organization) if @organization
|
55
58
|
http = http.headers('OpenAI-Project': @project) if @project
|
data/lib/omniai/openai/config.rb
CHANGED
@@ -2,21 +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
|
-
attr_accessor :organization, :project, :chat_options, :transcribe_options, :speak_options
|
8
|
-
|
9
7
|
DEFAULT_HOST = 'https://api.openai.com'
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
20
35
|
end
|
21
36
|
end
|
22
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
|