Sha256: 673abd02a52ad1e36425ac913669fe3bdf26f1a2b80e11be43095c7a3fb29a65

Contents?: true

Size: 757 Bytes

Versions: 2

Compression:

Stored size: 757 Bytes

Contents

# frozen_string_literal: true

require 'ruby/openai'

module Please
  module OpenAI
    CodexService = Struct.new(:access_token, keyword_init: true) do
      def completion(prompt)
        client = ::OpenAI::Client.new(access_token: access_token)

        response = client.completions(
          engine: 'davinci-codex',
          parameters: default_parameters.merge(
            prompt: prompt,
          ),
        )

        response.parsed_response.fetch('choices').first.fetch('text')
      end

      private

      def default_parameters
        {
          temperature: 0,
          max_tokens: 512,
          top_p: 1,
          frequency_penalty: 0,
          presence_penalty: 0,
          stop: ["\n\n"],
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openai-please-0.1.3 lib/please/openai/codex_service.rb
openai-please-0.1.2 lib/please/openai/codex_service.rb