-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep7
executable file
·122 lines (109 loc) · 3.13 KB
/
step7
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env ruby
require "bundler"
Bundler.require(:default)
Dotenv.load
require_relative "lib/render"
renderer = Render.new
prompt = "Examine the leads in the database and create a pie chart showing 3 different cohorts. The first, are leads created 3 days ago. The second are leads created 2 days ago. The third cohort are leads created yesterday."
request = <<~JSON
{
"model": "claude-3-5-sonnet",
"messages": [
{
"role": "user",
"content": "#{prompt}"
}
],
"tools": [
{
"type": "heroku_tool",
"function": "database_get_schema",
"runtime_params": {
"target_app_name": "heroku-df24-trello",
"tool_params": {
"db_attachment": "DATABASE"
}
}
},
{
"type": "heroku_tool",
"function": "database_run_query",
"runtime_params": {
"target_app_name": "heroku-df24-trello",
"tool_params": {
"db_attachment": "DATABASE"
}
}
},
{
"type": "function",
"function": {
"name": "create_pie_chart",
"description": "Creates a pie chart for 3 given values",
"parameters": {
"type": "object",
"properties": {
"cohort_1": {
"type": "integer",
"description": "The first cohort value"
},
"cohort_1_label": {
"type": "string",
"description": "The label to use for the first cohort. What does it represent?"
},
"cohort_2": {
"type": "integer",
"description": "The second cohort value"
},
"cohort_2_label": {
"type": "string",
"description": "The label to use for the second cohort. What does it represent?"
},
"cohort_3": {
"type": "integer",
"description": "The third cohort value"
},
"cohort_3_label": {
"type": "string",
"description": "The label to use for the third cohort. What does it represent?"
}
},
"required": ["cohort_1", "cohort_1_label", "cohort_2", "cohort_2_label", "cohort_3", "cohort_3_label"]
}
}
}
],
"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)
params = response.dig("choices", 0, "message", "tool_calls", 0, "function", "arguments")
parsed_params = JSON.parse(params)
data = []
styles = [
{ color: :bright_red, fill: "*" },
{ color: :bright_green, fill: "x" },
{ color: :bright_magenta, fill: "@" }
]
styles.each.with_index do |style, i|
data << {
name: parsed_params["cohort_#{i + 1}_label"],
value: Integer(parsed_params["cohort_#{i + 1}"]),
color: style[:color],
fill: style[:fill]
}
end
puts "\n"
pie_chart = TTY::Pie.new(data: data, radius: 10)
puts pie_chart
renderer.hr