File size: 837 Bytes
6bf4f4e
 
 
 
 
 
7592671
6bf4f4e
 
 
 
 
 
7592671
 
6bf4f4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/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))