Module: QuickOpenAI::Gpt3

Defined in:
lib/quick_openai/gpt3.rb

Class Method Summary collapse

Class Method Details

.gpt3(prompt, **options) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/quick_openai/gpt3.rb', line 5

def self.gpt3(prompt, **options)
  parameters = {
    model: "gpt-3.5-turbo-instruct",
    max_tokens: 2048,
    prompt: prompt,
    **options
  }

  response = QuickOpenAI.fetch_response_from_client do |client|
    client.completions(parameters: parameters)
  end

  text = response.dig("choices", 0, "text")

  raise QuickOpenAI::Error, "Unable to parse response." if text.nil? || text.empty?

  text.chomp.strip
end