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