Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop Colorize due to GPL license #727

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## [Unreleased]
- Drop `colorize` which is GPL-licensed in favour of `rainbow`

## [0.15.0] - 2024-08-14
- Fix Langchain::Assistant when llm is Anthropic
Expand Down Expand Up @@ -135,7 +136,7 @@
- AWS Bedrock is available as an LLM provider. Available models from AI21, Cohere, AWS, and Anthropic.

## [0.7.3] - 2023-11-08
- LLM response passes through the context in RAG cases
- LLM response passes through the context in RAG cases
- Fix gpt-4 token length validation

## [0.7.2] - 2023-11-02
Expand Down Expand Up @@ -180,7 +181,7 @@

## [0.6.13] - 2023-08-23
- Add `k:` parameter to all `ask()` vector search methods
- Bump Faraday to 2.x
- Bump Faraday to 2.x

## [0.6.12] - 2023-08-13

Expand Down
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ PATH
specs:
langchainrb (0.15.0)
baran (~> 0.1.9)
colorize (~> 1.1.0)
json-schema (~> 4)
matrix
pragmatic_segmenter (~> 0.3.0)
rainbow (~> 3.1.0)
to_bool (~> 2.0.0)
zeitwerk (~> 2.5)

Expand Down Expand Up @@ -73,7 +73,6 @@ GEM
coderay (1.1.3)
cohere-ruby (0.9.10)
faraday (>= 2.0.1, < 3.0)
colorize (1.1.0)
concurrent-ruby (1.3.1)
connection_pool (2.4.1)
crack (1.0.0)
Expand Down
2 changes: 1 addition & 1 deletion langchain.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
# dependencies
# Not sure if we should require this as it only applies to OpenAI usecase.
spec.add_dependency "baran", "~> 0.1.9"
spec.add_dependency "colorize", "~> 1.1.0"
spec.add_dependency "rainbow", "~> 3.1.0"
spec.add_dependency "json-schema", "~> 4"
spec.add_dependency "zeitwerk", "~> 2.5"
spec.add_dependency "pragmatic_segmenter", "~> 0.3.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/langchain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "logger"
require "pathname"
require "colorize"
require "rainbow"
require "to_bool"
require "zeitwerk"
loader = Zeitwerk::Loader.for_gem
Expand Down
12 changes: 9 additions & 3 deletions lib/langchain/contextual_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,25 @@ def method_missing(method, *args, **kwargs, &block)
for_class_name = for_class&.name

log_line_parts = []
log_line_parts << "[Langchain.rb]".colorize(color: :yellow)
log_line_parts << colorize("[Langchain.rb]", color: :yellow)
log_line_parts << if for_class.respond_to?(:logger_options)
"[#{for_class_name}]".colorize(for_class.logger_options) + ":"
colorize("[#{for_class_name}]", for_class.logger_options) + ":"
elsif for_class_name
"[#{for_class_name}]:"
end
log_line_parts << args.first.colorize(MESSAGE_COLOR_OPTIONS[method])
log_line_parts << colorize(args.first, MESSAGE_COLOR_OPTIONS[method])
log_line = log_line_parts.compact.join(" ")

@logger.send(
method,
log_line
)
end

private

def colorize(line, options)
Langchain::Utils::Colorizer.colorize(line, options)
end
end
end
19 changes: 19 additions & 0 deletions lib/langchain/utils/colorizer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Langchain
module Utils
class Colorizer
def self.colorize(line, options)
decorated_line = Rainbow(line)
options.each_pair.each do |modifier, value|
decorated_line = if modifier == :mode
decorated_line.public_send(value)
else
decorated_line.public_send(modifier, value)
end
end
decorated_line
end
end
end
end
16 changes: 10 additions & 6 deletions spec/langchain/contextual_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it "#info" do
expect(logger).to receive(:info).with(
<<~LINE.strip
#{"[Langchain.rb]".yellow} #{"Hello World".white}
#{colorize("[Langchain.rb]", color: :yellow)} #{colorize("Hello World", color: :white)}
LINE
)
subject.info("Hello World")
Expand All @@ -18,7 +18,7 @@
it "#warn" do
expect(logger).to receive(:warn).with(
<<~LINE.strip
#{"[Langchain.rb]".yellow} #{"Hello World".colorize(color: :yellow, mode: :bold)}
#{colorize("[Langchain.rb]", color: :yellow)} #{colorize("Hello World", color: :yellow, mode: :bold)}
LINE
)
subject.warn("Hello World")
Expand All @@ -27,7 +27,7 @@
it "#debug" do
expect(logger).to receive(:debug).with(
<<~LINE.strip
#{"[Langchain.rb]".yellow} #{"Hello World".white}
#{colorize("[Langchain.rb]", color: :yellow)} #{colorize("Hello World", color: :white)}
LINE
)
subject.debug("Hello World")
Expand All @@ -38,7 +38,7 @@
it "#info" do
expect(logger).to receive(:info).with(
<<~LINE.strip
#{"[Langchain.rb]".yellow} #{"[Langchain::Vectorsearch::Pgvector]".blue}: #{"Hello World".white}
#{colorize("[Langchain.rb]", color: :yellow)} #{colorize("[Langchain::Vectorsearch::Pgvector]", color: :blue)}: #{colorize("Hello World", color: :white)}
LINE
)
subject.info("Hello World", for: Langchain::Vectorsearch::Pgvector)
Expand All @@ -47,7 +47,7 @@
it "#warn" do
expect(logger).to receive(:warn).with(
<<~LINE.strip
#{"[Langchain.rb]".yellow} #{"[Langchain::Vectorsearch::Pgvector]".blue}: #{"Hello World".colorize(color: :yellow, mode: :bold)}
#{colorize("[Langchain.rb]", color: :yellow)} #{colorize("[Langchain::Vectorsearch::Pgvector]", color: :blue)}: #{colorize("Hello World", color: :yellow, mode: :bold)}
LINE
)
subject.warn("Hello World", for: Langchain::Vectorsearch::Pgvector)
Expand All @@ -56,10 +56,14 @@
it "doesn't have an issue with objects that don't have .logger_options" do
expect(logger).to receive(:warn).with(
<<~LINE.strip
#{"[Langchain.rb]".yellow} [Object]: #{"Hello World".colorize(color: :yellow, mode: :bold)}
#{colorize("[Langchain.rb]", color: :yellow)} [Object]: #{colorize("Hello World", color: :yellow, mode: :bold)}
LINE
)
subject.warn("Hello World", for: Object)
end
end

def colorize(line, options)
Langchain::Utils::Colorizer.colorize(line, options)
end
end