Class: OpenAI::Client
- Inherits:
-
Object
show all
- Includes:
- HTTP
- Defined in:
- lib/openai/client.rb
Constant Summary
collapse
- SENSITIVE_ATTRIBUTES =
%i[@access_token @organization_id @extra_headers].freeze
- CONFIG_KEYS =
%i[
api_type
api_version
access_token
log_errors
organization_id
uri_base
request_timeout
extra_headers
].freeze
Instance Method Summary
collapse
Methods included from HTTP
#delete, #get, #json_post, #multipart_post, #post
#add_headers
Constructor Details
#initialize(config = {}, &faraday_middleware) ⇒ Client
Returns a new instance of Client.
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/openai/client.rb', line 18
def initialize(config = {}, &faraday_middleware)
CONFIG_KEYS.each do |key|
instance_variable_set(
"@#{key}",
config[key].nil? ? OpenAI.configuration.send(key) : config[key]
)
end
@faraday_middleware = faraday_middleware
end
|
Instance Method Details
#assistants ⇒ Object
62
63
64
|
# File 'lib/openai/client.rb', line 62
def assistants
@assistants ||= OpenAI::Assistants.new(client: self)
end
|
#audio ⇒ Object
42
43
44
|
# File 'lib/openai/client.rb', line 42
def audio
@audio ||= OpenAI::Audio.new(client: self)
end
|
#azure? ⇒ Boolean
102
103
104
|
# File 'lib/openai/client.rb', line 102
def azure?
@api_type&.to_sym == :azure
end
|
#batches ⇒ Object
94
95
96
|
# File 'lib/openai/client.rb', line 94
def batches
@batches ||= OpenAI::Batches.new(client: self)
end
|
#beta(apis) ⇒ Object
106
107
108
109
110
|
# File 'lib/openai/client.rb', line 106
def beta(apis)
dup.tap do |client|
client.("OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";"))
end
end
|
#chat(parameters: {}) ⇒ Object
30
31
32
|
# File 'lib/openai/client.rb', line 30
def chat(parameters: {})
json_post(path: "/chat/completions", parameters: parameters)
end
|
#completions(parameters: {}) ⇒ Object
38
39
40
|
# File 'lib/openai/client.rb', line 38
def completions(parameters: {})
json_post(path: "/completions", parameters: parameters)
end
|
#embeddings(parameters: {}) ⇒ Object
34
35
36
|
# File 'lib/openai/client.rb', line 34
def embeddings(parameters: {})
json_post(path: "/embeddings", parameters: parameters)
end
|
#files ⇒ Object
46
47
48
|
# File 'lib/openai/client.rb', line 46
def files
@files ||= OpenAI::Files.new(client: self)
end
|
#finetunes ⇒ Object
50
51
52
|
# File 'lib/openai/client.rb', line 50
def finetunes
@finetunes ||= OpenAI::Finetunes.new(client: self)
end
|
#images ⇒ Object
54
55
56
|
# File 'lib/openai/client.rb', line 54
def images
@images ||= OpenAI::Images.new(client: self)
end
|
#inspect ⇒ Object
112
113
114
115
116
117
118
119
120
|
# File 'lib/openai/client.rb', line 112
def inspect
vars = instance_variables.map do |var|
value = instance_variable_get(var)
SENSITIVE_ATTRIBUTES.include?(var) ? "#{var}=[REDACTED]" : "#{var}=#{value.inspect}"
end
"#<#{self.class}:#{object_id} #{vars.join(', ')}>"
end
|
#messages ⇒ Object
70
71
72
|
# File 'lib/openai/client.rb', line 70
def messages
@messages ||= OpenAI::Messages.new(client: self)
end
|
#models ⇒ Object
58
59
60
|
# File 'lib/openai/client.rb', line 58
def models
@models ||= OpenAI::Models.new(client: self)
end
|
#moderations(parameters: {}) ⇒ Object
98
99
100
|
# File 'lib/openai/client.rb', line 98
def moderations(parameters: {})
json_post(path: "/moderations", parameters: parameters)
end
|
#run_steps ⇒ Object
78
79
80
|
# File 'lib/openai/client.rb', line 78
def run_steps
@run_steps ||= OpenAI::RunSteps.new(client: self)
end
|
#runs ⇒ Object
74
75
76
|
# File 'lib/openai/client.rb', line 74
def runs
@runs ||= OpenAI::Runs.new(client: self)
end
|
#threads ⇒ Object
66
67
68
|
# File 'lib/openai/client.rb', line 66
def threads
@threads ||= OpenAI::Threads.new(client: self)
end
|
#vector_store_file_batches ⇒ Object
90
91
92
|
# File 'lib/openai/client.rb', line 90
def vector_store_file_batches
@vector_store_file_batches ||= OpenAI::VectorStoreFileBatches.new(client: self)
end
|
#vector_store_files ⇒ Object
86
87
88
|
# File 'lib/openai/client.rb', line 86
def vector_store_files
@vector_store_files ||= OpenAI::VectorStoreFiles.new(client: self)
end
|
#vector_stores ⇒ Object
82
83
84
|
# File 'lib/openai/client.rb', line 82
def vector_stores
@vector_stores ||= OpenAI::VectorStores.new(client: self)
end
|