Skip to content

Commit

Permalink
Improve one-shot mode to support initial messages
Browse files Browse the repository at this point in the history
  • Loading branch information
synaptiko committed Apr 24, 2023
1 parent 38af43e commit 8597dc1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
https://platform.openai.com/docs/guides/error-codes
- [ ] Keep history of used tokens per conversation and globally (+ have estimation of cost)
- [ ] Implement plugin system (+ have support for sub-conversations which can be used by plugin to spawn another cli-gpt process)
- https://github.com/Nutlope/aicommits
- https://github.com/di-sukharev/opencommit
4 changes: 2 additions & 2 deletions src/ConversationPersistance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export class ConversationPersistance {
);
}

getMessages(): Message[] {
getMessages({ onlyInitial }: { onlyInitial?: boolean } = {}): Message[] {
const initialMessages = readFile(initialMessagesPath);
const conversation = readFile(conversationPath);
const conversation = onlyInitial ? undefined : readFile(conversationPath);

return [...parseMessages(initialMessages), ...parseMessages(conversation)];
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if (flags.help) {
const responseContent = [];

if (flags.oneShot) {
chatCompletion.setMessages([{ role: 'user', content }]);
chatCompletion.setMessages([...conversationPersistance.getMessages({ onlyInitial: true }), { role: 'user', content }]);
} else {
chatCompletion.setMessages(conversationPersistance.getMessages());
}
Expand Down
1 change: 1 addition & 0 deletions src/printHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Options:
--read, -r [file(s)] Read file(s) and use their content in the prompt.
--initial, -i Add to or reset the initial messages.
--one-shot, -o Prompt without persisted conversation, do not save the result.
Uses initial messages if present.
--copy, -c Copy the response to the clipboard.
--reset, -e Reset the conversation.
--help, -h Display this help message and exit.
Expand Down

0 comments on commit 8597dc1

Please sign in to comment.