Adiciona o toggle openai_api | openai_codex_oauth. Por padrão mantém comportamento legado (API key OpenAI tradicional). Quando mudamos pra openai_codex_oauth, os clientes (RubyLLM + Agents gem) passam a apontar para o proxy interno em http://localhost:3000/codex, configurável via CAPTAIN_CODEX_PROXY_URL. - Captain::Llm::ProviderConfig: single source of truth de api_key, api_base e model, baseado em CAPTAIN_LLM_PROVIDER - config/initializers/ai_agents.rb refatorado - lib/llm/config.rb refatorado - 8 specs do ProviderConfig passando - Fallback seguro: api_key dummy ('codex-oauth') quando usando proxy (o proxy ignora Authorization e usa OAuth interno) NÃO mexe no Llm::LegacyBaseOpenAiService (PDF/Files API). Esse continua sempre na API tradicional porque o endpoint Codex não expõe Files API. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
921 B
Ruby
44 lines
921 B
Ruby
require 'ruby_llm'
|
|
|
|
module Llm::Config
|
|
DEFAULT_MODEL = Captain::Llm::ProviderConfig::DEFAULT_MODEL
|
|
|
|
class << self
|
|
def initialized?
|
|
@initialized ||= false
|
|
end
|
|
|
|
def initialize!
|
|
return if @initialized
|
|
|
|
configure_ruby_llm
|
|
@initialized = true
|
|
end
|
|
|
|
def reset!
|
|
@initialized = false
|
|
end
|
|
|
|
def with_api_key(api_key, api_base: nil)
|
|
context = RubyLLM.context do |config|
|
|
config.openai_api_key = api_key
|
|
config.openai_api_base = api_base
|
|
end
|
|
|
|
yield context
|
|
end
|
|
|
|
private
|
|
|
|
def configure_ruby_llm
|
|
settings = Captain::Llm::ProviderConfig.settings
|
|
|
|
RubyLLM.configure do |config|
|
|
config.openai_api_key = settings[:api_key] if settings[:api_key].present?
|
|
config.openai_api_base = "#{settings[:api_base]}/v1" if settings[:api_base].present?
|
|
config.logger = Rails.logger
|
|
end
|
|
end
|
|
end
|
|
end
|