Sha256: 5401cae01ffc90d793a5dd4ed910dfb0cf71ea512e2df41c7f12c5f114c58003

Contents?: true

Size: 752 Bytes

Versions: 2

Compression:

Stored size: 752 Bytes

Contents

# frozen_string_literal: true

module Please
  Request = Struct.new(:instruction, :codex_service, :context, keyword_init: true) do
    def send
      codex_service.completion(prompt)
        .strip
        # Collapse multiline commands into one line
        .gsub(/\s*\\\n\s*/, ' ')
        # Remove subsequent lines that do not contain commands
        .gsub(/\n[^$][^\n]*$/, '')
        # Collapse multiple commands into one line
        .gsub(/\n\$ /, '; ')
        # Remove multiple consecutive spaces
        .gsub(/\s+/, ' ')
    end

    def prompt
      <<~PROMPT.chomp
        Write a one-line bash command for each of the following tasks.

        #{context}

        # #{instruction.gsub(/\n/, " ")}
        $
      PROMPT
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openai-please-0.2.0 lib/please/request.rb
openai-please-0.1.3 lib/please/request.rb