forked from crmne/ruby_llm
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfiguration.rb
More file actions
75 lines (68 loc) · 2.27 KB
/
configuration.rb
File metadata and controls
75 lines (68 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true
module RubyLLM
# Global configuration for RubyLLM. Manages API keys, default models,
# and provider-specific settings.
#
# Configure via:
# RubyLLM.configure do |config|
# config.openai_api_key = ENV['OPENAI_API_KEY']
# config.anthropic_api_key = ENV['ANTHROPIC_API_KEY']
# end
class Configuration
# Provider-specific configuration
attr_accessor :openai_api_key,
:openai_api_base,
:anthropic_api_key,
:gemini_api_key,
:deepseek_api_key,
:bedrock_api_key,
:bedrock_secret_key,
:bedrock_region,
:bedrock_session_token,
:openrouter_api_key,
:ollama_api_base,
# Default models
:default_model,
:default_embedding_model,
:default_image_model,
# Connection configuration
:request_timeout,
:max_retries,
:retry_interval,
:retry_backoff_factor,
:retry_interval_randomness,
# Logging configuration
:log_file,
:log_level
def initialize
# Connection configuration
@request_timeout = 120
@max_retries = 3
@retry_interval = 0.1
@retry_backoff_factor = 2
@retry_interval_randomness = 0.5
# Default models
@default_model = 'gpt-4.1-nano'
@default_embedding_model = 'text-embedding-3-small'
@default_image_model = 'dall-e-3'
# Logging configuration
@log_file = $stdout
@log_level = ENV['RUBYLLM_DEBUG'] ? Logger::DEBUG : Logger::INFO
end
def inspect # rubocop:disable Metrics/MethodLength
redacted = lambda do |name, value|
if name.match?(/_key|_secret|_token$/)
value.nil? ? 'nil' : '[FILTERED]'
else
value
end
end
inspection = instance_variables.map do |ivar|
name = ivar.to_s.delete_prefix('@')
value = redacted[name, instance_variable_get(ivar)]
"#{name}: #{value}"
end.join(', ')
"#<#{self.class}:0x#{object_id.to_s(16)} #{inspection}>"
end
end
end