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/registry_loader.rb,
lib/llm_cost_tracker/price_sync/registry_writer.rb,
lib/llm_cost_tracker/price_sync/sources/litellm.rb,
lib/llm_cost_tracker/price_sync/sources/open_router.rb,
lib/llm_cost_tracker/price_sync/refresh_plan_builder.rb

Defined Under Namespace

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

Constant Summary collapse

DEFAULT_OUTPUT_PATH =
PriceRegistry::DEFAULT_PRICES_PATH

Class Method Summary collapse

Class Method Details

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



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/llm_cost_tracker/price_sync.rb', line 97

def check(path: DEFAULT_OUTPUT_PATH, seed_path: DEFAULT_OUTPUT_PATH, fetcher: Fetcher.new, today: Date.today)
  plan = RefreshPlanBuilder.new(sources: sources).call(
    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:



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

def sync(path: DEFAULT_OUTPUT_PATH, seed_path: DEFAULT_OUTPUT_PATH, preview: false, strict: false,
         fetcher: Fetcher.new, today: Date.today)
  plan = RefreshPlanBuilder.new(sources: sources).call(
    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?
  RegistryWriter.new.call(path: plan.path, registry: 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