Class: OpenAI::Client
- Inherits:
-
Object
show all
- Includes:
- HTTP
- Defined in:
- lib/openai/client.rb
Constant Summary
collapse
- CONFIG_KEYS =
%i[
api_type
api_version
access_token
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.
16
17
18
19
20
21
22
23
|
# File 'lib/openai/client.rb', line 16
def initialize(config = {}, &faraday_middleware)
CONFIG_KEYS.each do |key|
instance_variable_set("@#{key}", config[key] || OpenAI.configuration.send(key))
end
@faraday_middleware = faraday_middleware
end
|
Instance Method Details
#assistants ⇒ Object
61
62
63
|
# File 'lib/openai/client.rb', line 61
def assistants
@assistants ||= OpenAI::Assistants.new(client: self)
end
|
#audio ⇒ Object
41
42
43
|
# File 'lib/openai/client.rb', line 41
def audio
@audio ||= OpenAI::Audio.new(client: self)
end
|
#azure? ⇒ Boolean
85
86
87
|
# File 'lib/openai/client.rb', line 85
def azure?
@api_type&.to_sym == :azure
end
|
#beta(apis) ⇒ Object
89
90
91
92
93
|
# File 'lib/openai/client.rb', line 89
def beta(apis)
dup.tap do |client|
client.("OpenAI-Beta": apis.map { |k, v| "#{k}=#{v}" }.join(";"))
end
end
|
#chat(parameters: {}) ⇒ Object
25
26
27
|
# File 'lib/openai/client.rb', line 25
def chat(parameters: {})
json_post(path: "/chat/completions", parameters: parameters)
end
|
#completions(parameters: {}) ⇒ Object
37
38
39
|
# File 'lib/openai/client.rb', line 37
def completions(parameters: {})
json_post(path: "/completions", parameters: parameters)
end
|
#edits(parameters: {}) ⇒ Object
29
30
31
|
# File 'lib/openai/client.rb', line 29
def edits(parameters: {})
json_post(path: "/edits", parameters: parameters)
end
|
#embeddings(parameters: {}) ⇒ Object
33
34
35
|
# File 'lib/openai/client.rb', line 33
def embeddings(parameters: {})
json_post(path: "/embeddings", parameters: parameters)
end
|
#files ⇒ Object
45
46
47
|
# File 'lib/openai/client.rb', line 45
def files
@files ||= OpenAI::Files.new(client: self)
end
|
#finetunes ⇒ Object
49
50
51
|
# File 'lib/openai/client.rb', line 49
def finetunes
@finetunes ||= OpenAI::Finetunes.new(client: self)
end
|
#images ⇒ Object
53
54
55
|
# File 'lib/openai/client.rb', line 53
def images
@images ||= OpenAI::Images.new(client: self)
end
|
#messages ⇒ Object
69
70
71
|
# File 'lib/openai/client.rb', line 69
def messages
@messages ||= OpenAI::Messages.new(client: self)
end
|
#models ⇒ Object
57
58
59
|
# File 'lib/openai/client.rb', line 57
def models
@models ||= OpenAI::Models.new(client: self)
end
|
#moderations(parameters: {}) ⇒ Object
81
82
83
|
# File 'lib/openai/client.rb', line 81
def moderations(parameters: {})
json_post(path: "/moderations", parameters: parameters)
end
|
#run_steps ⇒ Object
77
78
79
|
# File 'lib/openai/client.rb', line 77
def run_steps
@run_steps ||= OpenAI::RunSteps.new(client: self)
end
|
#runs ⇒ Object
73
74
75
|
# File 'lib/openai/client.rb', line 73
def runs
@runs ||= OpenAI::Runs.new(client: self)
end
|
#threads ⇒ Object
65
66
67
|
# File 'lib/openai/client.rb', line 65
def threads
@threads ||= OpenAI::Threads.new(client: self)
end
|