Class: RubyLLM::Generators::Provider::Scaffold
- Inherits:
-
Object
- Object
- RubyLLM::Generators::Provider::Scaffold
- Defined in:
- lib/generators/ruby_llm/provider/scaffold.rb
Overview
Generates first-party providers and standalone provider gems.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- SUPPORTED_MODES =
:nodoc: all
%w[core gem].freeze
- SUPPORTED_DIALECTS =
%w[chat_completions responses anthropic gemini converse ollama].freeze
- TEMPLATE_ROOT =
File.('templates', __dir__)
Instance Attribute Summary collapse
-
#api_base ⇒ Object
readonly
Returns the value of attribute api_base.
-
#api_base_env ⇒ Object
readonly
Returns the value of attribute api_base_env.
-
#api_key_env ⇒ Object
readonly
Returns the value of attribute api_key_env.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#dialect ⇒ Object
readonly
Returns the value of attribute dialect.
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#github_owner ⇒ Object
readonly
Returns the value of attribute github_owner.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#models_dev_provider ⇒ Object
readonly
Returns the value of attribute models_dev_provider.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #api_base_config ⇒ Object
- #api_key_config ⇒ Object
- #class_name ⇒ Object
- #dynamic_models? ⇒ Boolean
- #env_prefix ⇒ Object
- #generate ⇒ Object
-
#initialize(name, **options) ⇒ Scaffold
constructor
A new instance of Scaffold.
- #protocol_class_name ⇒ Object
- #protocol_name ⇒ Object
- #protocol_superclass ⇒ Object
- #provider_description ⇒ Object
- #require_path ⇒ Object
- #slug ⇒ Object
Constructor Details
#initialize(name, **options) ⇒ Scaffold
Returns a new instance of Scaffold.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 26 def initialize(name, **) @name = normalize_provider_name(name) @mode = normalize_option(.fetch(:mode, :core), SUPPORTED_MODES, 'mode') @dialect = normalize_option(.fetch(:dialect, :chat_completions), SUPPORTED_DIALECTS, 'dialect') @api_base = [:api_base] || 'https://api.example.com/v1' @api_key_env = [:api_key_env] || "#{env_prefix}_API_KEY" @api_base_env = [:api_base_env] || "#{env_prefix}_API_BASE" @models_dev_provider = blank_to_nil([:models_dev_provider]) @dynamic_models = dynamic_models_option?() @gem_name = normalize_gem_name([:gem_name] || "ruby_llm-providers-#{slug.tr('_', '-')}") @destination = File.([:destination] || default_destination) @github_owner = [:github_owner] || 'your-github-org' @force = .fetch(:force, false) @result = Result.new(written: [], updated: [], skipped: [], actions: []) end |
Instance Attribute Details
#api_base ⇒ Object (readonly)
Returns the value of attribute api_base.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def api_base @api_base end |
#api_base_env ⇒ Object (readonly)
Returns the value of attribute api_base_env.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def api_base_env @api_base_env end |
#api_key_env ⇒ Object (readonly)
Returns the value of attribute api_key_env.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def api_key_env @api_key_env end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def destination @destination end |
#dialect ⇒ Object (readonly)
Returns the value of attribute dialect.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def dialect @dialect end |
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def gem_name @gem_name end |
#github_owner ⇒ Object (readonly)
Returns the value of attribute github_owner.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def github_owner @github_owner end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def mode @mode end |
#models_dev_provider ⇒ Object (readonly)
Returns the value of attribute models_dev_provider.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def models_dev_provider @models_dev_provider end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 23 def name @name end |
Instance Method Details
#api_base_config ⇒ Object
63 64 65 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 63 def api_base_config "#{slug}_api_base" end |
#api_key_config ⇒ Object
59 60 61 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 59 def api_key_config "#{slug}_api_key" end |
#class_name ⇒ Object
47 48 49 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 47 def class_name @class_name ||= classify(name) end |
#dynamic_models? ⇒ Boolean
67 68 69 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 67 def dynamic_models? !!@dynamic_models end |
#env_prefix ⇒ Object
55 56 57 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 55 def env_prefix slug.upcase end |
#generate ⇒ Object
42 43 44 45 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 42 def generate mode == 'core' ? generate_core_provider : generate_provider_gem @result end |
#protocol_class_name ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 75 def protocol_class_name { 'chat_completions' => 'ChatCompletions', 'responses' => 'Responses', 'anthropic' => 'Anthropic', 'gemini' => 'Gemini', 'converse' => 'Converse', 'ollama' => 'ChatCompletions' }.fetch(dialect) end |
#protocol_name ⇒ Object
71 72 73 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 71 def protocol_name dialect == 'ollama' ? 'chat_completions' : dialect end |
#protocol_superclass ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 86 def protocol_superclass { 'chat_completions' => 'Protocols::ChatCompletions', 'responses' => 'Protocols::Responses', 'anthropic' => 'Protocols::Anthropic', 'gemini' => 'Protocols::Gemini', 'converse' => 'Protocols::Converse', 'ollama' => 'Ollama::ChatCompletions' }.fetch(dialect) end |
#provider_description ⇒ Object
97 98 99 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 97 def provider_description "#{class_name} API integration." end |
#require_path ⇒ Object
101 102 103 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 101 def require_path "ruby_llm/providers/#{slug}" end |
#slug ⇒ Object
51 52 53 |
# File 'lib/generators/ruby_llm/provider/scaffold.rb', line 51 def slug @slug ||= RubyLLM::Support::Utils.underscore(class_name).tr('-', '_') end |