Sha256: c76cc4e9a8f440e7c211ed408a1bc9af79aec40d5a81f875a63d97745d76a21a

Contents?: true

Size: 543 Bytes

Versions: 3

Compression:

Stored size: 543 Bytes

Contents

# frozen_string_literal: true

module QuickOpenAI
  module Gpt3
    def self.gpt3(prompt, **options)
      parameters = {
        model: "text-davinci-003",
        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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
quick_openai-0.1.2 lib/quick_openai/gpt3.rb
quick_openai-0.1.1 lib/quick_openai/gpt3.rb
quick_openai-0.1.0 lib/quick_openai/gpt3.rb