termpilot 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: 4e4a484bd4f496557a819f238c658e150aa2a84d31f02fb968aae58c4e1972d6
4
+ data.tar.gz: 1e3c8c41cf4308ef0b0aa1220fa3dcb9ee03453e4f424b262b6a78ae9c8b9adf
5
+ SHA512:
6
+ metadata.gz: b5b693f5421a0d137f91cdc1ba7420c41a8aba46a7a9fd9ce84235a9cd48ba58acbdce000da0a54940fb5dc7fe7e865447c057648468a6e367cbdf061c3e023c
7
+ data.tar.gz: 2bfd59ad9e93736ae2bcff331f440e9ada198efd1525f75367d9691deddc47a9487ea315c6adade22237c18bad62764445910a0d75f97576183d0aa47b769dac
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # termpilot
2
+
3
+ Termpilot is a cli tool that mimics the AI mode in the Warp terminal. So it will turn a less
4
+ RAM-hungry terminal emulator into a janky Warp-like terminal. It is written in Ruby and uses
5
+ the OpenAI API to generate responses from ChatGPT 3.5 by default.
6
+
7
+ ## Installation
8
+
9
+ Clone the repo, `cd` into it's directory, and run `./bin/install.sh`. You will also need a
10
+ OpenAI API key, which you can get by signing up for the OpenAI API. Place this key in your
11
+ `.zshrc` or `.bashrc` file as `OPENAI_API_KEY`.
12
+
13
+ ## Usage
14
+
15
+ Simply type `termpilot` followed by a space and your terminal command question. The more
16
+ concise and simple you are, the better. Termpilot should return a response from ChatGPT with
17
+ just the terminal command. This command is then automatically copied to your clipboard.
18
+
19
+ ### License
20
+
21
+ whatever.
data/bin/termpilot ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/termpilot'
5
+
6
+ query = ARGV.join(' ')
7
+
8
+ Termpilot.run query
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openai'
4
+
5
+ # Service to interact with OpenAI API
6
+ module Services
7
+ class OpenaiService
8
+ def self.chat(query)
9
+ access_token = ENV.fetch('OPENAI_ACCESS_TOKEN')
10
+ client = OpenAI::Client.new(access_token:)
11
+
12
+ query = prepare_query(query)
13
+
14
+ response = client.chat(
15
+ parameters: {
16
+ model: 'gpt-3.5-turbo',
17
+ messages: [{ role: 'user', content: query }],
18
+ temperature: 0.7
19
+ }
20
+ )
21
+
22
+ response_text = response.dig('choices', 0, 'message', 'content')
23
+
24
+ copy_to_clipboard(response_text)
25
+ puts response_text
26
+ end
27
+
28
+ def self.prepare_query(query)
29
+ "I want you to respond only wth the code snippet or terminal command I ask
30
+ for, nothing else. No other text, only the code or command. I would like to know the command to #{query}"
31
+ end
32
+
33
+ # Only works on macOS
34
+ def self.copy_to_clipboard(data)
35
+ IO.popen('pbcopy', 'w') { |pbcopy| pbcopy << data }
36
+ end
37
+ end
38
+ end
data/lib/termpilot.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'services/openai_service'
4
+
5
+ # Entry point for the Termpilot gem
6
+ class Termpilot
7
+ def self.run(query)
8
+ Services::OpenaiService.chat(query)
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: termpilot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Taylor Collins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-05-10 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: 6.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 6.5.0
27
+ description: A wrapper around ChatGPT to allow for prompts in the terminal.
28
+ email:
29
+ - taylorcc33@gmail.com
30
+ executables:
31
+ - termpilot
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - bin/termpilot
37
+ - lib/services/openai_service.rb
38
+ - lib/termpilot.rb
39
+ homepage: https://github.com/taylorcc33/termpilot
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.3.26
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: A wrapper around ChatGPT to allow for prompts in the terminal.
62
+ test_files: []