diff --git a/README.md b/README.md index 4c02592..e525866 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,9 @@ I'm an AI language model, and each interaction with me doesn't necessarily carry Whatever you type into the prompt will be sent to the AI, unless it's a meta command. The meta commands are all prefixed with a backslash: -- `\reset` Reset the conversation history to a blank slate. This includes the system message. -- `\messages` Print out the entirety of the current conversation. (After a reset, this is blank) +- `\reset` Reset the conversation history to a blank slate. This leaves the system message. +- `\reset-system` Removes the system message. +- `\messages` Print out the entirety of the current conversation. (After a reset, this is blank except for system message if any) - `\config` Prints out aicli's configuration. - `\file ` Send the path and contents of a file on your local filesystem to the AI. It will be prefixed with a short message explaining that you'll refer to the file later. The AI should just respond with something like "ok". - `\system ` Prepends a system message to the list of messages (or replaces if one is already there). Does not send anything to the AI, but the new system message will be sent with the next message. diff --git a/pkg/aicli/cmd.go b/pkg/aicli/cmd.go index f84fc56..9784222 100644 --- a/pkg/aicli/cmd.go +++ b/pkg/aicli/cmd.go @@ -127,13 +127,25 @@ func (cmd *Cmd) sendMessages() error { return nil } +func (cmd *Cmd) hasSystemMessage() bool { + return len(cmd.messages) > 0 && cmd.messages[0].Role() == RoleSystem +} + func (cmd *Cmd) handleMeta(line string) { parts := strings.SplitN(line, " ", 2) var err error switch parts[0] { case `\reset`: - cmd.messages = []Message{} + if cmd.hasSystemMessage() { + cmd.messages = cmd.messages[:1] + } else { + cmd.messages = cmd.messages[:0] + } cmd.totalLen = 0 + case `\reset-system`: + if cmd.hasSystemMessage() { + cmd.messages = cmd.messages[1:] + } case `\messages`: cmd.printMessages() case `\config`: @@ -146,8 +158,9 @@ func (cmd *Cmd) handleMeta(line string) { } case `\system`: if len(parts) == 1 { - // TODO need a way to clear system message, but I think just doing \system should print the system message - // need tests for error cases (e.g. wrong number of args) for each system message + if cmd.hasSystemMessage() { + cmd.out(cmd.messages[0].Content() + "\n") + } break } msg := SimpleMsg{