mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix: defensive parsing
This commit is contained in:
parent
709e53c02d
commit
6bd0219c75
1 changed files with 19 additions and 12 deletions
|
|
@ -85,24 +85,31 @@ def transform_openrouter_data(data):
|
|||
def transform_vercel_ai_gateway_data(data):
|
||||
transformed = {}
|
||||
for row in data:
|
||||
obj = {
|
||||
"max_tokens": row["context_window"],
|
||||
"input_cost_per_token": float(row["pricing"]["input"]),
|
||||
"output_cost_per_token": float(row["pricing"]["output"]),
|
||||
'max_output_tokens': row['max_tokens'],
|
||||
'max_input_tokens': row["context_window"],
|
||||
}
|
||||
obj = {}
|
||||
|
||||
if "context_window" in row:
|
||||
obj['max_tokens'] = row["context_window"]
|
||||
obj['max_input_tokens'] = row["context_window"]
|
||||
|
||||
if "pricing" in row:
|
||||
if "input" in row["pricing"] and row["pricing"]["input"] is not None:
|
||||
obj['input_cost_per_token'] = float(row["pricing"]["input"])
|
||||
if "output" in row["pricing"] and row["pricing"]["output"] is not None:
|
||||
obj['output_cost_per_token'] = float(row["pricing"]["output"])
|
||||
|
||||
if "max_tokens" in row:
|
||||
obj['max_output_tokens'] = row['max_tokens']
|
||||
|
||||
# Handle cache pricing if available
|
||||
if "pricing" in row:
|
||||
if "input_cache_read" in row["pricing"] and row["pricing"]["input_cache_read"] is not None:
|
||||
obj['cache_read_input_token_cost'] = float(f"{float(row['pricing']['input_cache_read']):e}")
|
||||
|
||||
|
||||
if "input_cache_write" in row["pricing"] and row["pricing"]["input_cache_write"] is not None:
|
||||
obj['cache_creation_input_token_cost'] = float(f"{float(row['pricing']['input_cache_write']):e}")
|
||||
|
||||
mode = "embedding" if "embedding" in row["id"].lower() else "chat"
|
||||
|
||||
|
||||
obj.update({"litellm_provider": "vercel_ai_gateway", "mode": mode})
|
||||
|
||||
transformed[f'vercel_ai_gateway/{row["id"]}'] = obj
|
||||
|
|
@ -133,17 +140,17 @@ def main():
|
|||
|
||||
# Load local data from file
|
||||
local_data = load_local_data(local_file_path)
|
||||
|
||||
|
||||
# Fetch OpenRouter data
|
||||
openrouter_data = asyncio.run(fetch_data(openrouter_url))
|
||||
# Transform the fetched OpenRouter data
|
||||
openrouter_data = transform_openrouter_data(openrouter_data)
|
||||
|
||||
|
||||
# Fetch Vercel AI Gateway data
|
||||
vercel_data = asyncio.run(fetch_data(vercel_ai_gateway_url))
|
||||
# Transform the fetched Vercel AI Gateway data
|
||||
vercel_data = transform_vercel_ai_gateway_data(vercel_data)
|
||||
|
||||
|
||||
# Combine both datasets
|
||||
all_remote_data = {**openrouter_data, **vercel_data}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue