forestcalled/text-generation-webui
0
1from pathlib import Path2 3from modules.text_generation import get_encoded_length4 5 6def load_prompt(fname):7 if fname in ['None', '']:8 return ''9 else:10 file_path = Path(f'prompts/{fname}.txt')11 if not file_path.exists():12 return ''13 14 with open(file_path, 'r', encoding='utf-8') as f:15 text = f.read()16 if text[-1] == '\n':17 text = text[:-1]18 19 return text20 21 22def count_tokens(text):23 try:24 tokens = get_encoded_length(text)25 return str(tokens)26 except:27 return '0'28 