llm-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e2e9fc38a9233a89d2dab2deddca4a2ceb7ab0346669538e24a8490e67e194e3
4
+ data.tar.gz: e3d374d69c869e1af56a98a605a43ca585dfd1a245e4c05ead57199770b057c6
5
+ SHA512:
6
+ metadata.gz: 552cf244e394e895973ab4773028a719694f6e351db07aa6649888d6d626378058e3e892df6c978eed0c58fdb6fa139e6546158d3858cbade707bb81a9e5ebb3
7
+ data.tar.gz: d3e8b166150333424d101ee272f825fc8d5b6eee2d5d44dfa5d84169be779da4c5ec7c15f404564661494e19fc3a7d4d16a0cc0682f7b2597f6c0bb6071540e9
@@ -0,0 +1 @@
1
+ model: gpt-4
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at chris@petersen.io. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
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 llm-cli.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "standard", "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ llm-cli (0.0.1)
5
+ json
6
+ ruby-openai (~> 4.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ diff-lcs (1.5.0)
13
+ faraday (2.12.0)
14
+ faraday-net_http (>= 2.0, < 3.4)
15
+ json
16
+ logger
17
+ faraday-multipart (1.0.4)
18
+ multipart-post (~> 2)
19
+ faraday-net_http (3.3.0)
20
+ net-http
21
+ json (2.6.3)
22
+ language_server-protocol (3.17.0.3)
23
+ lint_roller (1.0.0)
24
+ logger (1.6.1)
25
+ multipart-post (2.4.1)
26
+ net-http (0.4.1)
27
+ uri
28
+ parallel (1.23.0)
29
+ parser (3.2.2.1)
30
+ ast (~> 2.4.1)
31
+ rainbow (3.1.1)
32
+ rake (13.0.6)
33
+ regexp_parser (2.8.0)
34
+ rexml (3.2.5)
35
+ rspec (3.12.0)
36
+ rspec-core (~> 3.12.0)
37
+ rspec-expectations (~> 3.12.0)
38
+ rspec-mocks (~> 3.12.0)
39
+ rspec-core (3.12.2)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-expectations (3.12.3)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-mocks (3.12.5)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.12.0)
47
+ rspec-support (3.12.0)
48
+ rubocop (1.52.0)
49
+ json (~> 2.3)
50
+ parallel (~> 1.10)
51
+ parser (>= 3.2.0.0)
52
+ rainbow (>= 2.2.2, < 4.0)
53
+ regexp_parser (>= 1.8, < 3.0)
54
+ rexml (>= 3.2.5, < 4.0)
55
+ rubocop-ast (>= 1.28.0, < 2.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (>= 2.4.0, < 3.0)
58
+ rubocop-ast (1.29.0)
59
+ parser (>= 3.2.1.0)
60
+ rubocop-performance (1.18.0)
61
+ rubocop (>= 1.7.0, < 2.0)
62
+ rubocop-ast (>= 0.4.0)
63
+ ruby-openai (4.3.2)
64
+ faraday (>= 1)
65
+ faraday-multipart (>= 1)
66
+ ruby-progressbar (1.13.0)
67
+ standard (1.29.0)
68
+ language_server-protocol (~> 3.17.0.2)
69
+ lint_roller (~> 1.0)
70
+ rubocop (~> 1.52.0)
71
+ standard-custom (~> 1.0.0)
72
+ standard-performance (~> 1.1.0)
73
+ standard-custom (1.0.1)
74
+ lint_roller (~> 1.0)
75
+ standard-performance (1.1.0)
76
+ lint_roller (~> 1.0)
77
+ rubocop-performance (~> 1.18.0)
78
+ unicode-display_width (2.4.2)
79
+ uri (0.13.1)
80
+
81
+ PLATFORMS
82
+ arm64-darwin-21
83
+ arm64-darwin-23
84
+
85
+ DEPENDENCIES
86
+ llm-cli!
87
+ rake (~> 13.0)
88
+ rspec (~> 3.0)
89
+ standard (~> 1.3)
90
+
91
+ BUNDLED WITH
92
+ 2.3.8
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Chris Petersen
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,22 @@
1
+ # Llm::Cli
2
+
3
+ llm-cli is a ruby gem that adds an `llm` command to your shell.
4
+
5
+ ## Installation
6
+
7
+ First, you need to install the gem. You can do this globally or in your specific Ruby environment.
8
+
9
+ ```sh
10
+ gem install llm-cli
11
+ ```
12
+
13
+ Once installed, it will be accessible the `llm` command
14
+
15
+ ## Usage
16
+
17
+ You can invoke the `llm` command in your terminal:
18
+
19
+
20
+ ```sh
21
+ llm
22
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
data/exe/llm ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'llm/cli'
4
+
5
+ Llm::CLI.new.run(ARGV)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Llm
4
+ module Cli
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
data/lib/llm/cli.rb ADDED
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rbconfig'
4
+ require 'yaml'
5
+ require 'json'
6
+ require 'openai'
7
+
8
+ module Llm
9
+ class Error < StandardError; end
10
+ class CLI
11
+
12
+ def os_info
13
+ host_os = RbConfig::CONFIG['host_os']
14
+
15
+ case host_os
16
+ when /linux/
17
+ os_name = "Linux"
18
+ when /darwin/
19
+ os_name = "Mac"
20
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
21
+ os_name = "Windows"
22
+ else
23
+ os_name = "Unknown"
24
+ end
25
+
26
+ version = RbConfig::CONFIG['host_os']
27
+
28
+ { os_name: os_name, version: version }
29
+ end
30
+
31
+ def run(argv=nil)
32
+ os = os_info
33
+ prompt = "You are a systems engineer working on #{os[:os_name]} (version #{os[:version]}). Your job is to write a shell commands. Please return your best guess as a single command that can be directly executed. If you must, you may include a short note, but please use comments so the results are directly executable. Please write a command that will:\n"
34
+
35
+ config = {
36
+ "model" => "gpt-4o",
37
+ "temperature" => 0.7,
38
+ "prompt" => prompt,
39
+ "openai_api_key" => ENV["OPENAI_API_KEY"],
40
+ "openai_organization_id" => ENV["OPENAI_ORGANIZATION_ID"]
41
+ }
42
+ config_filename = find_file(".llm-cli-config.yml")
43
+ config_file = YAML.load_file(".llm-cli-config.yml") if config_filename
44
+ config.merge!(config_file) if config_file
45
+
46
+ if config["openai_api_key"].nil?
47
+ puts "Please set OPENAI_API_KEY environment variable"
48
+ exit 1
49
+ end
50
+
51
+ prompt = config["prompt"] + (argv || []).join(" ")
52
+
53
+ client = OpenAI::Client.new(access_token: config["openai_api_key"], organization_id: config["openai_organization_id"])
54
+ response = client.chat(
55
+ parameters: {
56
+ model: config["model"],
57
+ temperature: config["temperature"],
58
+ messages: [{ role: "user", content: prompt }]
59
+ }
60
+ )
61
+ puts response.dig("choices", 0, "message", "content")
62
+ end
63
+
64
+ # Find the closest .llm-cli-config.yml file in the current directory, any parent directory or the users home directory
65
+ def find_file(filename)
66
+ paths = []
67
+ path_pieces = Dir.pwd.split(File::SEPARATOR)
68
+ while path_pieces.any?
69
+ path = path_pieces.join(File::SEPARATOR)
70
+ path_pieces.pop
71
+ paths << [path, filename].join(File::SEPARATOR)
72
+ end
73
+ paths << [ENV["HOME"], filename].join(File::SEPARATOR) if ENV["HOME"]
74
+ result = paths.detect { |path| File.exist?(path) }
75
+ result
76
+ end
77
+ end
78
+ end
data/llm-cli.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/llm/cli/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "llm-cli"
7
+ spec.version = Llm::Cli::VERSION
8
+ spec.authors = ["Chris Petersen"]
9
+ spec.email = ["chris@petersen.io"]
10
+
11
+ spec.summary = "Use ChatGPT to write your shell commands"
12
+ spec.description = "Use ChatGPT to write your shell commands"
13
+ spec.homepage = "https://github.com/cpetersen/llm-cli"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/cpetersen/llm-cli"
21
+ spec.metadata["changelog_uri"] = "https://github.com/cpetersen/llm-cli/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ # spec.executables = spec.files.grep(%r{bin/llm}) { |f| File.basename(f) }
32
+ # spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.executables = ["llm"]
34
+ spec.require_paths = ["lib"]
35
+
36
+ # Uncomment to register a new dependency of your gem
37
+ # spec.add_development_dependency "rspec"
38
+ # spec.add_dependency "thor"
39
+ spec.add_dependency "json"
40
+ spec.add_dependency "ruby-openai", "~> 4.0"
41
+
42
+ # For more information and examples about making a new gem, check out our
43
+ # guide at: https://bundler.io/guides/creating_gem.html
44
+ end
data/sig/git/gpt.rbs ADDED
@@ -0,0 +1,6 @@
1
+ module Llm
2
+ module Cli
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: llm-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Petersen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-openai
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ description: Use ChatGPT to write your shell commands
42
+ email:
43
+ - chris@petersen.io
44
+ executables:
45
+ - llm
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".llm-cli-config.yml"
50
+ - ".rspec"
51
+ - ".standard.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - exe/llm
59
+ - lib/llm/cli.rb
60
+ - lib/llm/cli/version.rb
61
+ - llm-cli.gemspec
62
+ - sig/git/gpt.rbs
63
+ homepage: https://github.com/cpetersen/llm-cli
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ allowed_push_host: https://rubygems.org
68
+ homepage_uri: https://github.com/cpetersen/llm-cli
69
+ source_code_uri: https://github.com/cpetersen/llm-cli
70
+ changelog_uri: https://github.com/cpetersen/llm-cli/CHANGELOG.md
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.6.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.5.18
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Use ChatGPT to write your shell commands
90
+ test_files: []