Skip to content

Commit 5b06439

Browse files
committed
feat: configuration inspect filters sensitive data
1 parent 635a215 commit 5b06439

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/ruby_llm/chat.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def initialize(model: nil, provider: nil, assume_model_exists: false, context: n
1818
raise ArgumentError, 'Provider must be specified if assume_model_exists is true'
1919
end
2020

21-
@config = context&.config || RubyLLM.config
22-
model_id = model || @config.default_model
21+
config = context&.config || RubyLLM.config
22+
model_id = model || config.default_model
2323
with_model(model_id, provider: provider, assume_exists: assume_model_exists)
24-
@connection = context ? context.connection_for(@provider) : @provider.connection(@config)
24+
@connection = context ? context.connection_for(@provider) : @provider.connection(config)
2525
@temperature = 0.7
2626
@messages = []
2727
@tools = {}

lib/ruby_llm/configuration.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,23 @@ def initialize
4646
@default_embedding_model = 'text-embedding-3-small'
4747
@default_image_model = 'dall-e-3'
4848
end
49+
50+
def inspect # rubocop:disable Metrics/MethodLength
51+
redacted = lambda do |name, value|
52+
if name.match?(/_key|_secret|_token$/)
53+
value.nil? ? 'nil' : '[FILTERED]'
54+
else
55+
value
56+
end
57+
end
58+
59+
inspection = instance_variables.map do |ivar|
60+
name = ivar.to_s.delete_prefix('@')
61+
value = redacted[name, instance_variable_get(ivar)]
62+
"#{name}: #{value}"
63+
end.join(', ')
64+
65+
"#<#{self.class}:0x#{object_id.to_s(16)} #{inspection}>"
66+
end
4967
end
5068
end

0 commit comments

Comments
 (0)