Skip to content

Commit

Permalink
reset doesn't clear system msg
Browse files Browse the repository at this point in the history
\reset-system does, \system prints system message
  • Loading branch information
jaffee committed Nov 18, 2023
1 parent ff1495f commit bb715a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filepath>` 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 <message>` 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.
Expand Down
19 changes: 16 additions & 3 deletions pkg/aicli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand All @@ -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{
Expand Down

0 comments on commit bb715a7

Please sign in to comment.