| | import os |
| |
|
| |
|
| | def init(cfg): |
| | print(cfg['setting_cache_path'].value) |
| | if os.path.exists(cfg['setting_cache_path'].value): |
| | |
| | tmp = cfg['model'].load_session(cfg['setting_cache_path'].value) |
| | print(f"load cache from {cfg['setting_cache_path'].value} {tmp}") |
| | tmp = cfg['chat_template']('system', |
| | cfg['text_format'](cfg['role_char_d'].value, |
| | char=cfg['role_char'].value, |
| | user=cfg['role_usr'].value)) |
| | cfg['setting_n_keep'].value = len(tmp) |
| | tmp = cfg['chat_template'](cfg['role_char'].value, |
| | cfg['text_format'](cfg['role_chat_style'].value, |
| | char=cfg['role_char'].value, |
| | user=cfg['role_usr'].value)) |
| | cfg['setting_n_keep'].value += len(tmp) |
| | |
| | cfg['chatbot'] = [] |
| | for one in cfg["role_char_first"]: |
| | one['name'] = cfg['text_format'](one['name'], |
| | char=cfg['role_char'].value, |
| | user=cfg['role_usr'].value) |
| | one['value'] = cfg['text_format'](one['value'], |
| | char=cfg['role_char'].value, |
| | user=cfg['role_usr'].value) |
| | if one['name'] == cfg['role_char'].value: |
| | cfg['chatbot'].append((None, cfg['chat_display_format'](one['value']))) |
| | print(one) |
| | else: |
| | |
| | tmp = cfg['chat_template']('system', |
| | cfg['text_format'](cfg['role_char_d'].value, |
| | char=cfg['role_char'].value, |
| | user=cfg['role_usr'].value)) |
| | cfg['setting_n_keep'].value = cfg['model'].eval_t(tmp) |
| |
|
| | |
| | tmp = cfg['chat_template'](cfg['role_char'].value, |
| | cfg['text_format'](cfg['role_chat_style'].value, |
| | char=cfg['role_char'].value, |
| | user=cfg['role_usr'].value)) |
| | cfg['setting_n_keep'].value = cfg['model'].eval_t(tmp) |
| |
|
| | |
| | cfg['chatbot'] = [] |
| | for one in cfg["role_char_first"]: |
| | one['name'] = cfg['text_format'](one['name'], |
| | char=cfg['role_char'].value, |
| | user=cfg['role_usr'].value) |
| | one['value'] = cfg['text_format'](one['value'], |
| | char=cfg['role_char'].value, |
| | user=cfg['role_usr'].value) |
| | if one['name'] == cfg['role_char'].value: |
| | cfg['chatbot'].append((None, cfg['chat_display_format'](one['value']))) |
| | print(one) |
| | tmp = cfg['chat_template'](one['name'], one['value']) |
| | cfg['model'].eval_t(tmp) |
| |
|
| | |
| | with open(cfg['setting_cache_path'].value, 'wb') as f: |
| | pass |
| | tmp = cfg['model'].save_session(cfg['setting_cache_path'].value) |
| | print(f'save cache {tmp}') |
| | |
| | if os.environ.get("HF_TOKEN"): |
| | from huggingface_hub import login, CommitScheduler |
| | login(token=os.environ.get("HF_TOKEN"), write_permission=True) |
| | CommitScheduler(repo_id='Limour/llama-python-streamingllm-cache', repo_type='dataset', folder_path='cache') |
| |
|