-
Notifications
You must be signed in to change notification settings - Fork 6
API Reference
Nagendra Dhanakeerthi edited this page Oct 30, 2024
·
2 revisions
ChatGPT::Client.new(api_key = nil)Creates a new client instance. If api_key is nil, uses the configured global API key.
client.chat(messages, params = {})Parameters:
-
messages: Array of message hashes withroleandcontent -
params: Optional parameters hash
# Example params
{
model: 'gpt-3.5-turbo', # Optional, defaults to configured value
temperature: 0.7, # Optional, defaults to 0.5
max_tokens: 100, # Optional, defaults to 16
top_p: 1.0, # Optional
n: 1 # Optional, number of responses
}client.chat_stream(messages, params = {}) { |chunk| ... }Same parameters as chat, but requires a block for handling chunks.
client.completions(prompt, params = {})Parameters:
-
prompt: String prompt for completion -
params: Optional parameters hash
# Example params
{
engine: 'text-davinci-002', # Optional
max_tokens: 50, # Optional
temperature: 0.7, # Optional
top_p: 0.9, # Optional
n: 1 # Optional
}ChatGPT.configure do |config|
config.api_key = 'your-key'
config.default_engine = 'text-davinci-002'
config.request_timeout = 30
config.max_retries = 3
end