helicone-rb 0.2.0 → 0.2.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/lib/helicone/agent.rb +9 -8
- data/lib/helicone/client.rb +1 -1
- data/lib/helicone/configuration.rb +3 -2
- data/lib/helicone/message.rb +4 -2
- data/lib/helicone/tool.rb +14 -0
- data/lib/helicone/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac034e0153e6ec01bbe008066b48c58c754a103b56461fdc24c4e0d1bc05d4d4
|
|
4
|
+
data.tar.gz: c95390c56a649b16fde96f7be81a1ef537671a19a129039d23d272ea391cfdaf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4726d935f0db71a01ece1db9f29d758f2c4f47e04b79cb62ed986f1180abf6415576ccfa94e1de6e6d73671d21448c8067b1c74b6b55052195548c67533f64b
|
|
7
|
+
data.tar.gz: 1b1b93d6cffe0e19a41dbbefec03ab019bda992c4eb7a0dfc7770c60852f7dfde8d879d634aeeec10ca75837e799919be2ecc14f9f601efbb4b63636922b43ec
|
data/lib/helicone/agent.rb
CHANGED
|
@@ -30,13 +30,13 @@ module Helicone
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
# Run the agent with
|
|
33
|
+
# Run the agent with an optional prompt, executing tools until done
|
|
34
34
|
#
|
|
35
|
-
# @param prompt [String] User prompt to
|
|
35
|
+
# @param prompt [String, nil] User prompt to add (nil to use existing messages)
|
|
36
36
|
# @param max_iterations [Integer] Maximum tool execution loops
|
|
37
37
|
# @return [AgentResult]
|
|
38
|
-
def run(prompt, max_iterations: MAX_ITERATIONS)
|
|
39
|
-
@messages << Message.user_text(prompt)
|
|
38
|
+
def run(prompt = nil, max_iterations: MAX_ITERATIONS)
|
|
39
|
+
@messages << Message.user_text(prompt) if prompt
|
|
40
40
|
|
|
41
41
|
iterations = 0
|
|
42
42
|
while iterations < max_iterations
|
|
@@ -121,16 +121,17 @@ module Helicone
|
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
def execute_tool(tool_call)
|
|
124
|
-
|
|
124
|
+
tool = find_tool(tool_call.name)
|
|
125
125
|
|
|
126
|
-
unless
|
|
126
|
+
unless tool
|
|
127
127
|
logger.warn("[Helicone::Agent] Unknown tool: #{tool_call.name}")
|
|
128
128
|
return { error: "Unknown tool: #{tool_call.name}" }
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
logger.info("[Helicone::Agent] Executing tool: #{tool_call.name} with #{tool_call.arguments}")
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
# Support both tool classes and tool instances
|
|
134
|
+
tool_instance = tool.is_a?(Class) ? tool.new(@context) : tool
|
|
134
135
|
result = tool_instance.execute(**tool_call.arguments)
|
|
135
136
|
|
|
136
137
|
result_preview = result.inspect
|
|
@@ -143,7 +144,7 @@ module Helicone
|
|
|
143
144
|
{ error: e.message }
|
|
144
145
|
end
|
|
145
146
|
|
|
146
|
-
def
|
|
147
|
+
def find_tool(name)
|
|
147
148
|
@tools.find { |t| t.function_name == name }
|
|
148
149
|
end
|
|
149
150
|
|
data/lib/helicone/client.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Helicone
|
|
|
13
13
|
def initialize(session_id: nil, session_name: nil, account_id: nil, account_name: nil)
|
|
14
14
|
@client = OpenAI::Client.new(
|
|
15
15
|
access_token: ENV["HELICONE_API_KEY"],
|
|
16
|
-
uri_base: Helicone
|
|
16
|
+
uri_base: Helicone.configuration.base_url
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
# Add Helicone session headers if provided
|
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
require "logger"
|
|
4
4
|
|
|
5
5
|
module Helicone
|
|
6
|
-
|
|
6
|
+
DEFAULT_BASE_URL = "https://ai-gateway.helicone.ai/v1"
|
|
7
7
|
|
|
8
8
|
class Configuration
|
|
9
|
-
attr_accessor :logger, :default_model
|
|
9
|
+
attr_accessor :logger, :default_model, :base_url
|
|
10
10
|
|
|
11
11
|
# Initialize configuration with defaults
|
|
12
12
|
#
|
|
13
13
|
# @return [Configuration]
|
|
14
14
|
def initialize
|
|
15
15
|
@default_model = "gpt-4o"
|
|
16
|
+
@base_url = DEFAULT_BASE_URL
|
|
16
17
|
@logger = Logger.new($stdout, level: Logger::INFO)
|
|
17
18
|
end
|
|
18
19
|
end
|
data/lib/helicone/message.rb
CHANGED
|
@@ -113,9 +113,11 @@ module Helicone
|
|
|
113
113
|
#
|
|
114
114
|
# @return [Hash] Message formatted for the API
|
|
115
115
|
def to_h
|
|
116
|
-
# If this is a raw message (assistant with tool_calls), return it as-is
|
|
117
116
|
if @raw_message
|
|
118
|
-
|
|
117
|
+
# Select only the fields needed for the API
|
|
118
|
+
hash = { role: @raw_message[:role], content: @raw_message[:content] }
|
|
119
|
+
hash[:tool_calls] = @raw_message[:tool_calls] if @raw_message[:tool_calls]
|
|
120
|
+
hash
|
|
119
121
|
else
|
|
120
122
|
hash = { role: role, content: content }
|
|
121
123
|
hash[:tool_call_id] = tool_call_id if tool_call_id
|
data/lib/helicone/tool.rb
CHANGED
|
@@ -98,5 +98,19 @@ module Helicone
|
|
|
98
98
|
def execute(**args)
|
|
99
99
|
raise NotImplementedError, "Subclasses must implement #execute"
|
|
100
100
|
end
|
|
101
|
+
|
|
102
|
+
# Delegate to class method for instances
|
|
103
|
+
#
|
|
104
|
+
# @return [Hash] Tool definition formatted for OpenAI API
|
|
105
|
+
def to_openai_tool
|
|
106
|
+
self.class.to_openai_tool
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Delegate to class method for instances
|
|
110
|
+
#
|
|
111
|
+
# @return [String] The function name
|
|
112
|
+
def function_name
|
|
113
|
+
self.class.function_name
|
|
114
|
+
end
|
|
101
115
|
end
|
|
102
116
|
end
|
data/lib/helicone/version.rb
CHANGED