rbs_goose 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +9 -2
  3. data/.ruby-version +1 -1
  4. data/Gemfile +20 -13
  5. data/Gemfile.lock +96 -61
  6. data/README-ja.md +88 -0
  7. data/README.md +38 -28
  8. data/Rakefile +54 -14
  9. data/Steepfile +1 -3
  10. data/evaluations/01_rbs_goose/claude_haiku.log +1494 -0
  11. data/evaluations/01_rbs_goose/claude_opus.log +1439 -0
  12. data/evaluations/01_rbs_goose/claude_sonnet.log +1437 -0
  13. data/evaluations/01_rbs_goose/gpt-3-5-turbo.log +1241 -0
  14. data/evaluations/01_rbs_goose/gpt-4-turbo.log +1304 -0
  15. data/examples/fix_errors/Steepfile +6 -0
  16. data/examples/fix_errors/error_messages.txt +26 -0
  17. data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/lib/person.rb +4 -0
  18. data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/refined/sig/email.rbs +1 -1
  19. data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/refined/sig/person.rbs +4 -2
  20. data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/refined/sig/phone.rbs +1 -1
  21. data/examples/fix_errors/sig/email.rbs +11 -0
  22. data/examples/fix_errors/sig/person.rbs +15 -0
  23. data/examples/fix_errors/sig/phone.rbs +15 -0
  24. data/examples/rbs_samples/lib/email.rb +16 -0
  25. data/examples/rbs_samples/lib/person.rb +23 -0
  26. data/examples/rbs_samples/lib/phone.rb +22 -0
  27. data/examples/rbs_samples/refined/sig/email.rbs +11 -0
  28. data/examples/rbs_samples/refined/sig/person.rbs +15 -0
  29. data/examples/rbs_samples/refined/sig/phone.rbs +15 -0
  30. data/{lib/rbs_goose/examples → examples}/rbs_samples/sig/person.rbs +2 -0
  31. data/examples/rbs_syntax/Steepfile +6 -0
  32. data/examples/rbs_syntax/lib/a.rb +53 -0
  33. data/examples/rbs_syntax/lib/list.rb +9 -0
  34. data/examples/rbs_syntax/lib/main.rb +17 -0
  35. data/examples/rbs_syntax/refined/sig/a.rbs +47 -0
  36. data/examples/rbs_syntax/refined/sig/list.rbs +7 -0
  37. data/examples/rbs_syntax/refined/sig/main.rbs +26 -0
  38. data/examples/rbs_syntax/sig/a.rbs +47 -0
  39. data/examples/rbs_syntax/sig/list.rbs +7 -0
  40. data/examples/rbs_syntax/sig/main.rbs +26 -0
  41. data/lib/rbs_goose/configuration.rb +93 -23
  42. data/lib/rbs_goose/io/example.rb +2 -2
  43. data/lib/rbs_goose/io/example_group.rb +16 -7
  44. data/lib/rbs_goose/io/target_group.rb +1 -1
  45. data/lib/rbs_goose/io/typed_ruby.rb +3 -3
  46. data/lib/rbs_goose/orthoses/fix_error.rb +26 -0
  47. data/lib/rbs_goose/orthoses/infer.rb +26 -0
  48. data/lib/rbs_goose/orthoses.rb +9 -0
  49. data/lib/rbs_goose/templates/base.rb +77 -0
  50. data/lib/rbs_goose/templates/fix_error_template.rb +43 -0
  51. data/lib/rbs_goose/templates/infer_template.rb +30 -0
  52. data/lib/rbs_goose/templates.rb +3 -1
  53. data/lib/rbs_goose/type_inferrer.rb +73 -2
  54. data/lib/rbs_goose/version.rb +1 -1
  55. data/lib/rbs_goose.rb +24 -4
  56. data/rbs_collection.lock.yaml +63 -47
  57. data/renovate.json +5 -0
  58. data/sig/rbs_goose/configuration.rbs +20 -12
  59. data/sig/rbs_goose/io/example.rbs +7 -7
  60. data/sig/rbs_goose/io/example_group.rbs +9 -7
  61. data/sig/rbs_goose/io/file.rbs +10 -10
  62. data/sig/rbs_goose/io/target_group.rbs +2 -2
  63. data/sig/rbs_goose/io/typed_ruby.rbs +7 -7
  64. data/sig/rbs_goose/io.rbs +1 -1
  65. data/sig/rbs_goose/orthoses/fix_error.rbs +11 -0
  66. data/sig/rbs_goose/orthoses/infer.rbs +11 -0
  67. data/sig/rbs_goose/orthoses.rbs +2 -0
  68. data/sig/rbs_goose/templates/base.rbs +18 -0
  69. data/sig/rbs_goose/templates/fix_error_template.rbs +6 -0
  70. data/sig/rbs_goose/templates/infer_template.rbs +6 -0
  71. data/sig/rbs_goose/templates.rbs +1 -1
  72. data/sig/rbs_goose/type_inferrer.rbs +9 -1
  73. data/sig/rbs_goose.rbs +18 -9
  74. metadata +151 -23
  75. data/README-EN-US.md +0 -78
  76. data/lib/rbs_goose/templates/default_template.rb +0 -49
  77. data/sig/rbs_goose/templates/default_template.rbs +0 -10
  78. /data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/lib/email.rb +0 -0
  79. /data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/lib/phone.rb +0 -0
  80. /data/{lib/rbs_goose/examples → examples}/rbs_samples/Steepfile +0 -0
  81. /data/{lib/rbs_goose/examples → examples}/rbs_samples/sig/email.rbs +0 -0
  82. /data/{lib/rbs_goose/examples → examples}/rbs_samples/sig/phone.rbs +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf73d7a4ddd606fd157daf05a360724de91c45167bc05a3e170a5eb0c98630ad
4
- data.tar.gz: 62bd3b303be0b22fe0b5c1dfc470035e80e7494072abca2a3c2da460c0edffed
3
+ metadata.gz: 10bed3f0456e4a9262ed23aa377238af9fa6297fabc1792aac15146c6ef20325
4
+ data.tar.gz: 5b7ac52a808a4a62b71e9bb603f14c92d5dadb897b897fde004e9dcc1cbb9fff
5
5
  SHA512:
6
- metadata.gz: d011a72db8c5ba4d9823cf5e4af4fd6aa17c72b0fca9e9984da237697329b113d132e87a446f7e988a6858520066a297d008072d4dc82add618008fd89f4350b
7
- data.tar.gz: 19e5c359436f5aee963abf6406dac507a6047fd008b045833d688efda26cc681a9ebc759f3a16787850db20de55290dca09325b6ea4ac3fa4704ea100624e353
6
+ metadata.gz: 9f9e69a4443e9f08cb98f4282df0b4787f13a07563e74debea467da6216bb0e7034f9661c68896f1083e3edad2c9d61c2aa01c11b5864ca7368a1dd9abcd5d48
7
+ data.tar.gz: c92d6b1a3c4ac8b6988a8b33192b44a41404cc0e122d13323e945d2a44ba08a39bc261aa33b3c5c99bd9bc45d83c1d24f0702a1412880bafa542ebf6346747e8
data/.rubocop.yml CHANGED
@@ -4,13 +4,17 @@ require:
4
4
  - rubocop-rspec
5
5
 
6
6
  AllCops:
7
- TargetRubyVersion: 3.0
7
+ TargetRubyVersion: 3.3
8
8
  NewCops: enable
9
9
  Exclude:
10
- - 'lib/rbs_goose/examples/**/*'
10
+ - 'examples/**/*'
11
11
  - 'spec/fixtures/**/*'
12
12
  - 'vendor/bundle/**/*'
13
13
 
14
+ Metrics/BlockLength:
15
+ Exclude:
16
+ - Rakefile
17
+
14
18
  Style/StringLiterals:
15
19
  Enabled: true
16
20
 
@@ -38,5 +42,8 @@ RSpec/MultipleMemoizedHelpers:
38
42
  RSpec/MultipleExpectations:
39
43
  Max: 5
40
44
 
45
+ RSpec/NestedGroups:
46
+ Max: 4
47
+
41
48
  FactoryBot/FactoryAssociationWithStrategy:
42
49
  Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.0
1
+ 3.3.1
data/Gemfile CHANGED
@@ -5,16 +5,23 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in rbs_goose.gemspec
6
6
  gemspec
7
7
 
8
- gem 'dotenv', '~> 2.8.1'
9
- gem 'factory_bot', '~> 6.4.5'
10
- gem 'orthoses', '~> 1.13.0'
11
- gem 'rake', '~> 13.0'
12
- gem 'rspec', '~> 3.0'
13
- gem 'rubocop', '~> 1.21'
14
- gem 'rubocop-factory_bot', '~> 2.25.1'
15
- gem 'rubocop-rake', '~> 0.6.0'
16
- gem 'rubocop-rspec', '~> 2.22'
17
- gem 'ruby-openai', '~> 6.1.0'
18
- gem 'steep', '~> 1.6.0'
19
- gem 'vcr', '~> 6.2.0'
20
- gem 'webmock', '~> 3.18.1'
8
+ group :development, :test do
9
+ gem 'anthropic', '~> 0.2.0', require: false
10
+ gem 'dotenv', '~> 3.1.0', require: false
11
+ gem 'factory_bot', '~> 6.4.5', require: false
12
+ gem 'faraday', '~> 2.9.0', require: false
13
+ gem 'orthoses', '~> 1.13.0', require: false
14
+ gem 'rake', '~> 13.0', require: false
15
+ gem 'rspec', '~> 3.0', require: false
16
+ gem 'rubocop', '~> 1.21', require: false
17
+ gem 'rubocop-factory_bot', '~> 2.25.1', require: false
18
+ gem 'rubocop-rake', '~> 0.6.0', require: false
19
+ gem 'rubocop-rspec', '~> 2.22', require: false
20
+ gem 'ruby-openai', '~> 7.0.0', require: false
21
+ gem 'simplecov', require: false
22
+ gem 'simplecov-cobertura', require: false
23
+ gem 'simplecov-html', github: 'kokuyouwind/simplecov-html', ref: '132805391cda353'
24
+ gem 'steep', '~> 1.6.0', require: false
25
+ gem 'vcr', '~> 6.2.0', require: false
26
+ gem 'webmock', '~> 3.23.0', require: false
27
+ end
data/Gemfile.lock CHANGED
@@ -1,15 +1,26 @@
1
+ GIT
2
+ remote: https://github.com/kokuyouwind/simplecov-html.git
3
+ revision: 132805391cda353dedb59bdb1f4fbe0b8af789bc
4
+ ref: 132805391cda353
5
+ specs:
6
+ simplecov-html (0.12.3)
7
+
1
8
  PATH
2
9
  remote: .
3
10
  specs:
4
- rbs_goose (0.1.0)
5
- langchainrb (~> 0.8.2)
6
- ruby-openai (~> 6.1.0)
11
+ rbs_goose (0.2.0)
12
+ anthropic (>= 0.2.0, < 1.0.0)
13
+ faraday (>= 2.9.0, < 3.0.0)
14
+ langchainrb (>= 0.12.0, < 1.0.0)
15
+ orthoses (>= 1.13.0, < 2.0.0)
16
+ ruby-openai (>= 6.1.0, < 8.0.0)
17
+ steep (>= 1.6.0, < 2.0.0)
7
18
 
8
19
  GEM
9
20
  remote: https://rubygems.org/
10
21
  specs:
11
22
  abbrev (0.1.2)
12
- activesupport (7.1.2)
23
+ activesupport (7.1.3)
13
24
  base64
14
25
  bigdecimal
15
26
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -19,46 +30,52 @@ GEM
19
30
  minitest (>= 5.1)
20
31
  mutex_m
21
32
  tzinfo (~> 2.0)
22
- addressable (2.8.4)
33
+ addressable (2.8.6)
23
34
  public_suffix (>= 2.0.2, < 6.0)
35
+ anthropic (0.2.0)
36
+ faraday (>= 1)
37
+ faraday-multipart (>= 1)
24
38
  ast (2.4.2)
25
39
  baran (0.1.10)
26
40
  base64 (0.2.0)
27
- bigdecimal (3.1.5)
28
- colorize (0.8.1)
29
- concurrent-ruby (1.2.2)
41
+ bigdecimal (3.1.6)
42
+ colorize (1.1.0)
43
+ concurrent-ruby (1.2.3)
30
44
  connection_pool (2.4.1)
31
- crack (0.4.5)
45
+ crack (0.4.6)
46
+ bigdecimal
32
47
  rexml
33
48
  csv (3.2.8)
34
- diff-lcs (1.5.0)
35
- dotenv (2.8.1)
49
+ diff-lcs (1.5.1)
50
+ docile (1.4.0)
51
+ dotenv (3.1.2)
36
52
  drb (2.2.0)
37
53
  ruby2_keywords
38
- event_stream_parser (0.3.0)
39
- factory_bot (6.4.5)
54
+ event_stream_parser (1.0.0)
55
+ factory_bot (6.4.6)
40
56
  activesupport (>= 5.0.0)
41
- faraday (2.7.9)
42
- faraday-net_http (>= 2.0, < 3.1)
43
- ruby2_keywords (>= 0.0.4)
57
+ faraday (2.9.0)
58
+ faraday-net_http (>= 2.0, < 3.2)
44
59
  faraday-multipart (1.0.4)
45
60
  multipart-post (~> 2)
46
- faraday-net_http (3.0.2)
61
+ faraday-net_http (3.1.0)
62
+ net-http
47
63
  ffi (1.16.3)
48
64
  fileutils (1.7.2)
49
- hashdiff (1.0.1)
65
+ hashdiff (1.1.0)
50
66
  i18n (1.14.1)
51
67
  concurrent-ruby (~> 1.0)
52
- json (2.6.3)
68
+ json (2.7.2)
53
69
  json-schema (4.0.0)
54
70
  addressable (>= 2.8)
55
- langchainrb (0.8.2)
71
+ langchainrb (0.12.0)
72
+ activesupport (>= 7.0.8)
56
73
  baran (~> 0.1.9)
57
- colorize (~> 0.8.1)
58
- json-schema (~> 4.0.0)
74
+ colorize (~> 1.1.0)
75
+ json-schema (~> 4)
59
76
  matrix
60
77
  pragmatic_segmenter (~> 0.3.0)
61
- tiktoken_ruby (~> 0.0.5)
78
+ tiktoken_ruby (~> 0.0.8)
62
79
  to_bool (~> 2.0.0)
63
80
  zeitwerk (~> 2.5)
64
81
  language_server-protocol (3.17.0.3)
@@ -67,72 +84,84 @@ GEM
67
84
  rb-inotify (~> 0.9, >= 0.9.10)
68
85
  logger (1.6.0)
69
86
  matrix (0.4.2)
70
- minitest (5.21.1)
71
- multipart-post (2.3.0)
87
+ minitest (5.21.2)
88
+ multipart-post (2.4.0)
72
89
  mutex_m (0.2.0)
90
+ net-http (0.4.1)
91
+ uri
73
92
  orthoses (1.13.0)
74
93
  rbs (~> 3.0)
75
- parallel (1.23.0)
76
- parser (3.2.2.3)
94
+ parallel (1.24.0)
95
+ parser (3.3.1.0)
77
96
  ast (~> 2.4.1)
78
97
  racc
79
98
  pragmatic_segmenter (0.3.23)
80
99
  unicode
81
- public_suffix (5.0.1)
82
- racc (1.7.1)
100
+ public_suffix (5.0.4)
101
+ racc (1.7.3)
83
102
  rainbow (3.1.1)
84
- rake (13.0.6)
103
+ rake (13.2.1)
85
104
  rb-fsevent (0.11.2)
86
105
  rb-inotify (0.10.1)
87
106
  ffi (~> 1.0)
88
- rb_sys (0.9.86)
89
107
  rbs (3.4.1)
90
108
  abbrev
91
- regexp_parser (2.8.1)
92
- rexml (3.2.5)
93
- rspec (3.12.0)
94
- rspec-core (~> 3.12.0)
95
- rspec-expectations (~> 3.12.0)
96
- rspec-mocks (~> 3.12.0)
97
- rspec-core (3.12.2)
98
- rspec-support (~> 3.12.0)
99
- rspec-expectations (3.12.3)
109
+ regexp_parser (2.9.0)
110
+ rexml (3.2.6)
111
+ rspec (3.13.0)
112
+ rspec-core (~> 3.13.0)
113
+ rspec-expectations (~> 3.13.0)
114
+ rspec-mocks (~> 3.13.0)
115
+ rspec-core (3.13.0)
116
+ rspec-support (~> 3.13.0)
117
+ rspec-expectations (3.13.0)
100
118
  diff-lcs (>= 1.2.0, < 2.0)
101
- rspec-support (~> 3.12.0)
102
- rspec-mocks (3.12.5)
119
+ rspec-support (~> 3.13.0)
120
+ rspec-mocks (3.13.0)
103
121
  diff-lcs (>= 1.2.0, < 2.0)
104
- rspec-support (~> 3.12.0)
105
- rspec-support (3.12.1)
106
- rubocop (1.53.1)
122
+ rspec-support (~> 3.13.0)
123
+ rspec-support (3.13.0)
124
+ rubocop (1.63.4)
107
125
  json (~> 2.3)
108
126
  language_server-protocol (>= 3.17.0)
109
127
  parallel (~> 1.10)
110
- parser (>= 3.2.2.3)
128
+ parser (>= 3.3.0.2)
111
129
  rainbow (>= 2.2.2, < 4.0)
112
130
  regexp_parser (>= 1.8, < 3.0)
113
131
  rexml (>= 3.2.5, < 4.0)
114
- rubocop-ast (>= 1.28.0, < 2.0)
132
+ rubocop-ast (>= 1.31.1, < 2.0)
115
133
  ruby-progressbar (~> 1.7)
116
134
  unicode-display_width (>= 2.4.0, < 3.0)
117
- rubocop-ast (1.29.0)
118
- parser (>= 3.2.1.0)
119
- rubocop-capybara (2.18.0)
135
+ rubocop-ast (1.31.3)
136
+ parser (>= 3.3.1.0)
137
+ rubocop-capybara (2.20.0)
120
138
  rubocop (~> 1.41)
121
139
  rubocop-factory_bot (2.25.1)
122
140
  rubocop (~> 1.41)
123
141
  rubocop-rake (0.6.0)
124
142
  rubocop (~> 1.0)
125
- rubocop-rspec (2.22.0)
126
- rubocop (~> 1.33)
143
+ rubocop-rspec (2.29.2)
144
+ rubocop (~> 1.40)
127
145
  rubocop-capybara (~> 2.17)
128
146
  rubocop-factory_bot (~> 2.22)
129
- ruby-openai (6.1.0)
130
- event_stream_parser (>= 0.3.0, < 1.0.0)
147
+ rubocop-rspec_rails (~> 2.28)
148
+ rubocop-rspec_rails (2.28.3)
149
+ rubocop (~> 1.40)
150
+ ruby-openai (7.0.1)
151
+ event_stream_parser (>= 0.3.0, < 2.0.0)
131
152
  faraday (>= 1)
132
153
  faraday-multipart (>= 1)
133
154
  ruby-progressbar (1.13.0)
134
155
  ruby2_keywords (0.0.5)
135
156
  securerandom (0.3.1)
157
+ simplecov (0.22.0)
158
+ docile (~> 1.1)
159
+ simplecov-html (~> 0.11)
160
+ simplecov_json_formatter (~> 0.1)
161
+ simplecov-cobertura (2.1.0)
162
+ rexml
163
+ simplecov (~> 0.19)
164
+ simplecov_json_formatter (0.1.4)
136
165
  steep (1.6.0)
137
166
  activesupport (>= 5.1)
138
167
  concurrent-ruby (>= 1.1.10)
@@ -151,15 +180,16 @@ GEM
151
180
  strscan (3.0.8)
152
181
  terminal-table (3.0.2)
153
182
  unicode-display_width (>= 1.1.1, < 3)
154
- tiktoken_ruby (0.0.6)
155
- rb_sys (~> 0.9.68)
183
+ tiktoken_ruby (0.0.8-arm64-darwin)
184
+ tiktoken_ruby (0.0.8-x86_64-linux)
156
185
  to_bool (2.0.0)
157
186
  tzinfo (2.0.6)
158
187
  concurrent-ruby (~> 1.0)
159
188
  unicode (0.4.4.4)
160
- unicode-display_width (2.4.2)
189
+ unicode-display_width (2.5.0)
190
+ uri (0.13.0)
161
191
  vcr (6.2.0)
162
- webmock (3.18.1)
192
+ webmock (3.23.0)
163
193
  addressable (>= 2.8.0)
164
194
  crack (>= 0.3.2)
165
195
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -171,8 +201,10 @@ PLATFORMS
171
201
  x86_64-linux
172
202
 
173
203
  DEPENDENCIES
174
- dotenv (~> 2.8.1)
204
+ anthropic (~> 0.2.0)
205
+ dotenv (~> 3.1.0)
175
206
  factory_bot (~> 6.4.5)
207
+ faraday (~> 2.9.0)
176
208
  orthoses (~> 1.13.0)
177
209
  rake (~> 13.0)
178
210
  rbs_goose!
@@ -181,10 +213,13 @@ DEPENDENCIES
181
213
  rubocop-factory_bot (~> 2.25.1)
182
214
  rubocop-rake (~> 0.6.0)
183
215
  rubocop-rspec (~> 2.22)
184
- ruby-openai (~> 6.1.0)
216
+ ruby-openai (~> 7.0.0)
217
+ simplecov
218
+ simplecov-cobertura
219
+ simplecov-html!
185
220
  steep (~> 1.6.0)
186
221
  vcr (~> 6.2.0)
187
- webmock (~> 3.18.1)
222
+ webmock (~> 3.23.0)
188
223
 
189
224
  BUNDLED WITH
190
225
  2.4.10
data/README-ja.md ADDED
@@ -0,0 +1,88 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/kokuyouwind/rbs_goose/main/assets/logo.svg" alt="RuboCop Logo"/>
3
+ </p>
4
+
5
+ [![en-US README](https://img.shields.io/badge/Multilingual_README-en--US-blue.svg)](/README.md)
6
+ [![ja-JP README](https://img.shields.io/badge/Multilingual_README-ja--JP-orangered.svg)](/README-ja.md)
7
+
8
+ [![CI](https://github.com/kokuyouwind/rbs_goose/actions/workflows/main.yml/badge.svg)](https://github.com/kokuyouwind/rbs_goose/actions/workflows/main.yml)
9
+ [![Gem Version](https://badge.fury.io/rb/rbs_goose.svg)](https://badge.fury.io/rb/rbs_goose)
10
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/d05ed2e4fa5e565f87f5/test_coverage)](https://codeclimate.com/github/kokuyouwind/rbs_goose/test_coverage)
11
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d05ed2e4fa5e565f87f5/maintainability)](https://codeclimate.com/github/kokuyouwind/rbs_goose/maintainability)
12
+
13
+ RBS Goose は ChatGPT などの大規模言語モデルを利用して、 Ruby コードの RBS シグニチャを推測するツールです。
14
+
15
+ > [!CAUTION]
16
+ > 現在は技術検証中のため、適切な型がほとんど、あるいは全く出力されない可能性があります。
17
+ > また推測にあたっては ChatGPT API などを利用するため、コード規模によっては利用料が高額になる可能性があります。
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ $ gem install rbs_goose
23
+ # 利用する LangChain LLM に応じて、対応する gem を合わせてインストールします
24
+ $ gem install ruby-openai
25
+ ```
26
+
27
+ `bundler` を利用する場合は、代わりに以下を `Gemfile` に追加してください。
28
+
29
+ ```ruby
30
+ gem 'rbs_goose'
31
+ # 利用する LangChain LLM に応じて、対応する gem を合わせてインストールします
32
+ gem 'ruby-openai'
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ 現状ではコマンドラインツールが未整備なので、 `Rakefile` などから `RbsGoose.run` を直接呼び出してください。
38
+
39
+ [OpenAI API](https://openai.com/blog/openai-api) を利用する場合は以下のようにします。
40
+
41
+ ```ruby
42
+ require 'rbs_goose'
43
+ require 'openai'
44
+
45
+ desc 'refine RBS files in sig directory'
46
+ task :refine do
47
+ RbsGoose.configure do |c|
48
+ c.use_open_ai(ENV.fetch('OPENAI_ACCESS_TOKEN'))
49
+ end
50
+ RbsGoose.run
51
+ end
52
+ ```
53
+
54
+ このタスクを実行すると、 `lib` 以下の Ruby コードと `sig` 以下の RBS シグニチャを参照し、推測したシグニチャを上書きします。
55
+
56
+ 対象とするディレクトリを変更する場合、以下のように `RbsGoose.run` の引数を指定してください。
57
+
58
+ ```ruby
59
+ RbsGoose.run(code_dir: 'app', sig_dir: 'types', base_path: Rails.root)
60
+ ```
61
+
62
+ 大規模言語モデルの呼び出しには [Langchain.rb](https://github.com/andreibondarev/langchainrb) を利用しています。
63
+
64
+ 他の大規模言語モデルを利用する場合は、以下のように `llm` を直接設定してください。
65
+
66
+ ```ruby
67
+ RbsGoose.configure do |c|
68
+ c.llm = Langchain::LLM::GooglePalm.new(api_key: ENV["GOOGLE_PALM_API_KEY"])
69
+ end
70
+ ```
71
+
72
+ ## Development
73
+
74
+ リポジトリのチェックアウト後、bin/setup を実行して依存関係をインストールします。次に、`rake spec` を実行してテストを実行します。対話型プロンプトとして `bin/console` を実行して試してみることもできます。
75
+
76
+ この gem をローカルマシンにインストールするには、`bundle exec rake install` を実行します。新しいバージョンをリリースするには、`version.rb` でバージョン番号を更新してから `bundle exec rake release` を実行します。これにより、バージョンに対する Git タグが作成され、Git のコミットと作成されたタグがプッシュされ、.gem ファイルが rubygems.org にプッシュされます。
77
+
78
+ ## Contributing
79
+
80
+ バグレポートやプルリクエストは GitHub の https://github.com/kokuyouwind/rbs_goose で受け付けています。このプロジェクトは、共同作業のための安全で歓迎すべきスペースを目指しており、貢献者は [行動規範](/CODE_OF_CONDUCT.md) に従うことが求められます。
81
+
82
+ ## ライセンス
83
+
84
+ この gem は [MITライセンス](https://opensource.org/licenses/MIT) の条項に基づいてオープンソースとして利用できます。
85
+
86
+ ## 行動規範
87
+
88
+ RbsGoose プロジェクトのコードベース、課題トラッカー、チャットルーム、およびメーリングリストに関わる全員は、 [行動規範](/CODE_OF_CONDUCT.md) に従うことが求められます。
data/README.md CHANGED
@@ -2,56 +2,66 @@
2
2
  <img src="https://raw.githubusercontent.com/kokuyouwind/rbs_goose/main/assets/logo.svg" alt="RuboCop Logo"/>
3
3
  </p>
4
4
 
5
- [![en-US README](https://img.shields.io/badge/Multilingual_README-en--US-blue.svg)](/README-EN-US.md)
6
- [![ja-JP README](https://img.shields.io/badge/Multilingual_README-ja--JP-orangered.svg)](/README.md)
5
+ [![en-US README](https://img.shields.io/badge/Multilingual_README-en--US-blue.svg)](/README.md)
6
+ [![ja-JP README](https://img.shields.io/badge/Multilingual_README-ja--JP-orangered.svg)](/README-ja.md)
7
7
 
8
- [![Ruby](https://github.com/kokuyouwind/rbs_goose/actions/workflows/main.yml/badge.svg)](https://github.com/kokuyouwind/rbs_goose/actions/workflows/main.yml)
8
+ [![CI](https://github.com/kokuyouwind/rbs_goose/actions/workflows/main.yml/badge.svg)](https://github.com/kokuyouwind/rbs_goose/actions/workflows/main.yml)
9
+ [![Gem Version](https://badge.fury.io/rb/rbs_goose.svg)](https://badge.fury.io/rb/rbs_goose)
10
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/d05ed2e4fa5e565f87f5/test_coverage)](https://codeclimate.com/github/kokuyouwind/rbs_goose/test_coverage)
11
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d05ed2e4fa5e565f87f5/maintainability)](https://codeclimate.com/github/kokuyouwind/rbs_goose/maintainability)
9
12
 
10
- RBS Goose ChatGPT などの大規模言語モデルを利用して、 Ruby コードの RBS シグニチャを推測するツールです。
13
+ RBS Goose is a tool that uses large language models such as ChatGPT to infer RBS signatures for Ruby code.
11
14
 
12
15
  > [!CAUTION]
13
- > 現在は技術検証中のため、適切な型がほとんど、あるいは全く出力されない可能性があります。
14
- > また推測にあたっては ChatGPT API などを利用するため、コード規模によっては利用料が高額になる可能性があります。
16
+ > Currently in the process of technical verification, there is a possibility that appropriate types may not be output at all or may not be output at all.
17
+ > Also, when making inferences, it may be expensive to use the ChatGPT API, depending on the size of the code.
15
18
 
16
19
  ## Installation
17
20
 
18
21
  ```bash
19
- $ gem install rbs-goose
22
+ $ gem install rbs_goose
23
+ # Install the corresponding gem according to the LangChain LLM you want to use
24
+ $ gem install ruby-openai
20
25
  ```
21
26
 
22
- `bundler` を利用する場合は、代わりに以下を `Gemfile` に追加してください。
27
+ If you are using `bundler`, add the following to your `Gemfile` instead.
23
28
 
24
29
  ```ruby
25
- gem 'rbs-goose'
30
+ gem 'rbs_goose'
31
+ # Install the corresponding gem according to the LangChain LLM you want to use
32
+ gem 'ruby-openai'
26
33
  ```
27
34
 
28
35
  ## Usage
29
36
 
30
- 現状ではコマンドラインツールが未整備なので、 `Rakefile` などから `RbsGoose.run` を直接呼び出してください。
37
+ Currently, the command-line tool is not fully developed, so please call `RbsGoose.run` directly from a file like `Rakefile`.
31
38
 
32
- [OpenAI API](https://openai.com/blog/openai-api) を利用する場合は以下のようにします。
39
+ To use the [OpenAI API](https://openai.com/blog/openai-api), do the following:
33
40
 
34
41
  ```ruby
35
- desc 'refine RBS files in sig directory'
36
- task :refine do
37
- RbsGoose.configure do |c|
38
- c.use_open_ai(ENV.fetch('OPENAI_ACCESS_TOKEN'))
39
- end
40
- RbsGoose.run
42
+ require 'rbs_goose'
43
+ require 'openai'
44
+
45
+ desc 'refine RBS files in sig directory'
46
+ task :refine do
47
+ RbsGoose.configure do |c|
48
+ c.use_open_ai(ENV.fetch('OPENAI_ACCESS_TOKEN'))
41
49
  end
50
+ RbsGoose.run
51
+ end
42
52
  ```
43
53
 
44
- このタスクを実行すると、 `lib` 以下の Ruby コードと `sig` 以下の RBS シグニチャを参照し、推測したシグニチャを上書きします。
54
+ When you run this task, it will reference the Ruby code in the `lib` directory and the RBS signatures in the `sig` directory, and overwrite the inferred signatures.
45
55
 
46
- 対象とするディレクトリを変更する場合、以下のように `RbsGoose.run` の引数を指定してください。
56
+ If you want to change the target directory, specify the arguments for `RbsGoose.run` as follows:
47
57
 
48
58
  ```ruby
49
59
  RbsGoose.run(code_dir: 'app', sig_dir: 'types', base_path: Rails.root)
50
60
  ```
51
61
 
52
- 大規模言語モデルの呼び出しには [Langchain.rb](https://github.com/andreibondarev/langchainrb) を利用しています。
62
+ The call to the large language model uses [Langchain.rb](https://github.com/andreibondarev/langchainrb).
53
63
 
54
- 他の大規模言語モデルを利用する場合は、以下のように `llm` を直接設定してください。
64
+ If you want to use another large language model, set `llm` directly as follows:
55
65
 
56
66
  ```ruby
57
67
  RbsGoose.configure do |c|
@@ -61,18 +71,18 @@ end
61
71
 
62
72
  ## Development
63
73
 
64
- リポジトリのチェックアウト後、bin/setup を実行して依存関係をインストールします。次に、`rake spec` を実行してテストを実行します。対話型プロンプトとして `bin/console` を実行して試してみることもできます。
74
+ After checking out the repository, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt.
65
75
 
66
- この gem をローカルマシンにインストールするには、`bundle exec rake install` を実行します。新しいバージョンをリリースするには、`version.rb` でバージョン番号を更新してから `bundle exec rake release` を実行します。これにより、バージョンに対する Git タグが作成され、Git のコミットと作成されたタグがプッシュされ、.gem ファイルが rubygems.org にプッシュされます。
76
+ 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`. This will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
67
77
 
68
78
  ## Contributing
69
79
 
70
- バグレポートやプルリクエストは GitHub https://github.com/kokuyouwind/rbs_goose で受け付けています。このプロジェクトは、共同作業のための安全で歓迎すべきスペースを目指しており、貢献者は [行動規範](/CODE_OF_CONDUCT.md) に従うことが求められます。
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kokuyouwind/rbs_goose. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](/CODE_OF_CONDUCT.md).
71
81
 
72
- ## ライセンス
82
+ ## License
73
83
 
74
- この gem [MITライセンス](https://opensource.org/licenses/MIT) の条項に基づいてオープンソースとして利用できます。
84
+ This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
75
85
 
76
- ## 行動規範
86
+ ## Code of Conduct
77
87
 
78
- RbsGoose プロジェクトのコードベース、課題トラッカー、チャットルーム、およびメーリングリストに関わる全員は、 [行動規範](/CODE_OF_CONDUCT.md) に従うことが求められます。
88
+ Everyone interacting in the RbsGoose project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -24,13 +24,22 @@ task :'spec:record' do
24
24
  Rake::Task['spec'].invoke
25
25
  end
26
26
 
27
- namespace :sig do # rubocop:disable Metrics/BlockLength
28
- desc 'build RBS prototypes to sig directory'
29
- task :prototype do
27
+ namespace :sig do
28
+ desc 'refine RBS files in sig directory'
29
+ task :refine do
30
30
  require 'orthoses'
31
31
  require_relative 'lib/rbs_goose'
32
32
 
33
33
  Orthoses::Builder.new do
34
+ # use RbsGoose::Orthoses::FixError
35
+ use RbsGoose::Orthoses::Infer do |config|
36
+ # config.use_open_ai(ENV.fetch('OPENAI_ACCESS_TOKEN'), model_name: 'gpt-3.5-turbo-0125')
37
+ # config.use_open_ai(ENV.fetch('OPENAI_ACCESS_TOKEN'), model_name: 'gpt-4-turbo-2024-04-09')
38
+ # config.use_anthropic(ENV.fetch('ANTHROPIC_API_KEY', nil), model_name: 'claude-3-haiku-20240307')
39
+ # config.use_anthropic(ENV.fetch('ANTHROPIC_API_KEY', nil), model_name: 'claude-3-sonnet-20240229')
40
+ config.use_anthropic(ENV.fetch('ANTHROPIC_API_KEY', nil), model_name: 'claude-3-opus-20240229')
41
+ # config.use_ollama(model_name: 'codegemma')
42
+ end
34
43
  use Orthoses::CreateFileByName,
35
44
  to: 'sig',
36
45
  rmtree: true
@@ -44,18 +53,49 @@ namespace :sig do # rubocop:disable Metrics/BlockLength
44
53
  end.call
45
54
  end
46
55
 
47
- desc 'refine RBS files in sig directory'
48
- task :refine do
56
+ desc 'fix RBS'
57
+ task :fix do
58
+ require 'orthoses'
49
59
  require_relative 'lib/rbs_goose'
50
60
 
51
- RbsGoose.configure do |c|
52
- c.use_open_ai(
53
- ENV.fetch('OPENAI_ACCESS_TOKEN'),
54
- default_options: {
55
- completion_model_name: 'gpt-3.5-turbo-1106'
56
- }
57
- )
58
- end
59
- RbsGoose.run
61
+ Orthoses::Builder.new do
62
+ use RbsGoose::Orthoses::FixError do |config|
63
+ config.use_anthropic(ENV.fetch('ANTHROPIC_API_KEY', nil), model_name: 'claude-3-opus-20240229')
64
+ # config.use_open_ai(ENV.fetch('OPENAI_ACCESS_TOKEN'), model_name: 'gpt-4-turbo-2024-04-09')
65
+ end
66
+ run -> {}
67
+ end.call
68
+ end
69
+ end
70
+
71
+ namespace :readme do
72
+ desc 'translate japanese README to english README'
73
+ task :translate do
74
+ require 'langchain'
75
+ require 'openai'
76
+
77
+ readme_ja = File.read('README-ja.md')
78
+ puts '======== Japanese README ========'
79
+ puts readme_ja
80
+
81
+ llm = Langchain::LLM::OpenAI.new(
82
+ api_key: ENV.fetch('OPENAI_ACCESS_TOKEN'),
83
+ default_options: {
84
+ completion_model_name: 'gpt-3.5-turbo-1106',
85
+ chat_completion_model_name: 'gpt-3.5-turbo-1106'
86
+ }
87
+ )
88
+
89
+ readme_en = llm.complete(prompt: <<~PROMPT).completion
90
+ Translate the following markdown document into English, keeping the markdown formatting.
91
+
92
+ ======== INPUT ========
93
+ #{readme_ja}
94
+
95
+ ======== OUTPUT ========
96
+ PROMPT
97
+ puts '======== Translated English README ========'
98
+ puts readme_en
99
+ File.write('README.md', readme_en)
60
100
  end
61
101
  end
data/Steepfile CHANGED
@@ -5,10 +5,8 @@ D = Steep::Diagnostic
5
5
  target :lib do
6
6
  check 'lib'
7
7
  signature 'sig', 'sig_ext'
8
- ignore(
9
- 'lib/rbs_goose/examples'
10
- )
11
8
  configure_code_diagnostics(D::Ruby.default) do |hash|
12
9
  hash[D::Ruby::BlockTypeMismatch] = :information
10
+ hash[D::Ruby::RequiredBlockMissing] = :information
13
11
  end
14
12
  end