mirror of https://github.com/aliasrobotics/cai.git
Pricing via JSON
This commit is contained in:
parent
1de6eb540d
commit
e740d6499d
|
|
@ -1,6 +1,6 @@
|
|||
# macOS Files
|
||||
.DS_Store
|
||||
|
||||
cai_env/
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
**/__pycache__/
|
||||
|
|
@ -152,4 +152,4 @@ cython_debug/
|
|||
workspaces/
|
||||
|
||||
# benchmarks
|
||||
benchmarks/outputs
|
||||
benchmarks/outputs
|
||||
|
|
|
|||
|
|
@ -341,23 +341,24 @@ class CostTracker:
|
|||
if model_name in self.model_pricing_cache:
|
||||
return self.model_pricing_cache[model_name]
|
||||
|
||||
# Try to load pricing from local pricing.json first
|
||||
# Try to load pricing from remote pricing.json first
|
||||
try:
|
||||
pricing_path = pathlib.Path("pricing.json")
|
||||
if pricing_path.exists():
|
||||
with open(pricing_path, "r", encoding="utf-8") as f:
|
||||
local_pricing = json.load(f)
|
||||
pricing_info = local_pricing.get("alias0", {})
|
||||
input_cost = pricing_info.get("input_cost_per_token", 0)
|
||||
output_cost = pricing_info.get("output_cost_per_token", 0)
|
||||
|
||||
# Cache and return local pricing
|
||||
self.model_pricing_cache[model_name] = (input_cost, output_cost)
|
||||
return input_cost, output_cost
|
||||
import requests
|
||||
pricing_url = "https://raw.githubusercontent.com/aliasrobotics/cai/refs/heads/mcp_stdio/pricing.json"
|
||||
response = requests.get(pricing_url, timeout=5)
|
||||
if response.status_code == 200:
|
||||
remote_pricing = response.json()
|
||||
pricing_info = remote_pricing.get("alias0", {})
|
||||
input_cost = pricing_info.get("input_cost_per_token", 0)
|
||||
output_cost = pricing_info.get("output_cost_per_token", 0)
|
||||
|
||||
# Cache and return remote pricing
|
||||
self.model_pricing_cache[model_name] = (input_cost, output_cost)
|
||||
return input_cost, output_cost
|
||||
except Exception as e:
|
||||
print(f" WARNING: Error loading local pricing.json: {str(e)}")
|
||||
|
||||
# Fallback to LiteLLM API if local pricing not found
|
||||
print(f" WARNING: Error loading remote pricing.json: {str(e)}")
|
||||
|
||||
# Fallback to LiteLLM API if both remote and local pricing not found
|
||||
LITELLM_URL = (
|
||||
"https://raw.githubusercontent.com/BerriAI/litellm/main/"
|
||||
"model_prices_and_context_window.json"
|
||||
|
|
|
|||
Loading…
Reference in New Issue