mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 02:34:29 +00:00
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?).")
This commit is contained in:
parent
4dfbe0be07
commit
f1ae9f0acd
1 changed files with 22 additions and 9 deletions
|
@ -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()
|
Loading…
Add table
Add a link
Reference in a new issue