rbs_goose 0.1.1 → 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 +69 -38
  6. data/README-ja.md +88 -0
  7. data/README.md +25 -22
  8. data/Rakefile +53 -8
  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}/refined/sig/email.rbs +1 -1
  18. data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/refined/sig/person.rbs +2 -2
  19. data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/refined/sig/phone.rbs +1 -1
  20. data/examples/fix_errors/sig/email.rbs +11 -0
  21. data/examples/fix_errors/sig/person.rbs +15 -0
  22. data/examples/fix_errors/sig/phone.rbs +15 -0
  23. data/examples/rbs_samples/lib/email.rb +16 -0
  24. data/examples/rbs_samples/lib/person.rb +23 -0
  25. data/examples/rbs_samples/lib/phone.rb +22 -0
  26. data/examples/rbs_samples/refined/sig/email.rbs +11 -0
  27. data/examples/rbs_samples/refined/sig/person.rbs +15 -0
  28. data/examples/rbs_samples/refined/sig/phone.rbs +15 -0
  29. data/examples/rbs_syntax/Steepfile +6 -0
  30. data/examples/rbs_syntax/lib/a.rb +53 -0
  31. data/examples/rbs_syntax/lib/list.rb +9 -0
  32. data/examples/rbs_syntax/lib/main.rb +17 -0
  33. data/examples/rbs_syntax/refined/sig/a.rbs +47 -0
  34. data/examples/rbs_syntax/refined/sig/list.rbs +7 -0
  35. data/examples/rbs_syntax/refined/sig/main.rbs +26 -0
  36. data/examples/rbs_syntax/sig/a.rbs +47 -0
  37. data/examples/rbs_syntax/sig/list.rbs +7 -0
  38. data/examples/rbs_syntax/sig/main.rbs +26 -0
  39. data/lib/rbs_goose/configuration.rb +93 -23
  40. data/lib/rbs_goose/io/example.rb +2 -2
  41. data/lib/rbs_goose/io/example_group.rb +16 -7
  42. data/lib/rbs_goose/io/target_group.rb +1 -1
  43. data/lib/rbs_goose/io/typed_ruby.rb +3 -3
  44. data/lib/rbs_goose/orthoses/fix_error.rb +26 -0
  45. data/lib/rbs_goose/orthoses/infer.rb +26 -0
  46. data/lib/rbs_goose/orthoses.rb +9 -0
  47. data/lib/rbs_goose/templates/base.rb +77 -0
  48. data/lib/rbs_goose/templates/fix_error_template.rb +43 -0
  49. data/lib/rbs_goose/templates/infer_template.rb +30 -0
  50. data/lib/rbs_goose/templates.rb +3 -1
  51. data/lib/rbs_goose/type_inferrer.rb +73 -2
  52. data/lib/rbs_goose/version.rb +1 -1
  53. data/lib/rbs_goose.rb +24 -4
  54. data/rbs_collection.lock.yaml +63 -47
  55. data/renovate.json +5 -0
  56. data/sig/rbs_goose/configuration.rbs +20 -12
  57. data/sig/rbs_goose/io/example.rbs +7 -7
  58. data/sig/rbs_goose/io/example_group.rbs +9 -7
  59. data/sig/rbs_goose/io/file.rbs +10 -10
  60. data/sig/rbs_goose/io/target_group.rbs +2 -2
  61. data/sig/rbs_goose/io/typed_ruby.rbs +7 -7
  62. data/sig/rbs_goose/io.rbs +1 -1
  63. data/sig/rbs_goose/orthoses/fix_error.rbs +11 -0
  64. data/sig/rbs_goose/orthoses/infer.rbs +11 -0
  65. data/sig/rbs_goose/orthoses.rbs +2 -0
  66. data/sig/rbs_goose/templates/base.rbs +18 -0
  67. data/sig/rbs_goose/templates/fix_error_template.rbs +6 -0
  68. data/sig/rbs_goose/templates/infer_template.rbs +6 -0
  69. data/sig/rbs_goose/templates.rbs +1 -1
  70. data/sig/rbs_goose/type_inferrer.rbs +9 -1
  71. data/sig/rbs_goose.rbs +18 -9
  72. metadata +137 -21
  73. data/README-EN-US.md +0 -85
  74. data/lib/rbs_goose/templates/default_template.rb +0 -49
  75. data/sig/rbs_goose/templates/default_template.rbs +0 -10
  76. /data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/lib/email.rb +0 -0
  77. /data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/lib/person.rb +0 -0
  78. /data/{lib/rbs_goose/examples/rbs_samples → examples/fix_errors}/lib/phone.rb +0 -0
  79. /data/{lib/rbs_goose/examples → examples}/rbs_samples/Steepfile +0 -0
  80. /data/{lib/rbs_goose/examples → examples}/rbs_samples/sig/email.rbs +0 -0
  81. /data/{lib/rbs_goose/examples → examples}/rbs_samples/sig/person.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: bfba03266529804e3cd1123057d193e3362495c21686f596d6e88acd48da4862
4
- data.tar.gz: b118cb15e016f8a678410df2b36c7e4079fecceebb512491935320197e193e32
3
+ metadata.gz: 10bed3f0456e4a9262ed23aa377238af9fa6297fabc1792aac15146c6ef20325
4
+ data.tar.gz: 5b7ac52a808a4a62b71e9bb603f14c92d5dadb897b897fde004e9dcc1cbb9fff
5
5
  SHA512:
6
- metadata.gz: bba1f1b303559ea88caa1899b66875139add68526b9d4236c56b8562fd32fac460711ed5e51354ef1df7b3ac5fb962a34868cafaa4d603d35bcfd753deb3bc48
7
- data.tar.gz: 2267ed274906716dfa4e7234ac7c1dfe9d633d8f0308b9311d6545d280085a82392a6fe2154de2763298b66a2d6f89963cdeeade666c2590c58aea46e39711a2
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.3.0'
18
- gem 'steep', '~> 1.6.0'
19
- gem 'vcr', '~> 6.2.0'
20
- gem 'webmock', '~> 3.19.0'
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,9 +1,20 @@
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.1)
5
- langchainrb (>= 0.8.2, < 1.0.0)
6
- ruby-openai (>= 6.1.0, < 7.0.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/
@@ -21,19 +32,23 @@ GEM
21
32
  tzinfo (~> 2.0)
22
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
41
  bigdecimal (3.1.6)
28
- colorize (0.8.1)
42
+ colorize (1.1.0)
29
43
  concurrent-ruby (1.2.3)
30
44
  connection_pool (2.4.1)
31
45
  crack (0.4.6)
32
46
  bigdecimal
33
47
  rexml
34
48
  csv (3.2.8)
35
- diff-lcs (1.5.0)
36
- dotenv (2.8.1)
49
+ diff-lcs (1.5.1)
50
+ docile (1.4.0)
51
+ dotenv (3.1.2)
37
52
  drb (2.2.0)
38
53
  ruby2_keywords
39
54
  event_stream_parser (1.0.0)
@@ -50,16 +65,17 @@ GEM
50
65
  hashdiff (1.1.0)
51
66
  i18n (1.14.1)
52
67
  concurrent-ruby (~> 1.0)
53
- json (2.7.1)
68
+ json (2.7.2)
54
69
  json-schema (4.0.0)
55
70
  addressable (>= 2.8)
56
- langchainrb (0.8.2)
71
+ langchainrb (0.12.0)
72
+ activesupport (>= 7.0.8)
57
73
  baran (~> 0.1.9)
58
- colorize (~> 0.8.1)
59
- json-schema (~> 4.0.0)
74
+ colorize (~> 1.1.0)
75
+ json-schema (~> 4)
60
76
  matrix
61
77
  pragmatic_segmenter (~> 0.3.0)
62
- tiktoken_ruby (~> 0.0.5)
78
+ tiktoken_ruby (~> 0.0.8)
63
79
  to_bool (~> 2.0.0)
64
80
  zeitwerk (~> 2.5)
65
81
  language_server-protocol (3.17.0.3)
@@ -69,14 +85,14 @@ GEM
69
85
  logger (1.6.0)
70
86
  matrix (0.4.2)
71
87
  minitest (5.21.2)
72
- multipart-post (2.3.0)
88
+ multipart-post (2.4.0)
73
89
  mutex_m (0.2.0)
74
90
  net-http (0.4.1)
75
91
  uri
76
92
  orthoses (1.13.0)
77
93
  rbs (~> 3.0)
78
94
  parallel (1.24.0)
79
- parser (3.3.0.5)
95
+ parser (3.3.1.0)
80
96
  ast (~> 2.4.1)
81
97
  racc
82
98
  pragmatic_segmenter (0.3.23)
@@ -84,29 +100,28 @@ GEM
84
100
  public_suffix (5.0.4)
85
101
  racc (1.7.3)
86
102
  rainbow (3.1.1)
87
- rake (13.1.0)
103
+ rake (13.2.1)
88
104
  rb-fsevent (0.11.2)
89
105
  rb-inotify (0.10.1)
90
106
  ffi (~> 1.0)
91
- rb_sys (0.9.86)
92
107
  rbs (3.4.1)
93
108
  abbrev
94
109
  regexp_parser (2.9.0)
95
110
  rexml (3.2.6)
96
- rspec (3.12.0)
97
- rspec-core (~> 3.12.0)
98
- rspec-expectations (~> 3.12.0)
99
- rspec-mocks (~> 3.12.0)
100
- rspec-core (3.12.2)
101
- rspec-support (~> 3.12.0)
102
- rspec-expectations (3.12.3)
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)
103
118
  diff-lcs (>= 1.2.0, < 2.0)
104
- rspec-support (~> 3.12.0)
105
- rspec-mocks (3.12.5)
119
+ rspec-support (~> 3.13.0)
120
+ rspec-mocks (3.13.0)
106
121
  diff-lcs (>= 1.2.0, < 2.0)
107
- rspec-support (~> 3.12.0)
108
- rspec-support (3.12.1)
109
- rubocop (1.60.2)
122
+ rspec-support (~> 3.13.0)
123
+ rspec-support (3.13.0)
124
+ rubocop (1.63.4)
110
125
  json (~> 2.3)
111
126
  language_server-protocol (>= 3.17.0)
112
127
  parallel (~> 1.10)
@@ -114,28 +129,39 @@ GEM
114
129
  rainbow (>= 2.2.2, < 4.0)
115
130
  regexp_parser (>= 1.8, < 3.0)
116
131
  rexml (>= 3.2.5, < 4.0)
117
- rubocop-ast (>= 1.30.0, < 2.0)
132
+ rubocop-ast (>= 1.31.1, < 2.0)
118
133
  ruby-progressbar (~> 1.7)
119
134
  unicode-display_width (>= 2.4.0, < 3.0)
120
- rubocop-ast (1.30.0)
121
- parser (>= 3.2.1.0)
135
+ rubocop-ast (1.31.3)
136
+ parser (>= 3.3.1.0)
122
137
  rubocop-capybara (2.20.0)
123
138
  rubocop (~> 1.41)
124
139
  rubocop-factory_bot (2.25.1)
125
140
  rubocop (~> 1.41)
126
141
  rubocop-rake (0.6.0)
127
142
  rubocop (~> 1.0)
128
- rubocop-rspec (2.26.1)
143
+ rubocop-rspec (2.29.2)
129
144
  rubocop (~> 1.40)
130
145
  rubocop-capybara (~> 2.17)
131
146
  rubocop-factory_bot (~> 2.22)
132
- ruby-openai (6.3.1)
147
+ rubocop-rspec_rails (~> 2.28)
148
+ rubocop-rspec_rails (2.28.3)
149
+ rubocop (~> 1.40)
150
+ ruby-openai (7.0.1)
133
151
  event_stream_parser (>= 0.3.0, < 2.0.0)
134
152
  faraday (>= 1)
135
153
  faraday-multipart (>= 1)
136
154
  ruby-progressbar (1.13.0)
137
155
  ruby2_keywords (0.0.5)
138
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)
139
165
  steep (1.6.0)
140
166
  activesupport (>= 5.1)
141
167
  concurrent-ruby (>= 1.1.10)
@@ -154,8 +180,8 @@ GEM
154
180
  strscan (3.0.8)
155
181
  terminal-table (3.0.2)
156
182
  unicode-display_width (>= 1.1.1, < 3)
157
- tiktoken_ruby (0.0.6)
158
- rb_sys (~> 0.9.68)
183
+ tiktoken_ruby (0.0.8-arm64-darwin)
184
+ tiktoken_ruby (0.0.8-x86_64-linux)
159
185
  to_bool (2.0.0)
160
186
  tzinfo (2.0.6)
161
187
  concurrent-ruby (~> 1.0)
@@ -163,7 +189,7 @@ GEM
163
189
  unicode-display_width (2.5.0)
164
190
  uri (0.13.0)
165
191
  vcr (6.2.0)
166
- webmock (3.19.1)
192
+ webmock (3.23.0)
167
193
  addressable (>= 2.8.0)
168
194
  crack (>= 0.3.2)
169
195
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -175,8 +201,10 @@ PLATFORMS
175
201
  x86_64-linux
176
202
 
177
203
  DEPENDENCIES
178
- dotenv (~> 2.8.1)
204
+ anthropic (~> 0.2.0)
205
+ dotenv (~> 3.1.0)
179
206
  factory_bot (~> 6.4.5)
207
+ faraday (~> 2.9.0)
180
208
  orthoses (~> 1.13.0)
181
209
  rake (~> 13.0)
182
210
  rbs_goose!
@@ -185,10 +213,13 @@ DEPENDENCIES
185
213
  rubocop-factory_bot (~> 2.25.1)
186
214
  rubocop-rake (~> 0.6.0)
187
215
  rubocop-rspec (~> 2.22)
188
- ruby-openai (~> 6.3.0)
216
+ ruby-openai (~> 7.0.0)
217
+ simplecov
218
+ simplecov-cobertura
219
+ simplecov-html!
189
220
  steep (~> 1.6.0)
190
221
  vcr (~> 6.2.0)
191
- webmock (~> 3.19.0)
222
+ webmock (~> 3.23.0)
192
223
 
193
224
  BUNDLED WITH
194
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,38 +2,41 @@
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
22
  $ gem install rbs_goose
20
- # 利用する LangChain LLM に応じて、対応する gem を合わせてインストールします
23
+ # Install the corresponding gem according to the LangChain LLM you want to use
21
24
  $ gem install ruby-openai
22
25
  ```
23
26
 
24
- `bundler` を利用する場合は、代わりに以下を `Gemfile` に追加してください。
27
+ If you are using `bundler`, add the following to your `Gemfile` instead.
25
28
 
26
29
  ```ruby
27
30
  gem 'rbs_goose'
28
- # 利用する LangChain LLM に応じて、対応する gem を合わせてインストールします
31
+ # Install the corresponding gem according to the LangChain LLM you want to use
29
32
  gem 'ruby-openai'
30
33
  ```
31
34
 
32
35
  ## Usage
33
36
 
34
- 現状ではコマンドラインツールが未整備なので、 `Rakefile` などから `RbsGoose.run` を直接呼び出してください。
37
+ Currently, the command-line tool is not fully developed, so please call `RbsGoose.run` directly from a file like `Rakefile`.
35
38
 
36
- [OpenAI API](https://openai.com/blog/openai-api) を利用する場合は以下のようにします。
39
+ To use the [OpenAI API](https://openai.com/blog/openai-api), do the following:
37
40
 
38
41
  ```ruby
39
42
  require 'rbs_goose'
@@ -48,17 +51,17 @@ task :refine do
48
51
  end
49
52
  ```
50
53
 
51
- このタスクを実行すると、 `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.
52
55
 
53
- 対象とするディレクトリを変更する場合、以下のように `RbsGoose.run` の引数を指定してください。
56
+ If you want to change the target directory, specify the arguments for `RbsGoose.run` as follows:
54
57
 
55
58
  ```ruby
56
59
  RbsGoose.run(code_dir: 'app', sig_dir: 'types', base_path: Rails.root)
57
60
  ```
58
61
 
59
- 大規模言語モデルの呼び出しには [Langchain.rb](https://github.com/andreibondarev/langchainrb) を利用しています。
62
+ The call to the large language model uses [Langchain.rb](https://github.com/andreibondarev/langchainrb).
60
63
 
61
- 他の大規模言語モデルを利用する場合は、以下のように `llm` を直接設定してください。
64
+ If you want to use another large language model, set `llm` directly as follows:
62
65
 
63
66
  ```ruby
64
67
  RbsGoose.configure do |c|
@@ -68,18 +71,18 @@ end
68
71
 
69
72
  ## Development
70
73
 
71
- リポジトリのチェックアウト後、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.
72
75
 
73
- この 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.
74
77
 
75
78
  ## Contributing
76
79
 
77
- バグレポートやプルリクエストは 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).
78
81
 
79
- ## ライセンス
82
+ ## License
80
83
 
81
- この 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).
82
85
 
83
- ## 行動規範
86
+ ## Code of Conduct
84
87
 
85
- 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
@@ -25,12 +25,21 @@ task :'spec:record' do
25
25
  end
26
26
 
27
27
  namespace :sig do
28
- desc 'build RBS prototypes to sig directory'
29
- task :prototype 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,13 +53,49 @@ namespace :sig do
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(ENV.fetch('OPENAI_ACCESS_TOKEN'))
53
- end
54
- 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)
55
100
  end
56
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