-
Notifications
You must be signed in to change notification settings - Fork 0
/
step13
executable file
·68 lines (57 loc) · 1.54 KB
/
step13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env ruby
require "bundler"
Bundler.require(:default)
Dotenv.load
require_relative "lib/render"
renderer = Render.new
prompt = "Use Open Meteo and tell the current weather and forecast in San Francisco, CA."
request = <<~JSON
{
"model": "claude-3-5-sonnet",
"messages": [
{
"role": "user",
"content": "#{prompt}"
}
],
"tools": [
{
"type": "heroku_tool",
"function": "code_exec_ruby"
}
],
"tool_choice": "auto"
}
JSON
renderer.heroku_print("Here is the request we are sending to Heroku for inferencing...")
renderer.print_markdown(
<<~MARKDOWN
```json
#{request}
```
MARKDOWN
)
answer = renderer.confirm("Ready to send the inference request?")
exit(0) unless answer
response = renderer.inference_request(request:, print_last_message: false)
renderer.print_large_box(response.dig("choices", 0, "message", "content"))
# Let's print out the generated code
renderer.all_responses.each do |r|
msg = r.dig("choices", 0, "message")
tool_call = msg.dig("tool_calls", 0)
if tool_call
args = JSON.parse(tool_call.dig("function", "arguments"))
if tool_call.dig("function", "name").match(/\Acode_exec_ruby/)
renderer.heroku_print("Here is what was run on the Dyno's shell prior to executing the code:")
renderer.print_markdown(args["shell_command"])
renderer.heroku_print("Here is the generated code that was run:")
ruby_code = <<~RUBY
```ruby
#{args["code"]}
```
RUBY
renderer.print_markdown(ruby_code)
end
end
end
renderer.hr