Module: SmartBrain::ModelProvider::Factory
- Defined in:
- lib/smart_brain/model_provider/factory.rb
Class Method Summary collapse
-
.build(config) ⇒ Object
按 config.llm_provider(stub|ollama|openai)构造 provider。.
Class Method Details
.build(config) ⇒ Object
按 config.llm_provider(stub|ollama|openai)构造 provider。
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 |
# File 'lib/smart_brain/model_provider/factory.rb', line 14 def build(config) cfg = config.respond_to?(:llm) ? config.llm : (config.fetch(:model_provider, {})) provider = (config.respond_to?(:llm_provider) ? config.llm_provider : cfg.fetch(:provider, 'stub')).to_s case provider when 'ollama' Ollama.new( model: cfg[:model] || 'qwen3', base_url: ENV.fetch('SMARTBRAIN_LLM_BASE_URL', cfg[:base_url] || 'http://localhost:11434'), rerank_model: cfg[:rerank_model], temperature: cfg[:temperature] || 0.2, timeout_seconds: cfg[:timeout_seconds] || 30, think: cfg.fetch(:think, false) ) when 'openai' OpenAI.new( model: cfg[:model] || 'qwen3', base_url: ENV.fetch('SMARTBRAIN_LLM_BASE_URL', cfg[:base_url] || 'http://localhost:11434'), api_key: ENV.fetch('SMARTBRAIN_LLM_API_KEY', cfg[:api_key] || ''), rerank_model: cfg[:rerank_model], temperature: cfg[:temperature] || 0.2, timeout_seconds: cfg[:timeout_seconds] || 30 ) else Stub.new end end |