Module: GPT

Defined in:
lib/gpt.rb,
lib/gpt.rb,
lib/gpt/client.rb,
lib/gpt/version.rb,
lib/gpt/responses.rb,
lib/gpt/response_extender.rb

Defined Under Namespace

Modules: ResponseExtender Classes: Client, Error, Responses

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.ask(prompt, model: 'gpt-5', stream: false, text_stream: false, **opts, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gpt.rb', line 22

def self.ask(prompt, model: 'gpt-5', stream: false, text_stream: false, **opts, &block)
  payload = { 'model' => model, 'input' => prompt }
  opts.each { |k, v| payload[k.to_s] = v }
  if stream
    responses.stream(payload) do |chunk|
      yield chunk if block_given?
    end
  elsif text_stream
    responses.stream_text(payload) do |text|
      yield text if block_given?
    end
  else
    res = responses.create(payload)
    res.extend(ResponseExtender)
    res
  end
end

.clientObject



14
15
16
# File 'lib/gpt.rb', line 14

def self.client
  @client ||= Client.new
end

.responsesObject



18
19
20
# File 'lib/gpt.rb', line 18

def self.responses
  @responses ||= Responses.new(client)
end