helicone-rb 0.0.4 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -1
- data/lib/helicone/agent.rb +4 -4
- data/lib/helicone/version.rb +1 -1
- data/sample.rb +177 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e88e12d27963faaf420d13dc78cda2eada0f86fd97fb22570c310ac91610bf03
|
|
4
|
+
data.tar.gz: fa8f16816537172ec4ef2c859791e63e816860fe23a5e72bc78b361177587d9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a3b285e947a350c25e2b7d68b5c415b38ed1415eaaa366078ed356405e19989f1fc4674e4709113dfc09a3b089534edbb03fbebdfa169d5f0b1d13ec28612fb
|
|
7
|
+
data.tar.gz: b8feec47c41a127a1108328c729ee11398d83c360b8498aacb71781c9a035aba6cba874851647cfc706dd93a08961593ce1f889cabc087c472850f8e427a3b5b
|
data/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
> **Beta** - This library is under active development. APIs may change.
|
|
2
|
+
|
|
1
3
|
# Helicone Ruby Client
|
|
2
4
|
|
|
3
5
|
A Ruby client for the [Helicone AI Gateway](https://helicone.ai), wrapping the OpenAI API with built-in session tracking, cost attribution, and an agentic framework for building AI applications with tool/function calling.
|
|
4
6
|
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
## Why Helicone?
|
|
6
10
|
|
|
7
11
|
[Helicone](https://helicone.ai) is an AI gateway that sits between your application and LLM providers (OpenAI, Anthropic, etc.). It provides:
|
|
@@ -16,6 +20,35 @@ A Ruby client for the [Helicone AI Gateway](https://helicone.ai), wrapping the O
|
|
|
16
20
|
|
|
17
21
|
*The Helicone dashboard shows all your LLM requests with latency, cost, and token usage at a glance.*
|
|
18
22
|
|
|
23
|
+
### Under the hood
|
|
24
|
+
This is an API that interacts with **any OpenAI-format /chat/completions LLM endpoint.**
|
|
25
|
+
[Helicone](https://helicone.ai) acts as a proxy, similar to OpenRouter, with built in telemetry and more.
|
|
26
|
+
|
|
27
|
+
This library adds the ability to interact with Helicone specific features like [Session waterfall tracking](https://github.com/genevere-inc/helicone-rb/tree/main?tab=readme-ov-file#session-and-account-tracking).
|
|
28
|
+
|
|
29
|
+
### Alternatives
|
|
30
|
+
|
|
31
|
+
**[RubyLLM](https://rubyllm.com/)**
|
|
32
|
+
|
|
33
|
+
This library is great for an opinioned quick start, but I found it has too much magic under the hood that makes using proxies like Helicone and OpenRouter very difficult.
|
|
34
|
+
|
|
35
|
+
**[`alexrudall/ruby-openai`](https://github.com/alexrudall/ruby-openai)**
|
|
36
|
+
|
|
37
|
+
This gem uses this great library under the hood. If you don't need tool calling or helicone, you can use this instead.
|
|
38
|
+
|
|
39
|
+
**[`openai/openai-ruby`](https://github.com/openai/openai-ruby)**
|
|
40
|
+
|
|
41
|
+
This is the official gem from OpenAI. It's severely lacking in functionality.
|
|
42
|
+
|
|
43
|
+
**[`Traceloop`](https://traceloop.com/)**
|
|
44
|
+
|
|
45
|
+
A telemetry tool built on top of OpenTelemetry. Their `traceloop-sdk` gem did not work out of the box as of June 2025, but accepts OpenTelemetry endpoints and works quite well for visualizing agentic workflows.
|
|
46
|
+
|
|
47
|
+
Note that it **does not** act as a _proxy_ in the way Helicone and OpenRouter do, which may help if you need to use LLM hosts directly, or may be a drawback given it lacks the fallback mechanisms the proxies include.
|
|
48
|
+
|
|
49
|
+
_Note:_ I've used this in production and it works very reliably for tracking, but cost aggregation has never worked correctly. For that and other challenges, switched to Helicone.
|
|
50
|
+
|
|
51
|
+
|
|
19
52
|
## Installation
|
|
20
53
|
|
|
21
54
|
Add this line to your application's Gemfile:
|
|
@@ -223,7 +256,7 @@ end
|
|
|
223
256
|
```ruby
|
|
224
257
|
agent = Helicone::Agent.new(
|
|
225
258
|
tools: [WeatherTool, CalendarTool],
|
|
226
|
-
|
|
259
|
+
system_prompt: "You are a helpful assistant with access to weather and calendar tools.",
|
|
227
260
|
context: current_user # Passed to tool#initialize
|
|
228
261
|
)
|
|
229
262
|
|
data/lib/helicone/agent.rb
CHANGED
|
@@ -11,17 +11,17 @@ module Helicone
|
|
|
11
11
|
# @param client [Helicone::Client] Optional client (creates new one if not provided)
|
|
12
12
|
# @param tools [Array<Class>] Array of Tool subclasses
|
|
13
13
|
# @param context [Object] Context object passed to tool#initialize
|
|
14
|
-
# @param
|
|
14
|
+
# @param system_prompt [String] System prompt
|
|
15
15
|
# @param messages [Array<Helicone::Message>] Initial messages (for continuing conversations)
|
|
16
|
-
def initialize(client: nil, tools: [], context: nil,
|
|
16
|
+
def initialize(client: nil, tools: [], context: nil, system_prompt: nil, messages: [])
|
|
17
17
|
@client = client || Client.new
|
|
18
18
|
@tools = tools
|
|
19
19
|
@context = context
|
|
20
20
|
@messages = messages.dup
|
|
21
21
|
|
|
22
22
|
# Add system message at the start if provided and not already present
|
|
23
|
-
if
|
|
24
|
-
@messages.unshift(Message.system(
|
|
23
|
+
if system_prompt && @messages.none? { |m| m.respond_to?(:role) && m.role == "system" }
|
|
24
|
+
@messages.unshift(Message.system(system_prompt))
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
data/lib/helicone/version.rb
CHANGED
data/sample.rb
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
require 'helicone'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# ============================================
|
|
5
|
+
# Configuration
|
|
6
|
+
# ============================================
|
|
7
|
+
|
|
8
|
+
Helicone.configure do |config|
|
|
9
|
+
config.default_model = "gpt-4o-mini"
|
|
10
|
+
config.logger = Logger.new(STDOUT, level: Logger::DEBUG)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
if ENV["HELICONE_API_KEY"].nil?
|
|
14
|
+
fail StandardError, "HELICONE_API_KEY is not set"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# ============================================
|
|
18
|
+
# Basic Usage - Simple Questions
|
|
19
|
+
# ============================================
|
|
20
|
+
|
|
21
|
+
client = Helicone::Client.new
|
|
22
|
+
client.ask("What is 2 + 2?")
|
|
23
|
+
# => "2 + 2 equals 4."
|
|
24
|
+
|
|
25
|
+
# With a system prompt
|
|
26
|
+
client.ask("Tell me a joke", system: "You are a comedian")
|
|
27
|
+
|
|
28
|
+
# With a specific model
|
|
29
|
+
client.ask("Explain Ruby blocks", model: "gpt-4o-mini")
|
|
30
|
+
|
|
31
|
+
# ============================================
|
|
32
|
+
# With Session/Account Tracking
|
|
33
|
+
# ============================================
|
|
34
|
+
|
|
35
|
+
client = Helicone::Client.new(
|
|
36
|
+
session_id: "conv_123",
|
|
37
|
+
session_name: "Customer Support Chat",
|
|
38
|
+
account_id: "user_456",
|
|
39
|
+
account_name: "Acme Corp"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
client.ask("Help me with my order")
|
|
43
|
+
|
|
44
|
+
# ============================================
|
|
45
|
+
# Multi-turn Conversation
|
|
46
|
+
# ============================================
|
|
47
|
+
|
|
48
|
+
client = Helicone::Client.new
|
|
49
|
+
messages = [
|
|
50
|
+
Helicone::Message.system("You are a helpful assistant"),
|
|
51
|
+
Helicone::Message.user_text("My name is Alice")
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
response = client.chat(messages: messages)
|
|
55
|
+
puts response.content
|
|
56
|
+
# => "Nice to meet you, Alice!"
|
|
57
|
+
|
|
58
|
+
messages << response.to_message
|
|
59
|
+
messages << Helicone::Message.user_text("What's my name?")
|
|
60
|
+
|
|
61
|
+
response = client.chat(messages: messages)
|
|
62
|
+
puts response.content
|
|
63
|
+
# => "Your name is Alice."
|
|
64
|
+
|
|
65
|
+
# ============================================
|
|
66
|
+
# Vision - Ask About Images
|
|
67
|
+
# ============================================
|
|
68
|
+
|
|
69
|
+
client.ask_with_image(
|
|
70
|
+
"What's in this image?",
|
|
71
|
+
"https://example.com/photo.jpg",
|
|
72
|
+
detail: "high"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# ============================================
|
|
76
|
+
# Using the Agent with Tools
|
|
77
|
+
# ============================================
|
|
78
|
+
|
|
79
|
+
# Define a tool
|
|
80
|
+
class WeatherTool < Helicone::Tool
|
|
81
|
+
description "Get current weather for a location"
|
|
82
|
+
|
|
83
|
+
parameters(
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: {
|
|
86
|
+
location: { type: "string", description: "City name" }
|
|
87
|
+
},
|
|
88
|
+
required: ["location"]
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def execute(location:)
|
|
92
|
+
# In reality, call a weather API
|
|
93
|
+
{ temperature: 72, conditions: "sunny", location: location }
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class CalculatorTool < Helicone::Tool
|
|
98
|
+
description "Evaluate a math expression"
|
|
99
|
+
|
|
100
|
+
parameters(
|
|
101
|
+
type: "object",
|
|
102
|
+
properties: {
|
|
103
|
+
expression: { type: "string", description: "Math expression like '2 + 2'" }
|
|
104
|
+
},
|
|
105
|
+
required: ["expression"]
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
def execute(expression:)
|
|
109
|
+
{ result: eval(expression) }
|
|
110
|
+
rescue => e
|
|
111
|
+
{ error: e.message }
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Run the agent
|
|
116
|
+
agent = Helicone::Agent.new(
|
|
117
|
+
tools: [WeatherTool, CalculatorTool],
|
|
118
|
+
system: "You are a helpful assistant with access to weather and calculator tools."
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
result = agent.run("What's the weather in San Francisco?")
|
|
122
|
+
puts result.content
|
|
123
|
+
puts "Iterations: #{result.iterations}"
|
|
124
|
+
puts "Tool calls made: #{result.tool_calls_made}"
|
|
125
|
+
|
|
126
|
+
# Continue the conversation
|
|
127
|
+
result = agent.continue("What about New York?")
|
|
128
|
+
puts result.content
|
|
129
|
+
|
|
130
|
+
# ============================================
|
|
131
|
+
# Agent with Context
|
|
132
|
+
# ============================================
|
|
133
|
+
|
|
134
|
+
# Context is passed to tool instances
|
|
135
|
+
class DatabaseTool < Helicone::Tool
|
|
136
|
+
description "Query the database"
|
|
137
|
+
|
|
138
|
+
parameters(
|
|
139
|
+
type: "object",
|
|
140
|
+
properties: {
|
|
141
|
+
query: { type: "string" }
|
|
142
|
+
},
|
|
143
|
+
required: ["query"]
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def execute(query:)
|
|
147
|
+
# Access context passed from agent
|
|
148
|
+
user_id = context[:user_id]
|
|
149
|
+
{ results: "Data for user #{user_id}: #{query}" }
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
agent = Helicone::Agent.new(
|
|
154
|
+
tools: [DatabaseTool],
|
|
155
|
+
context: { user_id: 123, db: some_db_connection }
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
result = agent.run("Find my recent orders")
|
|
159
|
+
|
|
160
|
+
# ============================================
|
|
161
|
+
# Inspecting Responses
|
|
162
|
+
# ============================================
|
|
163
|
+
|
|
164
|
+
client = Helicone::Client.new
|
|
165
|
+
response = client.chat(
|
|
166
|
+
messages: [Helicone::Message.user_text("Hello")]
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
response.content # => "Hello! How can I help?"
|
|
170
|
+
response.role # => "assistant"
|
|
171
|
+
response.model # => "gpt-4o"
|
|
172
|
+
response.finish_reason # => "stop"
|
|
173
|
+
response.prompt_tokens # => 10
|
|
174
|
+
response.completion_tokens # => 15
|
|
175
|
+
response.total_tokens # => 25
|
|
176
|
+
response.success? # => true
|
|
177
|
+
response.raw # => full raw response hash
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: helicone-rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Genevere
|
|
@@ -93,6 +93,7 @@ files:
|
|
|
93
93
|
- readme-assets/helicone-dashboard.png
|
|
94
94
|
- readme-assets/helicone-model-registry.png
|
|
95
95
|
- readme-assets/helicone-session-flamegraph.png
|
|
96
|
+
- sample.rb
|
|
96
97
|
homepage: https://github.com/genevere-inc/helicone-rb
|
|
97
98
|
licenses:
|
|
98
99
|
- MIT
|