#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import hashlib | |
def get_org_and_model_names_from_filepath(file_path: str) -> str: | |
org, model = file_path.split("/")[-3:-1] | |
model = model.removesuffix(".json") | |
model = model.split('_request_')[0] | |
return org, model | |
def get_model_name_from_filepath(file_path: str) -> str: | |
org, model = get_org_and_model_names_from_filepath(file_path) | |
return f"{org}/{model}" | |
def get_hash(key: str) -> str: | |
sha256_hash = hashlib.sha256() | |
sha256_hash.update(key.encode('utf-8')) | |
return sha256_hash.hexdigest()[:16] | |
def get_request_id(model: str, revision: str, precision: str) -> str: | |
return f"{model}_{revision}_{precision}" | |
def get_request_hash(model: str, revision: str, precision: str) -> str: | |
return get_hash(get_request_id(model, revision, precision)) | |