(fetch_json: F)
| 1191 | } |
| 1192 | |
| 1193 | fn load_models_dev_pricing<F>(fetch_json: F) -> Option<PricingMap> |
| 1194 | where |
| 1195 | F: FnOnce() -> std::io::Result<String>, |
| 1196 | { |
| 1197 | let json = match fetch_json() { |
| 1198 | Ok(json) => json, |
| 1199 | Err(error) => { |
| 1200 | if should_log_pricing_refresh_details() { |
| 1201 | eprintln!( |
| 1202 | "WARN Failed to fetch models.dev pricing ({error}); using LiteLLM pricing." |
| 1203 | ); |
| 1204 | } |
| 1205 | return None; |
| 1206 | } |
| 1207 | }; |
| 1208 | let mut map = PricingMap::default(); |
| 1209 | if map.load_models_dev_json_missing(&json).is_none() { |
| 1210 | if should_log_pricing_refresh_details() { |
| 1211 | eprintln!("WARN Failed to parse models.dev pricing; using LiteLLM pricing."); |
| 1212 | } |
| 1213 | return None; |
| 1214 | } |
| 1215 | Some(map) |
| 1216 | } |
| 1217 | |
| 1218 | fn fetch_pricing_json() -> std::io::Result<String> { |
| 1219 | fetch_json_url(LITELLM_PRICING_URL) |
no test coverage detected