Class: Raif::ModelManifest::Dsl::ProviderBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/raif/model_manifest/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(name:, source_path:) ⇒ ProviderBuilder

Returns a new instance of ProviderBuilder.



165
166
167
168
169
170
# File 'lib/raif/model_manifest/dsl.rb', line 165

def initialize(name:, source_path:)
  @name = name.to_sym
  @source_path = source_path
  @references = {}
  @models = []
end

Instance Method Details

#finish ⇒ Object



204
205
206
207
208
209
210
211
# File 'lib/raif/model_manifest/dsl.rb', line 204

def finish
  ProviderDeclaration.new(
    name: @name,
    references: Dsl.deep_freeze(@references),
    models: @models.freeze,
    source_path: @source_path
  ).freeze
end

#model(api_name:, display_name:, pricing:, lifecycle:, key: nil, key_base: nil, max_completion_tokens: nil, capabilities: nil, endpoints: nil, adapter: nil) ⇒ Object

A model declares either key: with capabilities: (one entry), or key_base: with endpoints: (one entry per endpoint, which is how OpenAI models reach both the completions and responses adapters).



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/raif/model_manifest/dsl.rb', line 179

def model(
  api_name:, display_name:, pricing:, lifecycle:,
  key: nil, key_base: nil, max_completion_tokens: nil, capabilities: nil, endpoints: nil, adapter: nil
)
  single_entry = !key.nil? && !capabilities.nil? && key_base.nil? && endpoints.nil?
  per_endpoint = !key_base.nil? && !endpoints.nil? && key.nil? && capabilities.nil?
  unless single_entry || per_endpoint
    raise ArgumentError, "#{@source_path}: #{display_name} must declare key: with capabilities:, or key_base: with endpoints:"
  end

  @models << ModelDeclaration.new(
    adapter: adapter&.to_sym,
    key: key&.to_sym,
    key_base: (key_base || key).to_s,
    api_name: api_name,
    display_name: display_name,
    max_completion_tokens: max_completion_tokens,
    pricing: Dsl.normalize_pricing(pricing),
    capabilities: capabilities && Dsl.normalize_capabilities(capabilities),
    endpoints: endpoints && Dsl.normalize_endpoints(endpoints, source_path: @source_path),
    lifecycle: Dsl.normalize_lifecycle(lifecycle),
    source_path: @source_path
  ).freeze
end

#references(**urls) ⇒ Object



172
173
174
# File 'lib/raif/model_manifest/dsl.rb', line 172

def references(**urls)
  @references = urls
end