Class: RCrewAI::LLMClient
- Inherits:
-
Object
- Object
- RCrewAI::LLMClient
- Defined in:
- lib/rcrewai/llm_client.rb
Class Method Summary collapse
- .chat(messages:, **options) ⇒ Object
- .complete(prompt:, **options) ⇒ Object
- .for_provider(provider = nil, config = RCrewAI.configuration) ⇒ Object
-
.resolve(spec, config = RCrewAI.configuration) ⇒ Object
Resolves a per-agent / per-pass LLM spec into a client.
Class Method Details
.chat(messages:, **options) ⇒ Object
54 55 56 57 |
# File 'lib/rcrewai/llm_client.rb', line 54 def self.chat(messages:, **) client = for_provider client.chat(messages: , **) end |
.complete(prompt:, **options) ⇒ Object
59 60 61 62 |
# File 'lib/rcrewai/llm_client.rb', line 59 def self.complete(prompt:, **) client = for_provider client.complete(prompt: prompt, **) end |
.for_provider(provider = nil, config = RCrewAI.configuration) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rcrewai/llm_client.rb', line 12 def self.for_provider(provider = nil, config = RCrewAI.configuration) provider ||= config.llm_provider case provider.to_sym when :openai LLMClients::OpenAI.new(config) when :anthropic LLMClients::Anthropic.new(config) when :google LLMClients::Google.new(config) when :azure LLMClients::Azure.new(config) when :ollama LLMClients::Ollama.new(config) else raise ConfigurationError, "Unsupported provider: #{provider}" end end |
.resolve(spec, config = RCrewAI.configuration) ⇒ Object
Resolves a per-agent / per-pass LLM spec into a client. nil -> global provider Symbol/String -> that provider, global model Hash -> { provider:, model:, api_key:, temperature: } overrides client object -> returned as-is (anything responding to #chat)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rcrewai/llm_client.rb', line 36 def self.resolve(spec, config = RCrewAI.configuration) case spec when nil for_provider(nil, config) when Symbol, String overridden = config.with_overrides(provider: spec) for_provider(overridden.llm_provider, overridden) when Hash overridden = config.with_overrides(**spec) for_provider(overridden.llm_provider, overridden) else return spec if spec.respond_to?(:chat) raise ConfigurationError, "Invalid llm: expected a provider symbol, an options hash, or a client responding to #chat, got #{spec.class}" end end |