Sha256: fb6289b9fb3c2b793145e95b185bff16a573a772bdb191a08cd50e572ffef435

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

Stored size: 755 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: 300,
          top_p: 1,
          frequency_penalty: 0,
          presence_penalty: 0,
          stop: ["\n"],
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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