From 77a8229e85a98c198f5eeabeb01aa76436e9eff5 Mon Sep 17 00:00:00 2001 From: Andrei Bondarev Date: Wed, 18 Sep 2024 13:24:21 -0400 Subject: [PATCH] Patch up ContextualLogger (#785) * Ollama logging uses the current Langchain.logger.level * ContextualLogger outputs everything passed in --- lib/langchain/contextual_logger.rb | 2 ++ lib/langchain/llm/ollama.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/langchain/contextual_logger.rb b/lib/langchain/contextual_logger.rb index 5df8c1172..4ef84c62b 100644 --- a/lib/langchain/contextual_logger.rb +++ b/lib/langchain/contextual_logger.rb @@ -49,6 +49,8 @@ def method_missing(method, *args, **kwargs, &block) "[#{for_class_name}]:" end log_line_parts << colorize(args.first, MESSAGE_COLOR_OPTIONS[method]) + log_line_parts << kwargs if !!kwargs && kwargs.any? + log_line_parts << block.call if block log_line = log_line_parts.compact.join(" ") @logger.send( diff --git a/lib/langchain/llm/ollama.rb b/lib/langchain/llm/ollama.rb index a9daf65f5..f2741a470 100644 --- a/lib/langchain/llm/ollama.rb +++ b/lib/langchain/llm/ollama.rb @@ -270,7 +270,7 @@ def client conn.request :json conn.response :json conn.response :raise_error - conn.response :logger, nil, {headers: true, bodies: true, errors: true} + conn.response :logger, Langchain.logger, {headers: true, bodies: true, errors: true} end end