Persist input history across runs
Load and save readline history in .cache/history (last 1000 entries). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f1ac0c69f
commit
647b3e6a57
3 files changed
+17
No files matched your search
+16
@@ -2,6 +2,7 @@
|
||||
|
||||
print("Loading torch/transformers, please wait...", flush=True)
|
||||
|
||||
import atexit
|
||||
import os
|
||||
import readline
|
||||
|
||||
@@ -22,6 +23,7 @@ MODELS = {
|
||||
PARAM_KEYS = ["pooling", "max_length", "batch_size"]
|
||||
DEFAULT_MODEL = "BAAI/bge-small-zh-v1.5"
|
||||
LAST_MODEL_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".cache", "last_model")
|
||||
HISTORY_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".cache", "history")
|
||||
COMMANDS = ["/select", "/sim", "/tokens", "/params", "/set", "/reset", "/lsmod", "/help", "/quit", "/exit"]
|
||||
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
@@ -202,6 +204,20 @@ def setup_readline():
|
||||
readline.parse_and_bind("bind ^I rl_complete")
|
||||
else:
|
||||
readline.parse_and_bind("tab: complete")
|
||||
try:
|
||||
readline.read_history_file(HISTORY_FILE)
|
||||
except OSError:
|
||||
pass
|
||||
readline.set_history_length(1000)
|
||||
atexit.register(save_history)
|
||||
|
||||
|
||||
def save_history():
|
||||
try:
|
||||
os.makedirs(os.path.dirname(HISTORY_FILE), exist_ok=True)
|
||||
readline.write_history_file(HISTORY_FILE)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
HELP = """Commands:
|
||||
|
||||
Reference in new issue
Block a user