traveler514's picture
first commit
81a794d
# DEBUG ONLY
import time
import random
from tqdm import tqdm
from backend.section_infer_helper.base_helper import BaseHelper
from backend.utils.data_process import split_to_file_diff, split_to_section
class RandomHelper(BaseHelper):
PREDEF_MODEL = ["Random"]
MODELS_SUPPORTED_LANGUAGES = {
"Random": ["C", "C++", "Java", "Python"]
}
def load_model(self, model_name):
pass
def infer(self, diff_code):
file_diff_list = split_to_file_diff(diff_code, BaseHelper._get_lang_ext(self.MODELS_SUPPORTED_LANGUAGES["Random"]))
results = {}
for file_a, _, file_diff in tqdm(file_diff_list, desc="Inferencing", unit="file", total=len(file_diff_list)):
time.sleep(0.1)
sections = split_to_section(file_diff)
file = file_a.removeprefix("a/")
results[file] = []
for section in sections:
results[file].append({
"section": section,
"predict": random.choice([0, 1]),
"conf": random.random()
})
return results
random_helper = RandomHelper()