openai-please 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 88db2eab8d2aafb7387f3f13b7da57ec499f85ab25c75b51a2ee342c4a0fa5c1
4
+ data.tar.gz: f50f4df10b90b1ab68543a9fb14a6494d47a33bccaf3fa54e829c43fe6215caa
5
+ SHA512:
6
+ metadata.gz: 692f1d6e44402e12d6fa59a7733b7b6620323be48f8ef999b367616a917d53262ee8bc1aeb9f4628a583978fea77f653536112f2c2a29b2eaddb915feb28f8d7
7
+ data.tar.gz: 675d9326b5e682e7d45c36162ec1fb52ea6487058843a274f8e75eb9cf8505fc5759241987f7f986bcf2bc13570ebbfa81ee1abed16864d024a98a6c77501b47
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ OPENAI_ACCESS_TOKEN=[YOUR ACCESS_TOKEN HERE]
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: single_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/TrailingCommaInHashLiteral:
15
+ Enabled: true
16
+ EnforcedStyleForMultiline: comma
17
+
18
+ Style/TrailingCommaInArguments:
19
+ Enabled: true
20
+ EnforcedStyleForMultiline: comma
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Layout/LineLength:
26
+ Max: 120
data/Dockerfile ADDED
@@ -0,0 +1,11 @@
1
+ FROM ruby:3
2
+
3
+ WORKDIR /app
4
+
5
+ RUN apt-get update -y && apt-get install vim nano -y
6
+
7
+ COPY Gemfile Gemfile.lock please.gemspec ./
8
+ COPY lib/please/version.rb ./lib/please/version.rb
9
+ RUN bundle install
10
+
11
+ COPY ./ ./
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in please.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'minitest', '~> 5.0'
11
+
12
+ gem 'rubocop', '~> 1.7'
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ please (0.1.0)
5
+ ruby-openai (>= 1.3)
6
+ tty-prompt (>= 0.23)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ dotenv (2.7.6)
13
+ httparty (0.18.1)
14
+ mime-types (~> 3.0)
15
+ multi_xml (>= 0.5.2)
16
+ mime-types (3.3.1)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2021.0901)
19
+ minitest (5.14.4)
20
+ multi_xml (0.6.0)
21
+ parallel (1.21.0)
22
+ parser (3.0.2.0)
23
+ ast (~> 2.4.1)
24
+ pastel (0.8.0)
25
+ tty-color (~> 0.5)
26
+ rainbow (3.0.0)
27
+ rake (13.0.6)
28
+ regexp_parser (2.1.1)
29
+ rexml (3.2.5)
30
+ rubocop (1.21.0)
31
+ parallel (~> 1.10)
32
+ parser (>= 3.0.0.0)
33
+ rainbow (>= 2.2.2, < 4.0)
34
+ regexp_parser (>= 1.8, < 3.0)
35
+ rexml
36
+ rubocop-ast (>= 1.9.1, < 2.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 3.0)
39
+ rubocop-ast (1.11.0)
40
+ parser (>= 3.0.1.1)
41
+ ruby-openai (1.3.1)
42
+ dotenv (~> 2.7.6)
43
+ httparty (~> 0.18.1)
44
+ ruby-progressbar (1.11.0)
45
+ tty-color (0.6.0)
46
+ tty-cursor (0.7.1)
47
+ tty-prompt (0.23.1)
48
+ pastel (~> 0.8)
49
+ tty-reader (~> 0.8)
50
+ tty-reader (0.9.0)
51
+ tty-cursor (~> 0.7)
52
+ tty-screen (~> 0.8)
53
+ wisper (~> 2.0)
54
+ tty-screen (0.8.1)
55
+ unicode-display_width (2.0.0)
56
+ wisper (2.0.1)
57
+
58
+ PLATFORMS
59
+ x86_64-linux
60
+
61
+ DEPENDENCIES
62
+ minitest (~> 5.0)
63
+ please!
64
+ rake (~> 13.0)
65
+ rubocop (~> 1.7)
66
+
67
+ BUNDLED WITH
68
+ 2.2.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Please
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/please`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'please'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install please
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/please.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ require 'rubocop/rake_task'
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'please'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ version: '3'
2
+
3
+ services:
4
+ please:
5
+ build: .
6
+ tty: true
7
+ stdin_open: true
8
+ env_file: .env
9
+ volumes:
10
+ - '.:/app'
data/exe/please ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'please/cli'
data/lib/please/cli.rb ADDED
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty-prompt'
4
+ require 'optparse'
5
+ require 'please'
6
+ require 'tempfile'
7
+
8
+ tty_prompt = TTY::Prompt.new
9
+
10
+ options = {}
11
+
12
+ USAGE = 'Usage: please [options] <instruction>'
13
+
14
+ OptionParser.new do |opts|
15
+ opts.banner = USAGE
16
+ end.parse!
17
+
18
+ access_token = ENV.fetch('OPENAI_ACCESS_TOKEN') do
19
+ tty_prompt.error 'Ensure the OPENAI_ACCESS_TOKEN environment variable is set'
20
+ exit 1
21
+ end
22
+
23
+ codex_service = Please::OpenAI::CodexService.new(access_token: access_token)
24
+
25
+ instruction = ARGV.join(' ')
26
+
27
+ if instruction.empty?
28
+ tty_prompt.error USAGE
29
+ exit 1
30
+ end
31
+
32
+ request = Please::Request.new(
33
+ options: options,
34
+ instruction: instruction,
35
+ codex_service: codex_service,
36
+ )
37
+
38
+ command = request.send
39
+
40
+ loop do
41
+ print '$ '
42
+ tty_prompt.ok command
43
+
44
+ action = tty_prompt.expand('Run the command?') do |q|
45
+ q.choice key: 'y', name: 'Yes', value: :run
46
+ q.choice key: 'n', name: 'No', value: :abort
47
+ q.choice key: 'e', name: 'Edit command before running', value: :edit
48
+ end
49
+
50
+ case action
51
+ when :run
52
+ Process.wait spawn(command)
53
+ exit $?.exitstatus
54
+ when :abort
55
+ break
56
+ when :edit
57
+ Tempfile.open('command') do |file|
58
+ file << command
59
+ file.flush
60
+
61
+ Process.wait spawn("${EDITOR:-vi} #{file.path}")
62
+
63
+ file.rewind
64
+ command = file.read.chomp
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby/openai'
4
+
5
+ module Please
6
+ module OpenAI
7
+ CodexService = Struct.new(:access_token, keyword_init: true) do
8
+ def completion(prompt)
9
+ client = ::OpenAI::Client.new(access_token: access_token)
10
+
11
+ response = client.completions(
12
+ engine: 'davinci-codex',
13
+ parameters: default_parameters.merge(
14
+ prompt: prompt,
15
+ ),
16
+ )
17
+
18
+ response.parsed_response.fetch('choices').first.fetch('text')
19
+ end
20
+
21
+ private
22
+
23
+ def default_parameters
24
+ {
25
+ temperature: 0,
26
+ max_tokens: 300,
27
+ top_p: 1,
28
+ frequency_penalty: 0,
29
+ presence_penalty: 0,
30
+ stop: ["\n"],
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Please
4
+ Request = Struct.new(:options, :instruction, :codex_service, keyword_init: true) do
5
+ def send
6
+ codex_service.completion(<<~PROMPT.chomp).strip
7
+ Write a one-line bash command each of the following tasks.
8
+
9
+ # Print the current working directory
10
+ $ pwd
11
+ #{`pwd`}
12
+
13
+ # Show information about the operating system
14
+ $ uname -a
15
+ #{`uname -a`}
16
+
17
+ # List all files in the current directory
18
+ $ ls -a
19
+ #{`ls -a`}
20
+
21
+ # #{instruction.gsub(/\n/, " ")}
22
+ $
23
+ PROMPT
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Please
4
+ VERSION = '0.1.0'
5
+ end
data/lib/please.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'please/version'
4
+ require_relative 'please/request'
5
+ require_relative 'please/openai/codex_service'
6
+
7
+ module Please
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
data/please.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/please/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'openai-please'
7
+ spec.version = Please::VERSION
8
+ spec.authors = ['Joe Anderson']
9
+ spec.email = ['joe@osbert.me']
10
+
11
+ spec.summary = 'Convert natural language to bash commands using OpenAI Codex'
12
+ spec.homepage = 'https://github.com/12joan/please'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = '>= 3.0'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ # Uncomment to register a new dependency of your gem
29
+ spec.add_dependency 'ruby-openai', '>= 1.3'
30
+ spec.add_dependency 'tty-prompt', '>= 0.23'
31
+
32
+ # For more information and examples about making a new gem, checkout our
33
+ # guide at: https://bundler.io/guides/creating_gem.html
34
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openai-please
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe Anderson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-openai
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-prompt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.23'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.23'
41
+ description:
42
+ email:
43
+ - joe@osbert.me
44
+ executables:
45
+ - please
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".env.example"
50
+ - ".gitignore"
51
+ - ".rubocop.yml"
52
+ - Dockerfile
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - docker-compose.yml
61
+ - exe/please
62
+ - lib/please.rb
63
+ - lib/please/cli.rb
64
+ - lib/please/openai/codex_service.rb
65
+ - lib/please/request.rb
66
+ - lib/please/version.rb
67
+ - please.gemspec
68
+ homepage: https://github.com/12joan/please
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://github.com/12joan/please
73
+ source_code_uri: https://github.com/12joan/please
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.2.22
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Convert natural language to bash commands using OpenAI Codex
93
+ test_files: []