Class: RCrewAI::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rcrewai/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rcrewai/configuration.rb', line 11

def initialize
  @llm_provider = :openai
  @model = 'gpt-4'
  @temperature = 0.1
  @max_tokens = 4000
  @timeout = 120

  # Default models for each provider
  @openai_model = 'gpt-4'
  @anthropic_model = 'claude-3-sonnet-20240229'
  @google_model = 'gemini-pro'
  @azure_model = 'gpt-4'

  @pricing = nil
  @ollama_native_tools = nil
  @log_level = :info

  # Load from environment variables
  load_from_env
end

Instance Attribute Details

#anthropic_api_keyObject

Returns the value of attribute anthropic_api_key.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def anthropic_api_key
  @anthropic_api_key
end

#anthropic_modelObject

Returns the value of attribute anthropic_model.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def anthropic_model
  @anthropic_model
end

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def api_version
  @api_version
end

#azure_api_keyObject

Returns the value of attribute azure_api_key.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def azure_api_key
  @azure_api_key
end

#azure_modelObject

Returns the value of attribute azure_model.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def azure_model
  @azure_model
end

#base_urlObject

Returns the value of attribute base_url.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def base_url
  @base_url
end

#deployment_nameObject

Returns the value of attribute deployment_name.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def deployment_name
  @deployment_name
end

#google_api_keyObject

Returns the value of attribute google_api_key.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def google_api_key
  @google_api_key
end

#google_modelObject

Returns the value of attribute google_model.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def google_model
  @google_model
end

#llm_providerObject

Returns the value of attribute llm_provider.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def llm_provider
  @llm_provider
end

#log_levelObject

Returns the value of attribute log_level.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def log_level
  @log_level
end

#max_tokensObject

Returns the value of attribute max_tokens.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def max_tokens
  @max_tokens
end

#modelObject

Returns the value of attribute model.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def model
  @model
end

#ollama_native_toolsObject

Returns the value of attribute ollama_native_tools.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def ollama_native_tools
  @ollama_native_tools
end

#openai_api_keyObject

Returns the value of attribute openai_api_key.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def openai_api_key
  @openai_api_key
end

#openai_modelObject

Returns the value of attribute openai_model.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def openai_model
  @openai_model
end

#pricingObject

Returns the value of attribute pricing.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def pricing
  @pricing
end

#temperatureObject

Returns the value of attribute temperature.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def temperature
  @temperature
end

#timeoutObject

Returns the value of attribute timeout.



5
6
7
# File 'lib/rcrewai/configuration.rb', line 5

def timeout
  @timeout
end

Instance Method Details

#provider_supported?(provider) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/rcrewai/configuration.rb', line 92

def provider_supported?(provider)
  supported_providers.include?(provider.to_sym)
end

#supported_providersObject



88
89
90
# File 'lib/rcrewai/configuration.rb', line 88

def supported_providers
  %i[openai anthropic google azure ollama]
end

#validate!Object

Raises:



82
83
84
85
86
# File 'lib/rcrewai/configuration.rb', line 82

def validate!
  raise ConfigurationError, 'LLM provider must be set' if @llm_provider.nil?
  raise ConfigurationError, "API key must be set for #{@llm_provider}" if api_key.nil? || api_key.empty?
  raise ConfigurationError, "Model must be set for #{@llm_provider}" if model.nil? || model.empty?
end

#with_overrides(provider: nil, model: nil, api_key: nil, temperature: nil) ⇒ Object

Returns a copy of this configuration with the given per-agent overrides applied. The original configuration is left untouched, so agents can each target a different provider/model without mutating global state.

config.with_overrides(provider: :anthropic, model: 'claude-3-opus-20240229')


67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rcrewai/configuration.rb', line 67

def with_overrides(provider: nil, model: nil, api_key: nil, temperature: nil)
  copy = dup
  copy.llm_provider = provider.to_sym if provider
  target = copy.llm_provider

  copy.public_send("#{target}_model=", model) if model && copy.respond_to?("#{target}_model=")
  copy.model = model if model

  copy.public_send("#{target}_api_key=", api_key) if api_key && copy.respond_to?("#{target}_api_key=")
  copy.api_key = api_key if api_key

  copy.temperature = temperature unless temperature.nil?
  copy
end