Sha256: fd22e43816a637676618b71b2dae269f3916616c0b21101a97ed2802138b3418

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 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(
          parameters: default_parameters.merge(prompt: prompt),
        )

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

      private

      def default_parameters
        {
          model: 'code-davinci-002',
          temperature: 0,
          max_tokens: 512,
          top_p: 1,
          frequency_penalty: 0,
          presence_penalty: 0,
          stop: ["\n\n"],
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
openai-please-0.2.0 lib/please/openai/codex_service.rb