From f1ae9f0acd19569d9c5a0c6cd01af93aec0a8a60 Mon Sep 17 00:00:00 2001 From: vietpham1911 Date: Wed, 22 May 2024 16:10:39 +0930 Subject: [PATCH] Added the requested features of Merlinvt ("1.If the model is not multimodal, there is no info needed for input_cost_per_image. Right now it's 0.0 for a lot of models. 2. Could you add the field max_output_tokens (is it max_completion_tokens in OpenRouter?).") --- ...to_update_price_and_context_window_file.py | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto_update_price_and_context_window_file.py b/.github/workflows/auto_update_price_and_context_window_file.py index 06b08bd30..3e0731b94 100644 --- a/.github/workflows/auto_update_price_and_context_window_file.py +++ b/.github/workflows/auto_update_price_and_context_window_file.py @@ -47,28 +47,41 @@ def write_to_file(file_path, data): def transform_remote_data(data): transformed = {} for row in data: - # Create a new dictionary with transformed data + # Add the fields 'max_tokens' and 'input_cost_per_token' obj = { "max_tokens": row["context_length"], "input_cost_per_token": float(row["pricing"]["prompt"]), - "output_cost_per_token": float(row["pricing"]["completion"]), - "litellm_provider": "openrouter", - "mode": "chat" } - # Add an field 'input_cost_per_image' - if "pricing" in row and "image" in row["pricing"]: + # Add 'max_output_tokens' as a field if it is not None + if "top_provider" in row and "max_completion_tokens" in row["top_provider"] and row["top_provider"]["max_completion_tokens"] is not None: + obj['max_output_tokens'] = int(row["top_provider"]["max_completion_tokens"]) + + # Add the field 'output_cost_per_token' + obj.update({ + "output_cost_per_token": float(row["pricing"]["completion"]), + }) + + # Add field 'input_cost_per_image' if it exists and is non-zero + if "pricing" in row and "image" in row["pricing"] and float(row["pricing"]["image"]) != 0.0: obj['input_cost_per_image'] = float(row["pricing"]["image"]) - # Add an additional field if the modality is 'multimodal' + # Add the fields 'litellm_provider' and 'mode' + obj.update({ + "litellm_provider": "openrouter", + "mode": "chat" + }) + + # Add the 'supports_vision' field if the modality is 'multimodal' if row.get('architecture', {}).get('modality') == 'multimodal': obj['supports_vision'] = True - + # Use a composite key to store the transformed object transformed[f'openrouter/{row["id"]}'] = obj return transformed + # Load local data from a specified file def load_local_data(file_path): try: @@ -105,4 +118,4 @@ def main(): # Entry point of the script if __name__ == "__main__": - main() + main() \ No newline at end of file