Commit 2578caa
authored
Enable
safe_ruby has supported Ruby 3.3+ since version 1.0.5:
ukutaht/safe_ruby#4 (comment)
## Before (using safe_ruby 1.0.4)
A `NameError` occurred when running under Ruby 3.3:
```console
$ ruby -v
ruby 3.3.8 (2025-04-09 revision b200bad6cd) [x86_64-darwin24]
$ bundle exec ruby -rlangchain -e "Langchain::Tool::RubyCodeInterpreter.new.execute(input: '[1, 2, 3].map{ |n| n + 1 }')"
D, [2025-05-01T00:15:18.396619 #61580] DEBUG -- [Langchain.rb]: Langchain::Tool::RubyCodeInterpreter - Executing "[1, 2, 3].map{ |n| n + 1 }"
/Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:45:
in `rescue in eval': /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:17:
in `undef_method': undefined method `new' for class `String' (NameError) (RuntimeError)
klass.send(:undef_method, method)
^^^^^
Did you mean? next
from /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:17:in `block in keep_methods'
from /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:16:in `each'
from /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:16:in `keep_methods'
from /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:37:in `<main>'
from /Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:41:in `eval'
from /Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:20:in `eval'
from /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/tool/ruby_code_interpreter.rb:38:in `safe_eval'
from /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/tool/ruby_code_interpreter.rb:34:in `execute'
from -e:1:in `<main>'
<internal:marshal>:34:in `load': incompatible marshal file format (can't be read) (TypeError)
format version 4.8 required; 47.118 given
from /Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:42:in `eval'
from /Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:20:in `eval'
from /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/tool/ruby_code_interpreter.rb:38:in `safe_eval'
from /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/tool/ruby_code_interpreter.rb:34:in `execute'
from -e:1:in `<main>'
```
## After (using safe_ruby 1.0.5)
No error occurs:
```console
$ ruby -v
ruby 3.3.8 (2025-04-09 revision b200bad6cd) [x86_64-darwin24]
$ bundle exec ruby -rlangchain -e "Langchain::Tool::RubyCodeInterpreter.new.execute(input: '[1, 2, 3].map{ |n| n + 1 }')"
D, [2025-05-01T00:16:09.404532 #63102] DEBUG -- [Langchain.rb]: Langchain::Tool::RubyCodeInterpreter - Executing "[1, 2, 3].map{ |n| n + 1 }"
```
Ruby 3.4 works as well.Langchain::Tool::RubyCodeInterpreter on Ruby 3.3+ (#977)1 parent d06acdb commit 2578caa
File tree
5 files changed
+24
-31
lines changed- lib
- langchain/tool
- spec/langchain/tool
5 files changed
+24
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
389 | | - | |
390 | | - | |
| 390 | + | |
| 391 | + | |
391 | 392 | | |
392 | 393 | | |
393 | 394 | | |
| |||
486 | 487 | | |
487 | 488 | | |
488 | 489 | | |
489 | | - | |
| 490 | + | |
490 | 491 | | |
491 | 492 | | |
492 | 493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | 32 | | |
37 | 33 | | |
38 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
13 | 10 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
19 | 16 | | |
20 | | - | |
21 | | - | |
| 17 | + | |
| 18 | + | |
22 | 19 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
27 | 23 | | |
28 | 24 | | |
29 | 25 | | |
0 commit comments