Skip to content

Commit d113c39

Browse files
authored
Refine warning behavior for unsupported options (patterns-ai-core#983)
## Summary Currently, the warning for unsupported options is shown regardless of whether an explicit value is provided. This PR updates the behavior so that the warning is shown only when the unsupported options is explicitly set by the user. Tests have been updated to reflect usage without warnings, which is what users would expect. ## Additional Information Note that `parallel_tool_calls` option in `Langchain::Assistant#initialize` defaults to `true`: https://github.com/patterns-ai-core/langchainrb/blob/0.19.5/lib/langchain/assistant.rb#L45 However, whether this option is supported depends on the underlying LLM. Therefore, for LLMs that do not support `parallel_tool_calls`, the option should effectively not be `true`. Since this would involve changing the default behavior of `parallel_tool_calls`, it is considered out of scope for this PR and should be addressed separately.
1 parent a374c49 commit d113c39

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

lib/langchain/assistant/llm/adapters/aws_bedrock_anthropic.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class AwsBedrockAnthropic < Anthropic
1010
# @param [String] choice
1111
# @param [Boolean] _parallel_tool_calls
1212
# @return [Hash]
13-
def build_tool_choice(choice, _parallel_tool_calls)
13+
def build_tool_choice(choice, parallel_tool_calls)
1414
# Aws Bedrock hosted Anthropic does not support parallel tool calls
15-
Langchain.logger.warn "WARNING: parallel_tool_calls is not supported by AWS Bedrock Anthropic currently"
15+
Langchain.logger.warn "WARNING: parallel_tool_calls is not supported by AWS Bedrock Anthropic currently" if parallel_tool_calls
1616

1717
tool_choice_object = {}
1818

lib/langchain/assistant/llm/adapters/google_gemini.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def build_chat_params(
2020
tool_choice:,
2121
parallel_tool_calls:
2222
)
23-
Langchain.logger.warn "WARNING: `parallel_tool_calls:` is not supported by Google Gemini currently"
23+
Langchain.logger.warn "WARNING: `parallel_tool_calls:` is not supported by Google Gemini currently" if parallel_tool_calls
2424

2525
params = {messages: messages}
2626
if tools.any?

lib/langchain/assistant/llm/adapters/mistral_ai.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def build_chat_params(
2020
tool_choice:,
2121
parallel_tool_calls:
2222
)
23-
Langchain.logger.warn "WARNING: `parallel_tool_calls:` is not supported by Mistral AI currently"
23+
Langchain.logger.warn "WARNING: `parallel_tool_calls:` is not supported by Mistral AI currently" if parallel_tool_calls
2424

2525
params = {messages: messages}
2626
if tools.any?

lib/langchain/assistant/llm/adapters/ollama.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def build_chat_params(
2020
tool_choice:,
2121
parallel_tool_calls:
2222
)
23-
Langchain.logger.warn "WARNING: `parallel_tool_calls:` is not supported by Ollama currently"
24-
Langchain.logger.warn "WARNING: `tool_choice:` is not supported by Ollama currently"
23+
Langchain.logger.warn "WARNING: `parallel_tool_calls:` is not supported by Ollama currently" if parallel_tool_calls
24+
Langchain.logger.warn "WARNING: `tool_choice:` is not supported by Ollama currently" if tool_choice
2525

2626
params = {messages: messages}
2727
if tools.any?

spec/langchain/assistant/llm/adapters/aws_bedrock_anthropic_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RSpec.describe Langchain::Assistant::LLM::Adapters::AwsBedrockAnthropic do
44
describe "#build_tool_choice" do
55
it "returns the tool choice object with 'auto'" do
6-
expect(subject.send(:build_tool_choice, "auto", true)).to eq({type: "auto"})
6+
expect(subject.send(:build_tool_choice, "auto", false)).to eq({type: "auto"})
77
end
88

99
it "returns the tool choice object with selected tool function" do

spec/langchain/assistant/llm/adapters/ollama_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
messages: [{role: "user", content: "Hello"}],
99
instructions: "Instructions",
1010
tools: [Langchain::Tool::Calculator.new],
11-
tool_choice: "langchain_tool_calculator__execute",
11+
tool_choice: nil,
1212
parallel_tool_calls: false
1313
)
1414
).to eq({

0 commit comments

Comments
 (0)