class LittleGhost::Providers::LMStudio::CatalogSource
Refreshes downloaded model metadata from LM Studio’s native read-only model listing endpoint.
Public Class Methods
# File lib/little_ghost/providers/lm_studio/catalog_source.rb, line 17 def initialize(provider:, credential_resolver:, clock: -> { Time.now.utc }, http_client: nil) super(name: "lm_studio") @provider = provider.to_s @credential_resolver = credential_resolver @clock = clock @known_targets = [] @known_targets_mutex = Mutex.new @http_client = http_client || Support::HTTPClient.new( open_timeout: 5, read_timeout: 30, max_response_bytes: MAX_CATALOG_BYTES ) end
Creates a source for one named LM Studio connection. Credentials are resolved only when the application explicitly refreshes its catalog.
Calls superclass method
LittleGhost::Models::Catalog::Source::new
Public Instance Methods
Source
# File lib/little_ghost/providers/lm_studio/catalog_source.rb, line 31 def refresh(target: nil) return {} if target && target.provider != @provider configuration = @credential_resolver.call raise TypeError, "credentials must be a mapping" unless configuration.is_a?(Hash) configuration = configuration.to_h.transform_keys(&:to_s) models = JSON.parse(request(configuration)).fetch("models") raise TypeError, "models must be an array" unless models.is_a?(Array) observed_at = @clock.call.iso8601 return refresh_target(models, target:, observed_at:) if target records = models.to_h do |model| attributes = normalize(model).merge(observed_at:) ["#{@provider}:#{model.fetch("key")}", attributes] end reconcile(records, observed_at:) rescue JSON::ParserError, KeyError, TypeError, ArgumentError raise ProviderError, "LM Studio returned an invalid model catalog" end