diff --git a/README.md b/README.md index b1d3812..5c1377d 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ This won't perform any action over the wire, and just calculates the tokens loca The system message is used to instruct the model how to behave, see [OpenAI - Instructing Chat Models](https://platform.openai.com/docs/guides/chat/instructing-chat-models). -These can be loaded with `-p`. For convenience any file we place under ~/.config/chatblade/ will be picked up by this command. +These can be loaded with `-p`. For convenience any file we place under `~/.config/chatblade/` will be picked up by this command. So for example, given the following file `~/.config/chatblade/etymology`, which contains: @@ -203,7 +203,13 @@ We can now run a command and refer to this prompt with `-p etymology`: chatblade -p etymology gregarious ``` -You can also point -p to a file path directly to load a system message from any arbitrary location +If you set the environment variable `CHATBLADE_DEFAULT_PROMPT` to the name of a prompt, chatblade will use its value if no other prompt is specified on the command line. +```bash +% export CHATBLADE_DEFAULT_PROMPT=default +% chatblade "Hi there" # Acts like -p default +``` + +You can also point `-p` to a file path directly to load a system message from any arbitrary location diff --git a/chatblade/cli.py b/chatblade/cli.py index 14d9806..084156f 100644 --- a/chatblade/cli.py +++ b/chatblade/cli.py @@ -57,8 +57,8 @@ def handle_input(query, params): messages = None if params.session: messages = storage.messages_from_cache(params.session) - if messages: # a session specified and it alredy exists - if params.prompt_file: + if messages: # a session specified and it already exists + if params.prompt_file and not params.prompt_set_by_env: printer.warn("refusing to prepend prompt to existing session") exit(1) if query: # continue conversation @@ -143,6 +143,15 @@ def cli(): migrate_old_cache_file_if_exists() query, params = parser.parse(sys.argv[1:]) + + # If we don't have a prompt on the command line, but the user has + # defined a CHATBLADE_DEFAULT_PROMPT environment variable, use the env + # variable as the prompt. + params.prompt_set_by_env = False + if not params.prompt_file and "CHATBLADE_DEFAULT_PROMPT" in os.environ: + params.prompt_file = os.environ["CHATBLADE_DEFAULT_PROMPT"] + params.prompt_set_by_env = True + if params.session_op: ret = do_session_op(params.session, params.session_op, params.rename_to) exit(ret)