Module: LlmCostTracker::PriceSync

Defined in:
lib/llm_cost_tracker/price_sync.rb,
lib/llm_cost_tracker/price_sync/merger.rb,
lib/llm_cost_tracker/price_sync/source.rb,
lib/llm_cost_tracker/price_sync/fetcher.rb,
lib/llm_cost_tracker/price_sync/raw_price.rb,
lib/llm_cost_tracker/price_sync/validator.rb,
lib/llm_cost_tracker/price_sync/model_catalog.rb,
lib/llm_cost_tracker/price_sync/source_result.rb,
lib/llm_cost_tracker/price_sync/sources/litellm.rb,
lib/llm_cost_tracker/price_sync/sources/open_router.rb

Overview

rubocop:disable Metrics/ModuleLength, Metrics/ClassLength

Defined Under Namespace

Modules: Sources Classes: CheckResult, Fetcher, Merger, ModelCatalog, RawPrice, RefreshPlan, Source, SourceResult, SourceUsage, SyncResult, Validator

Constant Summary collapse

DEFAULT_OUTPUT_PATH =
PriceRegistry::DEFAULT_PRICES_PATH
YAML_EXTENSIONS =
%w[.yml .yaml].freeze

Class Method Summary collapse

Class Method Details

.check(path: DEFAULT_OUTPUT_PATH, seed_path: DEFAULT_OUTPUT_PATH, fetcher: Fetcher.new, today: Date.today) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/llm_cost_tracker/price_sync.rb', line 94

def check(path: DEFAULT_OUTPUT_PATH, seed_path: DEFAULT_OUTPUT_PATH, fetcher: Fetcher.new, today: Date.today)
  plan = build_refresh_plan(path: path, seed_path: seed_path, fetcher: fetcher, today: today)

  CheckResult.new(
    path: plan.path,
    changes: plan.changes,
    orphaned_models: plan.orphaned_models,
    failed_sources: plan.failed_sources,
    discrepancies: plan.discrepancies,
    rejected: plan.rejected,
    flagged: plan.flagged,
    sources_used: plan.sources_used,
    up_to_date: plan.up_to_date?
  )
end

.sync(path: DEFAULT_OUTPUT_PATH, seed_path: DEFAULT_OUTPUT_PATH, preview: false, strict: false, fetcher: Fetcher.new, today: Date.today) ⇒ Object

Raises:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/llm_cost_tracker/price_sync.rb', line 72

def sync(path: DEFAULT_OUTPUT_PATH, seed_path: DEFAULT_OUTPUT_PATH, preview: false, strict: false,
         fetcher: Fetcher.new, today: Date.today)
  plan = build_refresh_plan(path: path, seed_path: seed_path, fetcher: fetcher, today: today)
  raise Error, strict_failure_message(plan) if strict_sync_failure?(plan, strict: strict)

  written = !preview && plan.refresh_succeeded?
  write_registry(plan.path, plan.updated_registry) if written

  SyncResult.new(
    path: plan.path,
    updated_models: plan.changes.keys.sort,
    changes: plan.changes,
    orphaned_models: plan.orphaned_models,
    failed_sources: plan.failed_sources,
    discrepancies: plan.discrepancies,
    rejected: plan.rejected,
    flagged: plan.flagged,
    sources_used: plan.sources_used,
    written: written
  )
end