Skip to content

Commit 4b447e3

Browse files
Fix wrong published version (#888)
* Minor refactor * Fix wrong published version
1 parent a47bfce commit 4b447e3

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## [Unreleased]
1313

14-
## [0.19.2] - 2024-11-25
14+
## [0.19.2] - 2024-11-26
1515
- [FEATURE] [https://github.com/patterns-ai-core/langchainrb/pull/884] Add `tool_execution_callback` to `Langchain::Assistant`, a callback function (proc, lambda) that is called right before a tool is executed
1616

1717
## [0.19.1] - 2024-11-21

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
langchainrb (1.19.2)
4+
langchainrb (0.19.2)
55
baran (~> 0.1.9)
66
json-schema (~> 4)
77
matrix

lib/langchain/assistant.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,26 @@ def chat_with_llm
354354
def run_tools(tool_calls)
355355
# Iterate over each function invocation and submit tool output
356356
tool_calls.each do |tool_call|
357-
tool_call_id, tool_name, method_name, tool_arguments = @llm_adapter.extract_tool_call_args(tool_call: tool_call)
357+
run_tool(tool_call)
358+
end
359+
end
358360

359-
tool_instance = tools.find do |t|
360-
t.class.tool_name == tool_name
361-
end or raise ArgumentError, "Tool: #{tool_name} not found in assistant.tools"
361+
# Run the tool call
362+
#
363+
# @param tool_call [Hash] The tool call to run
364+
# @return [Object] The result of the tool call
365+
def run_tool(tool_call)
366+
tool_call_id, tool_name, method_name, tool_arguments = @llm_adapter.extract_tool_call_args(tool_call: tool_call)
362367

363-
# Call the callback if set
364-
tool_execution_callback.call(tool_call_id, tool_name, method_name, tool_arguments) if tool_execution_callback # rubocop:disable Style/SafeNavigation
365-
output = tool_instance.send(method_name, **tool_arguments)
368+
tool_instance = tools.find do |t|
369+
t.class.tool_name == tool_name
370+
end or raise ArgumentError, "Tool: #{tool_name} not found in assistant.tools"
366371

367-
submit_tool_output(tool_call_id: tool_call_id, output: output)
368-
end
372+
# Call the callback if set
373+
tool_execution_callback.call(tool_call_id, tool_name, method_name, tool_arguments) if tool_execution_callback # rubocop:disable Style/SafeNavigation
374+
output = tool_instance.send(method_name, **tool_arguments)
375+
376+
submit_tool_output(tool_call_id: tool_call_id, output: output)
369377
end
370378

371379
# Build a message

lib/langchain/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Langchain
4-
VERSION = "1.19.2"
4+
VERSION = "0.19.2"
55
end

0 commit comments

Comments
 (0)