2
2
Module for the CLI to experiment with chatting using a pre-configured chatbot.
3
3
"""
4
4
import argparse
5
+
6
+ from pyperclip import init_windows_clipboard
7
+
5
8
from llms_wrapper .config import read_config_file as read_config
6
9
from fasthtml .common import *
7
10
from loguru import logger
@@ -19,6 +22,7 @@ def get_args():
19
22
parser .add_argument ('--config' , '-c' , type = str , help = 'Configuration file, should contain LLM and prompt config' , required = True )
20
23
parser .add_argument ("--llm" , '-l' , type = str , help = "Alias of LLM to use for chatbot (or use first found in config)" , required = False )
21
24
parser .add_argument ("--promptfile" , type = str , help = "Prompt file containing prompts, overrides config (or use prompt section in config)" , required = False )
25
+ parser .add_argument ("--pids" , nargs = "*" , help = "Prompt ids (pids) to use as initial messages for the chatbot" )
22
26
parser .add_argument ("--max_messages" , type = int , default = 20 ,
23
27
help = "Max number of messages to keep in the chat history (default: 20)" , required = False )
24
28
parser .add_argument ("--clear_page" , action = "store_true" ,
@@ -27,6 +31,7 @@ def get_args():
27
31
help = 'Be more verbose' , required = False )
28
32
parser .add_argument ("--debug" , action = "store_true" , help = "Debug mode, overrides loglevel" , required = False )
29
33
args = parser .parse_args ()
34
+ configure_logging (level = "DEBUG" if args .debug else "INFO" )
30
35
config = {}
31
36
config .update (vars (args ))
32
37
# debug implies verbose
@@ -43,7 +48,7 @@ def get_args():
43
48
44
49
# if a promptfile is specified, load the prompts from the file and update the config
45
50
if args .promptfile is not None :
46
- prompts = load_prompts (args .promptfile , as_messages = True )
51
+ prompts = load_prompts (args .promptfile , as_messages = True ) # the prompt gets returned as messages!
47
52
if "prompts" not in config :
48
53
config ["prompts" ] = {}
49
54
elif not isinstance (config ["prompts" ], dict ):
@@ -52,6 +57,15 @@ def get_args():
52
57
if pid in config ["prompts" ]:
53
58
logger .warning (f"Prompt { pid } already exists in config file, overriding from the prompt file!" )
54
59
config ["prompts" ][pid ] = prompt
60
+ if args .pids : # if pids are specified, collect them for later
61
+ init_messages = []
62
+ for pid in args .pids :
63
+ if pid in config ["prompts" ]:
64
+ init_messages += config ["prompts" ][pid ]
65
+ else :
66
+ raise ValueError (f"PID { pid } not found in promptfile" )
67
+ logger .info (f"Loaded initial messages: { init_messages } " )
68
+ config ["init_messages" ] = init_messages
55
69
56
70
# set the config parameter use_llm to the llm to use
57
71
if not "llms" in config or not isinstance (config ["llms" ], list ) or len (config ["llms" ]) == 0 :
@@ -68,7 +82,6 @@ def get_args():
68
82
return config
69
83
70
84
config = get_args ()
71
- configure_logging (level = "DEBUG" if config ["debug" ] else "INFO" )
72
85
llms = LLMS (config )
73
86
llm_aliases = [l ["alias" ] for l in config ["llms" ]]
74
87
llm_used = config ["use_llm" ]
@@ -78,7 +91,7 @@ def get_args():
78
91
chatbot = SimpleSerialChatbot (
79
92
llm ,
80
93
config = config ,
81
- initial_message = None , # TODO: add prompt id for system prompt to args and specify here
94
+ initial_message = config . get ( "init_messages" ),
82
95
message_template = None ,
83
96
max_messages = config ["max_messages" ], # Max number of messages to keep in the chat history)
84
97
)
0 commit comments