helicone-rb 0.1.3 → 0.2.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/lib/helicone/agent.rb +21 -6
- 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: 5102ee7eb685c57698bb42b3a1818b1690b634a1f04fe1a2d5689c7d8b24c423
|
|
4
|
+
data.tar.gz: 0a37bb68ba76a4b51c8472d96d01cde87fd98df5e35d21b1d6519cb6b3991a9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8a801ebeb724ee8428a7c6ab73900a7dddabf1ad7524efe19391e431fc2bdb4bffe91bc9053c08c31f1e7e6398371cdcdd97437994cd4c9fec1532982e2d2f13
|
|
7
|
+
data.tar.gz: 2abcda0fcc478de60f6192967f9465f815d68476495b6c5988145bcbc7361b0f4dfcf8ef97a3924e09302c48c058f556bd848111eda8e8fe977ffec01dfee9f9
|
data/lib/helicone/agent.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Helicone
|
|
|
4
4
|
class Agent
|
|
5
5
|
MAX_ITERATIONS = 10
|
|
6
6
|
|
|
7
|
-
attr_reader :client, :tools, :messages, :context
|
|
7
|
+
attr_reader :client, :tools, :messages, :context, :turn_model, :response_model
|
|
8
8
|
|
|
9
9
|
# Create an agent with tools and optional context
|
|
10
10
|
#
|
|
@@ -14,10 +14,14 @@ module Helicone
|
|
|
14
14
|
# @param context [Object] Context object passed to tool#initialize
|
|
15
15
|
# @param system_prompt [String] System prompt
|
|
16
16
|
# @param messages [Array<Helicone::Message>] Initial messages (for continuing conversations)
|
|
17
|
-
|
|
17
|
+
# @param turn_model [String] Model for tool-calling turns (defaults to Helicone.configuration.default_model)
|
|
18
|
+
# @param response_model [String] Model for final response (defaults to turn_model)
|
|
19
|
+
def initialize(client: nil, session: nil, tools: [], context: nil, system_prompt: nil, messages: [], turn_model: nil, response_model: nil)
|
|
18
20
|
@client = client || build_client(session: session)
|
|
19
21
|
@tools = tools
|
|
20
22
|
@context = context
|
|
23
|
+
@turn_model = turn_model
|
|
24
|
+
@response_model = response_model || turn_model
|
|
21
25
|
@messages = messages.dup
|
|
22
26
|
|
|
23
27
|
# Add system message at the start if provided and not already present
|
|
@@ -36,7 +40,7 @@ module Helicone
|
|
|
36
40
|
|
|
37
41
|
iterations = 0
|
|
38
42
|
while iterations < max_iterations
|
|
39
|
-
response = call_llm
|
|
43
|
+
response = call_llm(model: @turn_model)
|
|
40
44
|
|
|
41
45
|
tool_calls = response.tool_calls
|
|
42
46
|
if tool_calls && !tool_calls.empty?
|
|
@@ -55,7 +59,17 @@ module Helicone
|
|
|
55
59
|
|
|
56
60
|
iterations += 1
|
|
57
61
|
else
|
|
58
|
-
# No tool calls -
|
|
62
|
+
# No tool calls - if response_model differs, make final call with it
|
|
63
|
+
if @response_model && @response_model != @turn_model
|
|
64
|
+
final_response = @client.chat(messages: @messages, model: @response_model)
|
|
65
|
+
return AgentResult.new(
|
|
66
|
+
content: final_response.content,
|
|
67
|
+
messages: @messages,
|
|
68
|
+
iterations: iterations,
|
|
69
|
+
response: final_response
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
59
73
|
return AgentResult.new(
|
|
60
74
|
content: response.content,
|
|
61
75
|
messages: @messages,
|
|
@@ -66,7 +80,7 @@ module Helicone
|
|
|
66
80
|
end
|
|
67
81
|
|
|
68
82
|
# Max iterations reached - make one final call without tools to get a response
|
|
69
|
-
final_response = @client.chat(messages: @messages)
|
|
83
|
+
final_response = @client.chat(messages: @messages, model: @response_model)
|
|
70
84
|
|
|
71
85
|
AgentResult.new(
|
|
72
86
|
content: final_response.content,
|
|
@@ -92,9 +106,10 @@ module Helicone
|
|
|
92
106
|
Helicone.configuration.logger
|
|
93
107
|
end
|
|
94
108
|
|
|
95
|
-
def call_llm
|
|
109
|
+
def call_llm(model: nil)
|
|
96
110
|
@client.chat(
|
|
97
111
|
messages: @messages,
|
|
112
|
+
model: model,
|
|
98
113
|
tools: tools_for_api,
|
|
99
114
|
tool_choice: "auto"
|
|
100
115
|
)
|
data/lib/helicone/version.rb
CHANGED