gpt4all 0.0.1
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +30 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +126 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +12 -0
- data/gpt4all.gemspec +38 -0
- data/lib/gpt4all/conversational_ai.rb +172 -0
- data/lib/gpt4all/version.rb +5 -0
- data/lib/gpt4all.rb +8 -0
- data/sig/gpt4all.rbs +27 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f611f3c03de174c0bbc7ff1cf009569c8f2b4405cb4cead51fdafc367559fcd9
|
|
4
|
+
data.tar.gz: 376a1e7c1100b5368d4fd6a00ad7226c7b9def1510aae6fb7af2b3629d3fe860
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8be39a0889515dd33171fb73db9905edde1f8f68872b389268ec19a3352761202a3da2f524d3a18a777d8f5b032f151ed9e62656655d736e83ad4bce357f2a17
|
|
7
|
+
data.tar.gz: 03e6ea52397c7426081333ec3b36f4d274e2df259f55afdd2eea0dc376f1df7ae7e1781afd03a58223a88ea8c8c35156fed5e5b37bbe5d328cf35eeb7ae4e571
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-performance
|
|
3
|
+
- rubocop-sequel
|
|
4
|
+
|
|
5
|
+
AllCops:
|
|
6
|
+
NewCops: enable
|
|
7
|
+
TargetRubyVersion: 3.2
|
|
8
|
+
Exclude:
|
|
9
|
+
- db/**/*.rb
|
|
10
|
+
- bin/**/*.rb
|
|
11
|
+
- bin/*
|
|
12
|
+
- vendor/**/*
|
|
13
|
+
- coverage/**/*
|
|
14
|
+
|
|
15
|
+
Metrics/BlockLength:
|
|
16
|
+
Exclude:
|
|
17
|
+
- spec/support/shared_contexts/*.rb
|
|
18
|
+
- spec/support/shared_examples/*.rb
|
|
19
|
+
- spec/**/*_spec.rb
|
|
20
|
+
- spec/factories/*.rb
|
|
21
|
+
|
|
22
|
+
Style/Documentation:
|
|
23
|
+
Enabled: false
|
|
24
|
+
|
|
25
|
+
Style/HashSyntax:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Style/RescueModifier:
|
|
29
|
+
Exclude:
|
|
30
|
+
- spec/**/*_spec.rb
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2023-04-07
|
|
10
|
+
|
|
11
|
+
- Initial release
|
data/Gemfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in gpt4all.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
gem 'rake', '~> 13.0'
|
|
9
|
+
|
|
10
|
+
gem 'rspec', '~> 3.0'
|
|
11
|
+
|
|
12
|
+
gem 'rubocop', '~> 1.21'
|
|
13
|
+
|
|
14
|
+
gem 'brakeman'
|
|
15
|
+
gem 'bundler-audit'
|
|
16
|
+
gem 'byebug'
|
|
17
|
+
gem 'dotenv'
|
|
18
|
+
gem 'license_finder'
|
|
19
|
+
gem 'overcommit'
|
|
20
|
+
gem 'rubocop-performance'
|
|
21
|
+
gem 'rubocop-sequel'
|
|
22
|
+
gem 'rubocop-shopify'
|
|
23
|
+
|
|
24
|
+
gem 'webmock', require: false
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
gpt4all (0.0.1)
|
|
5
|
+
faraday (~> 2.7)
|
|
6
|
+
os (~> 1.1)
|
|
7
|
+
tty-progressbar (~> 0.18.2)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
addressable (2.8.3)
|
|
13
|
+
public_suffix (>= 2.0.2, < 6.0)
|
|
14
|
+
ast (2.4.2)
|
|
15
|
+
brakeman (5.4.1)
|
|
16
|
+
bundler-audit (0.9.1)
|
|
17
|
+
bundler (>= 1.2.0, < 3)
|
|
18
|
+
thor (~> 1.0)
|
|
19
|
+
byebug (11.1.3)
|
|
20
|
+
childprocess (4.1.0)
|
|
21
|
+
crack (0.4.5)
|
|
22
|
+
rexml
|
|
23
|
+
diff-lcs (1.5.0)
|
|
24
|
+
dotenv (2.8.1)
|
|
25
|
+
faraday (2.7.4)
|
|
26
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
27
|
+
ruby2_keywords (>= 0.0.4)
|
|
28
|
+
faraday-net_http (3.0.2)
|
|
29
|
+
hashdiff (1.0.1)
|
|
30
|
+
iniparse (1.5.0)
|
|
31
|
+
json (2.6.3)
|
|
32
|
+
license_finder (7.1.0)
|
|
33
|
+
bundler
|
|
34
|
+
rubyzip (>= 1, < 3)
|
|
35
|
+
thor (~> 1.2)
|
|
36
|
+
tomlrb (>= 1.3, < 2.1)
|
|
37
|
+
with_env (= 1.1.0)
|
|
38
|
+
xml-simple (~> 1.1.9)
|
|
39
|
+
os (1.1.4)
|
|
40
|
+
overcommit (0.60.0)
|
|
41
|
+
childprocess (>= 0.6.3, < 5)
|
|
42
|
+
iniparse (~> 1.4)
|
|
43
|
+
rexml (~> 3.2)
|
|
44
|
+
parallel (1.22.1)
|
|
45
|
+
parser (3.2.2.0)
|
|
46
|
+
ast (~> 2.4.1)
|
|
47
|
+
public_suffix (5.0.1)
|
|
48
|
+
rainbow (3.1.1)
|
|
49
|
+
rake (13.0.6)
|
|
50
|
+
regexp_parser (2.7.0)
|
|
51
|
+
rexml (3.2.5)
|
|
52
|
+
rspec (3.12.0)
|
|
53
|
+
rspec-core (~> 3.12.0)
|
|
54
|
+
rspec-expectations (~> 3.12.0)
|
|
55
|
+
rspec-mocks (~> 3.12.0)
|
|
56
|
+
rspec-core (3.12.1)
|
|
57
|
+
rspec-support (~> 3.12.0)
|
|
58
|
+
rspec-expectations (3.12.2)
|
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
60
|
+
rspec-support (~> 3.12.0)
|
|
61
|
+
rspec-mocks (3.12.5)
|
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
63
|
+
rspec-support (~> 3.12.0)
|
|
64
|
+
rspec-support (3.12.0)
|
|
65
|
+
rubocop (1.49.0)
|
|
66
|
+
json (~> 2.3)
|
|
67
|
+
parallel (~> 1.10)
|
|
68
|
+
parser (>= 3.2.0.0)
|
|
69
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
70
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
71
|
+
rexml (>= 3.2.5, < 4.0)
|
|
72
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
73
|
+
ruby-progressbar (~> 1.7)
|
|
74
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
75
|
+
rubocop-ast (1.28.0)
|
|
76
|
+
parser (>= 3.2.1.0)
|
|
77
|
+
rubocop-performance (1.16.0)
|
|
78
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
79
|
+
rubocop-ast (>= 0.4.0)
|
|
80
|
+
rubocop-sequel (0.3.4)
|
|
81
|
+
rubocop (~> 1.0)
|
|
82
|
+
rubocop-shopify (2.12.0)
|
|
83
|
+
rubocop (~> 1.44)
|
|
84
|
+
ruby-progressbar (1.13.0)
|
|
85
|
+
ruby2_keywords (0.0.5)
|
|
86
|
+
rubyzip (2.3.2)
|
|
87
|
+
strings-ansi (0.2.0)
|
|
88
|
+
thor (1.2.1)
|
|
89
|
+
tomlrb (2.0.3)
|
|
90
|
+
tty-cursor (0.7.1)
|
|
91
|
+
tty-progressbar (0.18.2)
|
|
92
|
+
strings-ansi (~> 0.2)
|
|
93
|
+
tty-cursor (~> 0.7)
|
|
94
|
+
tty-screen (~> 0.8)
|
|
95
|
+
unicode-display_width (>= 1.6, < 3.0)
|
|
96
|
+
tty-screen (0.8.1)
|
|
97
|
+
unicode-display_width (2.4.2)
|
|
98
|
+
webmock (3.18.1)
|
|
99
|
+
addressable (>= 2.8.0)
|
|
100
|
+
crack (>= 0.3.2)
|
|
101
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
102
|
+
with_env (1.1.0)
|
|
103
|
+
xml-simple (1.1.9)
|
|
104
|
+
rexml
|
|
105
|
+
|
|
106
|
+
PLATFORMS
|
|
107
|
+
arm64-darwin-22
|
|
108
|
+
|
|
109
|
+
DEPENDENCIES
|
|
110
|
+
brakeman
|
|
111
|
+
bundler-audit
|
|
112
|
+
byebug
|
|
113
|
+
dotenv
|
|
114
|
+
gpt4all!
|
|
115
|
+
license_finder
|
|
116
|
+
overcommit
|
|
117
|
+
rake (~> 13.0)
|
|
118
|
+
rspec (~> 3.0)
|
|
119
|
+
rubocop (~> 1.21)
|
|
120
|
+
rubocop-performance
|
|
121
|
+
rubocop-sequel
|
|
122
|
+
rubocop-shopify
|
|
123
|
+
webmock
|
|
124
|
+
|
|
125
|
+
BUNDLED WITH
|
|
126
|
+
2.4.10
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jaigouk Kim
|
|
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,45 @@
|
|
|
1
|
+
# Gpt4all
|
|
2
|
+
|
|
3
|
+
Gpt4all is a Ruby gem that provides an easy-to-use interface for interacting with the GPT-4 conversational AI model.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'gpt4all'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ bundle install
|
|
17
|
+
```
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
$ gem install gpt4all
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
To use the Gpt4all gem, you can follow these steps:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require 'gpt4all'
|
|
30
|
+
|
|
31
|
+
gpt4all = Gpt4all::ConversationalAI.new
|
|
32
|
+
gpt4all.prepare_resources(force_download: true)
|
|
33
|
+
gpt4all.start_bot
|
|
34
|
+
|
|
35
|
+
response = gpt4all.prompt('What is your name?')
|
|
36
|
+
puts response
|
|
37
|
+
|
|
38
|
+
gpt4all.stop_bot
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Development
|
|
42
|
+
|
|
43
|
+
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.
|
|
44
|
+
|
|
45
|
+
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 tags, and push the .gem file to rubygems.org.
|
data/Rakefile
ADDED
data/gpt4all.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/gpt4all/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'gpt4all'
|
|
7
|
+
spec.version = Gpt4all::VERSION
|
|
8
|
+
spec.authors = ['Jaigouk Kim']
|
|
9
|
+
spec.email = ['ping@jaigouk.kim']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'gpt4all'
|
|
12
|
+
spec.description = 'interface to gpt4all'
|
|
13
|
+
spec.homepage = 'https://github.com/jaigouk/gpt4all'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.2'
|
|
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/jaigouk/gpt4all'
|
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/jaigouk/gpt4all/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(__dir__) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = 'exe'
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ['lib']
|
|
33
|
+
|
|
34
|
+
spec.add_dependency 'faraday', '~> 2.7'
|
|
35
|
+
spec.add_dependency 'os', '~> 1.1'
|
|
36
|
+
spec.add_dependency 'tty-progressbar', '~> 0.18.2'
|
|
37
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
38
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'open3'
|
|
5
|
+
require 'os'
|
|
6
|
+
require 'faraday'
|
|
7
|
+
require 'tty-progressbar'
|
|
8
|
+
|
|
9
|
+
module Gpt4all
|
|
10
|
+
# rubocop:disable Metrics/ClassLength
|
|
11
|
+
class ConversationalAI
|
|
12
|
+
attr_accessor :bot, :model, :decoder_config, :executable_path, :model_path, :force_download, :test_mode
|
|
13
|
+
|
|
14
|
+
OSX_INTEL_URL = 'https://github.com/nomic-ai/gpt4all/blob/main/chat/gpt4all-lora-quantized-OSX-intel?raw=true'
|
|
15
|
+
OSX_M1_URL = 'https://github.com/nomic-ai/gpt4all/blob/main/chat/gpt4all-lora-quantized-OSX-m1?raw=true'
|
|
16
|
+
LINUX_URL = 'https://github.com/nomic-ai/gpt4all/blob/main/chat/gpt4all-lora-quantized-linux-x86?raw=true'
|
|
17
|
+
WINDOWS_URL = 'https://github.com/nomic-ai/gpt4all/blob/main/chat/gpt4all-lora-quantized-win64.exe?raw=true'
|
|
18
|
+
|
|
19
|
+
# rubocop:disable Metrics/MethodLength
|
|
20
|
+
def initialize(model: 'gpt4all-lora-quantized', force_download: false, decoder_config: {})
|
|
21
|
+
@bot = nil
|
|
22
|
+
@model = model
|
|
23
|
+
@decoder_config = decoder_config
|
|
24
|
+
@executable_path = "#{Dir.home}/.nomic/gpt4all"
|
|
25
|
+
@model_path = "#{Dir.home}/.nomic/#{model}.bin"
|
|
26
|
+
@force_download = force_download
|
|
27
|
+
@test_mode = false
|
|
28
|
+
|
|
29
|
+
return unless %w[gpt4all-lora-quantized gpt4all-lora-unfiltered-quantized].none?(model)
|
|
30
|
+
|
|
31
|
+
raise "Model #{model} is not supported. Current models supported are:
|
|
32
|
+
gpt4all-lora-quantized
|
|
33
|
+
gpt4all-lora-unfiltered-quantized"
|
|
34
|
+
end
|
|
35
|
+
# rubocop:enable Metrics/MethodLength
|
|
36
|
+
|
|
37
|
+
def prepare_resources(force_download: false)
|
|
38
|
+
download_promises = []
|
|
39
|
+
|
|
40
|
+
download_promises << download_executable if force_download || !File.exist?(executable_path)
|
|
41
|
+
download_promises << download_model if force_download || !File.exist?(model_path)
|
|
42
|
+
|
|
43
|
+
download_promises.compact.each(&:call)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def start_bot
|
|
47
|
+
stop_bot if bot
|
|
48
|
+
|
|
49
|
+
spawn_args = [executable_path, '--model', model_path]
|
|
50
|
+
|
|
51
|
+
decoder_config.each do |key, value|
|
|
52
|
+
spawn_args.push("--#{key}", value.to_s)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
@bot = Open3.popen2e(*spawn_args)
|
|
56
|
+
@bot_pid = bot.last.pid
|
|
57
|
+
|
|
58
|
+
wait_for_bot_ready
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def stop_bot
|
|
62
|
+
return unless bot
|
|
63
|
+
|
|
64
|
+
bot.each(&:close)
|
|
65
|
+
@bot = nil
|
|
66
|
+
@bot_pid = nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def download_executable
|
|
70
|
+
upstream = determine_upstream_url
|
|
71
|
+
download_file(upstream, executable_path)
|
|
72
|
+
FileUtils.chmod(0o755, executable_path)
|
|
73
|
+
puts "File downloaded successfully to #{executable_path}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def determine_upstream_url
|
|
77
|
+
if OS.mac?
|
|
78
|
+
OS.host_cpu == 'x86_64' ? OSX_INTEL_URL : OSX_M1_URL
|
|
79
|
+
elsif OS.linux?
|
|
80
|
+
LINUX_URL
|
|
81
|
+
elsif OS.windows?
|
|
82
|
+
WINDOWS_URL
|
|
83
|
+
else
|
|
84
|
+
raise 'Unsupported platform. Supported: OSX (ARM and Intel), Linux, Windows.'
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def download_model
|
|
89
|
+
model_url = "https://the-eye.eu/public/AI/models/nomic-ai/gpt4all/#{model}.bin"
|
|
90
|
+
|
|
91
|
+
download_file(model_url, model_path)
|
|
92
|
+
|
|
93
|
+
puts "File downloaded successfully to #{model_path}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def download_file(url, destination)
|
|
97
|
+
response = create_faraday_connection(url)
|
|
98
|
+
total_size = response.headers['Content-Length'].to_i
|
|
99
|
+
create_destination_directory(destination)
|
|
100
|
+
download_with_progress_bar(response, destination, total_size)
|
|
101
|
+
puts "File downloaded successfully to #{destination}"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def create_faraday_connection(url)
|
|
105
|
+
connection = Faraday.new(url) do |f|
|
|
106
|
+
f.response :raise_error
|
|
107
|
+
f.adapter Faraday.default_adapter
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
connection.get do |request|
|
|
111
|
+
request.headers['Accept-Encoding'] = 'identity'
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def create_destination_directory(destination)
|
|
116
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def download_with_progress_bar(response, destination, total_size)
|
|
120
|
+
progress_bar = TTY::ProgressBar.new(
|
|
121
|
+
'[:bar] :percent :etas',
|
|
122
|
+
complete: '=',
|
|
123
|
+
incomplete: ' ',
|
|
124
|
+
width: 20,
|
|
125
|
+
total: total_size
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
write_chunks_to_file(response, destination, progress_bar)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def write_chunks_to_file(response, destination, progress_bar)
|
|
132
|
+
File.open(destination, 'wb') do |file|
|
|
133
|
+
response.body.each_chunk do |chunk|
|
|
134
|
+
progress_bar.advance(chunk.bytesize)
|
|
135
|
+
file.write(chunk)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def wait_for_bot_ready
|
|
141
|
+
loop do
|
|
142
|
+
output = bot.last.gets
|
|
143
|
+
break if output&.include?('>')
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def prompt(input)
|
|
148
|
+
ensure_bot_is_ready
|
|
149
|
+
|
|
150
|
+
begin
|
|
151
|
+
bot.first.puts(input)
|
|
152
|
+
response = bot.last.gets.strip
|
|
153
|
+
rescue StandardError => e
|
|
154
|
+
puts "Error during prompt: #{e.message}"
|
|
155
|
+
restart_bot
|
|
156
|
+
response = prompt(input)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
response
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def ensure_bot_is_ready
|
|
163
|
+
raise 'Bot is not initialized.' unless bot
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def restart_bot
|
|
167
|
+
stop_bot
|
|
168
|
+
start_bot
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
# rubocop:enable Metrics/ClassLength
|
|
172
|
+
end
|
data/lib/gpt4all.rb
ADDED
data/sig/gpt4all.rbs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Gpt4all
|
|
2
|
+
VERSION: String
|
|
3
|
+
|
|
4
|
+
class ConversationalAI
|
|
5
|
+
@bot: Process::Child | nil
|
|
6
|
+
@model: String
|
|
7
|
+
@decoder_config: Hash[String, untyped]
|
|
8
|
+
@executable_path: String
|
|
9
|
+
@model_path: String
|
|
10
|
+
|
|
11
|
+
def initialize: (String? model, bool? force_download, Hash[String, untyped]? decoder_config) -> void
|
|
12
|
+
|
|
13
|
+
def init: (?bool force_download) -> void
|
|
14
|
+
|
|
15
|
+
def open: () -> void
|
|
16
|
+
|
|
17
|
+
def close: () -> void
|
|
18
|
+
|
|
19
|
+
private def download_executable: () -> void
|
|
20
|
+
|
|
21
|
+
private def download_model: () -> void
|
|
22
|
+
|
|
23
|
+
private def download_file: (String url, String destination) -> void
|
|
24
|
+
|
|
25
|
+
def prompt: (String input) -> String
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gpt4all
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jaigouk Kim
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-04-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.7'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.7'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: os
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.1'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.1'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: tty-progressbar
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.18.2
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.18.2
|
|
55
|
+
description: interface to gpt4all
|
|
56
|
+
email:
|
|
57
|
+
- ping@jaigouk.kim
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".rspec"
|
|
63
|
+
- ".rubocop.yml"
|
|
64
|
+
- CHANGELOG.md
|
|
65
|
+
- Gemfile
|
|
66
|
+
- Gemfile.lock
|
|
67
|
+
- LICENSE.txt
|
|
68
|
+
- README.md
|
|
69
|
+
- Rakefile
|
|
70
|
+
- gpt4all.gemspec
|
|
71
|
+
- lib/gpt4all.rb
|
|
72
|
+
- lib/gpt4all/conversational_ai.rb
|
|
73
|
+
- lib/gpt4all/version.rb
|
|
74
|
+
- sig/gpt4all.rbs
|
|
75
|
+
homepage: https://github.com/jaigouk/gpt4all
|
|
76
|
+
licenses:
|
|
77
|
+
- MIT
|
|
78
|
+
metadata:
|
|
79
|
+
allowed_push_host: https://rubygems.org
|
|
80
|
+
homepage_uri: https://github.com/jaigouk/gpt4all
|
|
81
|
+
source_code_uri: https://github.com/jaigouk/gpt4all
|
|
82
|
+
changelog_uri: https://github.com/jaigouk/gpt4all/CHANGELOG.md
|
|
83
|
+
rubygems_mfa_required: 'true'
|
|
84
|
+
post_install_message:
|
|
85
|
+
rdoc_options: []
|
|
86
|
+
require_paths:
|
|
87
|
+
- lib
|
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '3.2'
|
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
requirements: []
|
|
99
|
+
rubygems_version: 3.4.10
|
|
100
|
+
signing_key:
|
|
101
|
+
specification_version: 4
|
|
102
|
+
summary: gpt4all
|
|
103
|
+
test_files: []
|