Skip to content

Commit

Permalink
Fix wrong published version (#888)
Browse files Browse the repository at this point in the history
* Minor refactor

* Fix wrong published version
  • Loading branch information
andreibondarev authored Nov 26, 2024
1 parent a47bfce commit 4b447e3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## [Unreleased]

## [0.19.2] - 2024-11-25
## [0.19.2] - 2024-11-26
- [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

## [0.19.1] - 2024-11-21
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
langchainrb (1.19.2)
langchainrb (0.19.2)
baran (~> 0.1.9)
json-schema (~> 4)
matrix
Expand Down
26 changes: 17 additions & 9 deletions lib/langchain/assistant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,26 @@ def chat_with_llm
def run_tools(tool_calls)
# Iterate over each function invocation and submit tool output
tool_calls.each do |tool_call|
tool_call_id, tool_name, method_name, tool_arguments = @llm_adapter.extract_tool_call_args(tool_call: tool_call)
run_tool(tool_call)
end
end

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

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

submit_tool_output(tool_call_id: tool_call_id, output: output)
end
# Call the callback if set
tool_execution_callback.call(tool_call_id, tool_name, method_name, tool_arguments) if tool_execution_callback # rubocop:disable Style/SafeNavigation
output = tool_instance.send(method_name, **tool_arguments)

submit_tool_output(tool_call_id: tool_call_id, output: output)
end

# Build a message
Expand Down
2 changes: 1 addition & 1 deletion lib/langchain/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Langchain
VERSION = "1.19.2"
VERSION = "0.19.2"
end

0 comments on commit 4b447e3

Please sign in to comment.