sawara 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: 458a9864b8cbbd7d4122608612f9282b1ca6adbbdbbf431faa879215f01f41aa
4
+ data.tar.gz: 14e1a18199efa5d09f82ebdb6ffc483ccf6cfcedc09c47c1b323bfc10a8f2cab
5
+ SHA512:
6
+ metadata.gz: 328d34fee8546615568397b8f0e99540eeb638cd565ca8168c50923e2a99f00908f1ada67ac74a01c652fdedb8f93c61a64e275413c93678d45b456571c13d8a
7
+ data.tar.gz: 5dffa179894a0d330c05574f4af0c889c1ca23b2122138bcd4521e9ed2b3befdf898a0c6b865ddaae90ca2288221ad3c3ced6556025de07d0c9982d4d08d1487
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.1
4
+
5
+ Style/Documentation:
6
+ Enabled: false
7
+
8
+ Style/StringLiterals:
9
+ Enabled: true
10
+ EnforcedStyle: single_quotes
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ Enabled: true
14
+ EnforcedStyle: single_quotes
15
+
16
+ Layout/LineLength:
17
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-03-03
4
+
5
+ - Initial release
@@ -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 yocajii@stone.sakura.ne.jp. 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 sawara.gemspec
6
+ # gemspec
7
+
8
+ gem 'byebug'
9
+ gem 'rake'
10
+ gem 'rspec'
11
+ gem 'rubocop'
12
+ gem 'ruby-openai'
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ast (2.4.2)
5
+ byebug (11.1.3)
6
+ diff-lcs (1.5.0)
7
+ httparty (0.21.0)
8
+ mini_mime (>= 1.0.0)
9
+ multi_xml (>= 0.5.2)
10
+ json (2.6.3)
11
+ mini_mime (1.1.2)
12
+ multi_xml (0.6.0)
13
+ parallel (1.22.1)
14
+ parser (3.2.1.0)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.1.1)
17
+ rake (13.0.6)
18
+ regexp_parser (2.7.0)
19
+ rexml (3.2.5)
20
+ rspec (3.12.0)
21
+ rspec-core (~> 3.12.0)
22
+ rspec-expectations (~> 3.12.0)
23
+ rspec-mocks (~> 3.12.0)
24
+ rspec-core (3.12.1)
25
+ rspec-support (~> 3.12.0)
26
+ rspec-expectations (3.12.2)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.12.0)
29
+ rspec-mocks (3.12.3)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-support (3.12.0)
33
+ rubocop (1.47.0)
34
+ json (~> 2.3)
35
+ parallel (~> 1.10)
36
+ parser (>= 3.2.0.0)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml (>= 3.2.5, < 4.0)
40
+ rubocop-ast (>= 1.26.0, < 2.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 2.4.0, < 3.0)
43
+ rubocop-ast (1.27.0)
44
+ parser (>= 3.2.1.0)
45
+ ruby-openai (3.5.0)
46
+ httparty (>= 0.18.1)
47
+ ruby-progressbar (1.13.0)
48
+ unicode-display_width (2.4.2)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ byebug
55
+ rake
56
+ rspec
57
+ rubocop
58
+ ruby-openai
59
+
60
+ BUNDLED WITH
61
+ 2.4.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 yocajii
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,38 @@
1
+ # Sawara
2
+
3
+ Sawara is a Ruby Gem for using ChatGPT in your terminal via OpenAI API.
4
+
5
+ ## Installation
6
+
7
+ $ gem install sawara
8
+
9
+ ## Initial setup
10
+
11
+ 1. Get your API key from [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys)
12
+ 2. `$ sawara`
13
+ 3. Enter your API Key.
14
+
15
+ ## Usage
16
+
17
+ Executing `sawara` initiates a conversation with ChatGPT.
18
+ ```
19
+ $ sawara
20
+ ```
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ 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).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yocajii/sawara. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yocajii/sawara/blob/main/CODE_OF_CONDUCT.md).
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
35
+
36
+ ## Code of Conduct
37
+
38
+ Everyone interacting in the sawara project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sawara/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/exe/sawara ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'sawara'
5
+
6
+ config = Sawara::Config.new
7
+ client = Sawara::ChatClient.new(config)
8
+ Sawara::Talk.new.start(client)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openai'
4
+
5
+ module Sawara
6
+ class ChatClient
7
+ def initialize(user_config)
8
+ api_key = user_config.api_key
9
+ OpenAI.configure do |config|
10
+ config.access_token = api_key
11
+ end
12
+ @openai_client = OpenAI::Client.new
13
+ end
14
+
15
+ def fetch(messages)
16
+ response = @openai_client.chat(
17
+ parameters: { model: 'gpt-3.5-turbo', messages: }
18
+ )
19
+ response.dig('choices', 0, 'message', 'content')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'yaml/store'
5
+
6
+ module Sawara
7
+ class Config
8
+ CONFIG_PATH = "#{Dir.home}/.sawara".freeze
9
+
10
+ def initialize
11
+ unless File.exist? CONFIG_PATH
12
+ File.new(CONFIG_PATH, 'w')
13
+ update_config
14
+ end
15
+ @config = load_config
16
+ end
17
+
18
+ def api_key
19
+ @config['api_key']
20
+ end
21
+
22
+ private
23
+
24
+ def load_config
25
+ YAML.load_file(CONFIG_PATH)
26
+ end
27
+
28
+ def update_config
29
+ puts 'Enter your OpenAI API Key.'
30
+ api_key = $stdin.gets
31
+ store = YAML::Store.new CONFIG_PATH
32
+ store.transaction do
33
+ store['api_key'] = api_key
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'byebug'
4
+
5
+ module Sawara
6
+ class Talk
7
+ def initialize
8
+ @messages = []
9
+ end
10
+
11
+ def start(client)
12
+ display_header
13
+
14
+ loop do
15
+ user_content = await_user_content
16
+ break if user_content.empty?
17
+
18
+ await_assistant_content(client)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def display_header
25
+ hints = <<~MSG
26
+ Hint 1: To send your message, press "Enter" and "Ctrl + d".
27
+ Hint 2: To exit this conversation, press "Ctrl + d" without any message.
28
+ MSG
29
+ puts
30
+ puts 'C h a t G P T C L I'.center(80)
31
+ puts '*' * 80
32
+ puts hints
33
+ puts '*' * 80
34
+ end
35
+
36
+ def await_user_content
37
+ puts
38
+ print 'You: '
39
+ content = $stdin.readlines.join
40
+ @messages << { role: 'user', content: }
41
+ content
42
+ end
43
+
44
+ def await_assistant_content(client)
45
+ puts
46
+ print 'Vanilla: '
47
+ content = client.fetch(@messages).sub!(/^\R/, '')
48
+ @messages << { role: 'assistant', content: }
49
+ puts content
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sawara
4
+ VERSION = '0.1.0'
5
+ end
data/lib/sawara.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sawara/chat_client'
4
+ require_relative 'sawara/config'
5
+ require_relative 'sawara/talk'
6
+ require_relative 'sawara/version'
7
+
8
+ module Sawara
9
+ class Error < StandardError; end
10
+ end
@@ -0,0 +1,4 @@
1
+ class ChatgptCli
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sawara
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yocajii
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Use ChatGPT in Terminal via OpenAI API.
14
+ email:
15
+ - yocajii@stone.sakura.ne.jp
16
+ executables:
17
+ - sawara
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - exe/sawara
31
+ - lib/sawara.rb
32
+ - lib/sawara/chat_client.rb
33
+ - lib/sawara/config.rb
34
+ - lib/sawara/talk.rb
35
+ - lib/sawara/version.rb
36
+ - sig/chatgpt_cli.rbs
37
+ homepage: https://github.com/yocajii/sawara
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://github.com/yocajii/sawara
42
+ source_code_uri: https://github.com/yocajii/sawara
43
+ changelog_uri: https://github.com/yocajii/sawara/blob/main/CHANGELOG.md
44
+ rubygems_mfa_required: 'true'
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.1.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.4.7
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: This is ChatGPT CLI.
64
+ test_files: []