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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5102ee7eb685c57698bb42b3a1818b1690b634a1f04fe1a2d5689c7d8b24c423
4
- data.tar.gz: 0a37bb68ba76a4b51c8472d96d01cde87fd98df5e35d21b1d6519cb6b3991a9d
3
+ metadata.gz: ac034e0153e6ec01bbe008066b48c58c754a103b56461fdc24c4e0d1bc05d4d4
4
+ data.tar.gz: c95390c56a649b16fde96f7be81a1ef537671a19a129039d23d272ea391cfdaf
5
5
  SHA512:
6
- metadata.gz: 8a801ebeb724ee8428a7c6ab73900a7dddabf1ad7524efe19391e431fc2bdb4bffe91bc9053c08c31f1e7e6398371cdcdd97437994cd4c9fec1532982e2d2f13
7
- data.tar.gz: 2abcda0fcc478de60f6192967f9465f815d68476495b6c5988145bcbc7361b0f4dfcf8ef97a3924e09302c48c058f556bd848111eda8e8fe977ffec01dfee9f9
6
+ metadata.gz: a4726d935f0db71a01ece1db9f29d758f2c4f47e04b79cb62ed986f1180abf6415576ccfa94e1de6e6d73671d21448c8067b1c74b6b55052195548c67533f64b
7
+ data.tar.gz: 1b1b93d6cffe0e19a41dbbefec03ab019bda992c4eb7a0dfc7770c60852f7dfde8d879d634aeeec10ca75837e799919be2ecc14f9f601efbb4b63636922b43ec
@@ -30,13 +30,13 @@ module Helicone
30
30
  end
31
31
  end
32
32
 
33
- # Run the agent with a prompt, executing tools until done
33
+ # Run the agent with an optional prompt, executing tools until done
34
34
  #
35
- # @param prompt [String] User prompt to start with
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
- tool_class = find_tool_class(tool_call.name)
124
+ tool = find_tool(tool_call.name)
125
125
 
126
- unless tool_class
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
- tool_instance = tool_class.new(@context)
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 find_tool_class(name)
147
+ def find_tool(name)
147
148
  @tools.find { |t| t.function_name == name }
148
149
  end
149
150
 
@@ -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::URI_BASE
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
- URI_BASE = "https://ai-gateway.helicone.ai/v1"
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
@@ -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
- @raw_message
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Helicone
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genevere