helicone-rb 0.0.1 → 0.1.0
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 +50 -6
- data/lib/helicone/client.rb +3 -6
- data/lib/helicone/configuration.rb +4 -3
- data/lib/helicone/version.rb +1 -1
- data/readme-assets/helicone-dashboard.png +0 -0
- data/readme-assets/helicone-model-registry.png +0 -0
- data/readme-assets/helicone-session-flamegraph.png +0 -0
- data/sample.rb +177 -0
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30551d818f767a29ad080d1ec1beffc42a5346e0e4f94f9cbe112b6c7aaaa9b5
|
|
4
|
+
data.tar.gz: 3505af534452304f15f075a0fbde6d334c8a1b3cc8a4a85f61abc292fe564226
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2e09d82c356de9e0ca25af6846e582c63bbc773fab7c7f257e0e06a2dcf4ebbb0ee6af983457a7fd61fa9b5ec84116e7621017cf4fb8216649bdfc23fd6d14a9
|
|
7
|
+
data.tar.gz: 44affe9ff8922ba1254567b88cb7ac4b280aa3b95eac4162969c6ac606e6be5194f8b2b1784feaba1cdc73d340d67cef078f5bf7e63b4caa36b401a02ce384d8
|
data/README.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
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
4
|
|
|
5
|
+
## Why Helicone?
|
|
6
|
+
|
|
7
|
+
[Helicone](https://helicone.ai) is an AI gateway that sits between your application and LLM providers (OpenAI, Anthropic, etc.). It provides:
|
|
8
|
+
|
|
9
|
+
- **Unified billing** - One API key, one bill, access to multiple providers
|
|
10
|
+
- **Request logging** - Every API call is logged with full request/response details
|
|
11
|
+
- **Cost tracking** - See exactly what you're spending per user, session, or feature
|
|
12
|
+
- **Latency monitoring** - Track response times and identify slow requests
|
|
13
|
+
- **Rate limiting & caching** - Built-in protection and optimization
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
*The Helicone dashboard shows all your LLM requests with latency, cost, and token usage at a glance.*
|
|
18
|
+
|
|
5
19
|
## Installation
|
|
6
20
|
|
|
7
21
|
Add this line to your application's Gemfile:
|
|
@@ -24,14 +38,30 @@ gem install helicone-rb
|
|
|
24
38
|
|
|
25
39
|
## Configuration
|
|
26
40
|
|
|
27
|
-
|
|
41
|
+
First, [sign up for a Helicone account](https://us.helicone.ai/signup) to get your API key.
|
|
42
|
+
|
|
43
|
+
Set the `HELICONE_API_KEY` environment variable:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
export HELICONE_API_KEY=sk-helicone-your-key-here
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
That's it! The gem reads from `ENV["HELICONE_API_KEY"]` automatically.
|
|
50
|
+
|
|
51
|
+
Helicone handles billing and routes requests to OpenAI or other providers. See the [model registry](https://www.helicone.ai/models) for supported models including GPT-4, Claude, Llama, and more.
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
*Browse all available models with pricing, context windows, and capabilities in the Helicone model registry.*
|
|
56
|
+
|
|
57
|
+
### Optional Configuration
|
|
58
|
+
|
|
59
|
+
You can optionally configure the default model and logger:
|
|
28
60
|
|
|
29
61
|
```ruby
|
|
30
62
|
Helicone.configure do |config|
|
|
31
|
-
config.
|
|
32
|
-
config.
|
|
33
|
-
config.default_model = "gpt-4" # default
|
|
34
|
-
config.logger = Logger.new($stdout) # default
|
|
63
|
+
config.default_model = "gpt-4o" # default
|
|
64
|
+
config.logger = Logger.new($stdout) # default
|
|
35
65
|
end
|
|
36
66
|
```
|
|
37
67
|
|
|
@@ -98,7 +128,7 @@ response = client.chat(messages: [message])
|
|
|
98
128
|
|
|
99
129
|
## Session and Account Tracking
|
|
100
130
|
|
|
101
|
-
Track conversations and costs in the Helicone dashboard:
|
|
131
|
+
Track conversations and attribute costs to specific users or accounts in the Helicone dashboard:
|
|
102
132
|
|
|
103
133
|
```ruby
|
|
104
134
|
client = Helicone::Client.new(
|
|
@@ -109,6 +139,12 @@ client = Helicone::Client.new(
|
|
|
109
139
|
)
|
|
110
140
|
```
|
|
111
141
|
|
|
142
|
+
Sessions group related requests together, letting you see the full flow of a conversation or agentic workflow:
|
|
143
|
+
|
|
144
|
+

|
|
145
|
+
|
|
146
|
+
*The session view shows each request in a conversation as a flamegraph, with timing and token usage for each step. Great for debugging agent loops and understanding where time and tokens are spent.*
|
|
147
|
+
|
|
112
148
|
## Agentic Framework
|
|
113
149
|
|
|
114
150
|
Build AI agents that can use tools to accomplish tasks.
|
|
@@ -254,6 +290,14 @@ bundle install
|
|
|
254
290
|
bundle exec rspec
|
|
255
291
|
```
|
|
256
292
|
|
|
293
|
+
### Live Integration Tests
|
|
294
|
+
|
|
295
|
+
To run tests against the actual Helicone API:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
HELICONE_LIVE_TEST=true HELICONE_API_KEY=your_key bundle exec rspec spec/helicone/integration_spec.rb
|
|
299
|
+
```
|
|
300
|
+
|
|
257
301
|
## Contributing
|
|
258
302
|
|
|
259
303
|
Bug reports and pull requests are welcome on GitHub at https://github.com/genevere-inc/helicone-rb.
|
data/lib/helicone/client.rb
CHANGED
|
@@ -6,17 +6,14 @@ module Helicone
|
|
|
6
6
|
|
|
7
7
|
# Initialize with optional session/account context for Helicone tracking
|
|
8
8
|
#
|
|
9
|
-
# @param api_key [String] OpenAI API key (defaults to Helicone.configuration.api_key)
|
|
10
9
|
# @param session_id [String, Integer] Conversation/session ID for Helicone grouping
|
|
11
10
|
# @param session_name [String] Human-readable session name
|
|
12
11
|
# @param account_id [String, Integer] Account ID for cost tracking per account
|
|
13
12
|
# @param account_name [String] Human-readable account name
|
|
14
|
-
def initialize(
|
|
15
|
-
config = Helicone.configuration
|
|
16
|
-
|
|
13
|
+
def initialize(session_id: nil, session_name: nil, account_id: nil, account_name: nil)
|
|
17
14
|
@client = OpenAI::Client.new(
|
|
18
|
-
access_token:
|
|
19
|
-
uri_base:
|
|
15
|
+
access_token: ENV["HELICONE_API_KEY"],
|
|
16
|
+
uri_base: Helicone::URI_BASE
|
|
20
17
|
)
|
|
21
18
|
|
|
22
19
|
# Add Helicone session headers if provided
|
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
require "logger"
|
|
4
4
|
|
|
5
5
|
module Helicone
|
|
6
|
+
URI_BASE = "https://ai-gateway.helicone.ai/v1"
|
|
7
|
+
|
|
6
8
|
class Configuration
|
|
7
|
-
attr_accessor :
|
|
9
|
+
attr_accessor :logger, :default_model
|
|
8
10
|
|
|
9
11
|
# Initialize configuration with defaults
|
|
10
12
|
#
|
|
11
13
|
# @return [Configuration]
|
|
12
14
|
def initialize
|
|
13
|
-
@
|
|
14
|
-
@default_model = "gpt-4"
|
|
15
|
+
@default_model = "gpt-4o"
|
|
15
16
|
@logger = Logger.new($stdout, level: Logger::INFO)
|
|
16
17
|
end
|
|
17
18
|
end
|
data/lib/helicone/version.rb
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
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.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Genevere
|
|
@@ -90,6 +90,10 @@ files:
|
|
|
90
90
|
- lib/helicone/tool.rb
|
|
91
91
|
- lib/helicone/tool_call.rb
|
|
92
92
|
- lib/helicone/version.rb
|
|
93
|
+
- readme-assets/helicone-dashboard.png
|
|
94
|
+
- readme-assets/helicone-model-registry.png
|
|
95
|
+
- readme-assets/helicone-session-flamegraph.png
|
|
96
|
+
- sample.rb
|
|
93
97
|
homepage: https://github.com/genevere-inc/helicone-rb
|
|
94
98
|
licenses:
|
|
95
99
|
- MIT
|