Sha256: d7c45be3842982253ad6f7770beea18408f665936624d837b39fa8579caaa524
Contents?: true
Size: 1.07 KB
Versions: 6
Compression:
Stored size: 1.07 KB
Contents
# lib/ai_client/llm.rb require 'active_hash' require 'yaml' class AiClient class LLM < ActiveHash::Base DATA_PATH = Pathname.new( __dir__ + '/models.yml') self.data = YAML.parse(DATA_PATH.read).to_ruby scope :providers, -> {all.map(&:provider).uniq.map(&:to_sym)} scope :models, ->(substring=nil) do (substring.nil? ? all : all.where(id: /#{substring}/i)) .map(&:model).sort.uniq end # Extracts the model name from the LLM ID. # # @return [String] the model name. # def model = id.split('/')[1] # Extracts the provider name from the LLM ID. # # @return [Symbol] the provider name. # def provider = id.split('/')[0].to_sym def to_h = attributes end class << self # Resets the LLM data by fetching models from the Orc client # and writing it to the models.yml file. # # @return [void] # def reset_llm_data orc_models = AiClient.orc_client.models AiClient::LLM.data = orc_models AiClient::LLM::DATA_PATH.write(orc_models.to_yaml) end end end
Version data entries
6 entries across 6 versions & 1 rubygems