ruby-openai 7.3.1 → 7.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -10
- data/README.md +447 -265
- data/lib/openai/client.rb +19 -11
- data/lib/openai/compatibility.rb +1 -0
- data/lib/openai/usage.rb +70 -0
- data/lib/openai/version.rb +1 -1
- data/lib/openai.rb +4 -0
- metadata +3 -2
data/lib/openai/client.rb
CHANGED
@@ -2,18 +2,11 @@ module OpenAI
|
|
2
2
|
class Client
|
3
3
|
include OpenAI::HTTP
|
4
4
|
|
5
|
-
SENSITIVE_ATTRIBUTES = %i[@access_token @organization_id @extra_headers].freeze
|
6
|
-
CONFIG_KEYS = %i[
|
7
|
-
|
8
|
-
api_version
|
9
|
-
access_token
|
10
|
-
log_errors
|
11
|
-
organization_id
|
12
|
-
uri_base
|
13
|
-
request_timeout
|
14
|
-
extra_headers
|
15
|
-
].freeze
|
5
|
+
SENSITIVE_ATTRIBUTES = %i[@access_token @admin_token @organization_id @extra_headers].freeze
|
6
|
+
CONFIG_KEYS = %i[access_token admin_token api_type api_version extra_headers
|
7
|
+
log_errors organization_id request_timeout uri_base].freeze
|
16
8
|
attr_reader *CONFIG_KEYS, :faraday_middleware
|
9
|
+
attr_writer :access_token
|
17
10
|
|
18
11
|
def initialize(config = {}, &faraday_middleware)
|
19
12
|
CONFIG_KEYS.each do |key|
|
@@ -99,10 +92,25 @@ module OpenAI
|
|
99
92
|
json_post(path: "/moderations", parameters: parameters)
|
100
93
|
end
|
101
94
|
|
95
|
+
def usage
|
96
|
+
@usage ||= OpenAI::Usage.new(client: self)
|
97
|
+
end
|
98
|
+
|
102
99
|
def azure?
|
103
100
|
@api_type&.to_sym == :azure
|
104
101
|
end
|
105
102
|
|
103
|
+
def admin
|
104
|
+
unless admin_token
|
105
|
+
e = "You must set an OPENAI_ADMIN_TOKEN= to use administrative endpoints:\n\n https://platform.openai.com/settings/organization/admin-keys"
|
106
|
+
raise AuthenticationError, e
|
107
|
+
end
|
108
|
+
|
109
|
+
dup.tap do |client|
|
110
|
+
client.access_token = client.admin_token
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
106
114
|
def beta(apis)
|
107
115
|
dup.tap do |client|
|
108
116
|
client.add_headers("OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";"))
|
data/lib/openai/compatibility.rb
CHANGED
data/lib/openai/usage.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module OpenAI
|
2
|
+
class Usage
|
3
|
+
def initialize(client:)
|
4
|
+
@client = client
|
5
|
+
end
|
6
|
+
|
7
|
+
def completions(parameters: {})
|
8
|
+
@client.admin.get(
|
9
|
+
path: "/organization/usage/completions",
|
10
|
+
parameters: parameters
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def embeddings(parameters: {})
|
15
|
+
@client.admin.get(
|
16
|
+
path: "/organization/usage/embeddings",
|
17
|
+
parameters: parameters
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def moderations(parameters: {})
|
22
|
+
@client.admin.get(
|
23
|
+
path: "/organization/usage/moderations",
|
24
|
+
parameters: parameters
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def images(parameters: {})
|
29
|
+
@client.admin.get(
|
30
|
+
path: "/organization/usage/images",
|
31
|
+
parameters: parameters
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def audio_speeches(parameters: {})
|
36
|
+
@client.admin.get(
|
37
|
+
path: "/organization/usage/audio_speeches",
|
38
|
+
parameters: parameters
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def audio_transcriptions(parameters: {})
|
43
|
+
@client.admin.get(
|
44
|
+
path: "/organization/usage/audio_transcriptions",
|
45
|
+
parameters: parameters
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def vector_stores(parameters: {})
|
50
|
+
@client.admin.get(
|
51
|
+
path: "/organization/usage/vector_stores",
|
52
|
+
parameters: parameters
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def code_interpreter_sessions(parameters: {})
|
57
|
+
@client.admin.get(
|
58
|
+
path: "/organization/usage/code_interpreter_sessions",
|
59
|
+
parameters: parameters
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def costs(parameters: {})
|
64
|
+
@client.admin.get(
|
65
|
+
path: "/organization/costs",
|
66
|
+
parameters: parameters
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/openai/version.rb
CHANGED
data/lib/openai.rb
CHANGED
@@ -18,10 +18,12 @@ require_relative "openai/vector_store_file_batches"
|
|
18
18
|
require_relative "openai/audio"
|
19
19
|
require_relative "openai/version"
|
20
20
|
require_relative "openai/batches"
|
21
|
+
require_relative "openai/usage"
|
21
22
|
|
22
23
|
module OpenAI
|
23
24
|
class Error < StandardError; end
|
24
25
|
class ConfigurationError < Error; end
|
26
|
+
class AuthenticationError < Error; end
|
25
27
|
|
26
28
|
class MiddlewareErrors < Faraday::Middleware
|
27
29
|
def call(env)
|
@@ -41,6 +43,7 @@ module OpenAI
|
|
41
43
|
|
42
44
|
class Configuration
|
43
45
|
attr_accessor :access_token,
|
46
|
+
:admin_token,
|
44
47
|
:api_type,
|
45
48
|
:api_version,
|
46
49
|
:log_errors,
|
@@ -56,6 +59,7 @@ module OpenAI
|
|
56
59
|
|
57
60
|
def initialize
|
58
61
|
@access_token = nil
|
62
|
+
@admin_token = nil
|
59
63
|
@api_type = nil
|
60
64
|
@api_version = DEFAULT_API_VERSION
|
61
65
|
@log_errors = DEFAULT_LOG_ERRORS
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-openai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/openai/run_steps.rb
|
103
103
|
- lib/openai/runs.rb
|
104
104
|
- lib/openai/threads.rb
|
105
|
+
- lib/openai/usage.rb
|
105
106
|
- lib/openai/vector_store_file_batches.rb
|
106
107
|
- lib/openai/vector_store_files.rb
|
107
108
|
- lib/openai/vector_stores.rb
|