Skip to content

Commit

Permalink
feat: 支持新会话
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyurus committed May 27, 2024
1 parent df19c5c commit faac796
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/cli/commands/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ChatCommand extends BaseCommand {
console.warn = () => {};
process.stdout.write(
this.getDisplayContent(PromptRole.SYSTEM) +
`If you want to end this conversation, please tell the AI directly\n`
'If you want to end this conversation, please tell the AI directly\n'
);
process.stdout.write(aiDisplay + lastMessage + '\n');

Expand All @@ -86,10 +86,18 @@ class ChatCommand extends BaseCommand {
break;
}

process.stdout.write('\n');

await this.addMessage(PromptRole.USER, userMessage);
await this.addMessage(PromptRole.AI, lastMessage);

if (lastMessage === '$command:clear$') {
process.stdout.write(ansiEscapes.eraseLine + ansiEscapes.cursorLeft);
process.stdout.write(this.getDisplayContent(PromptRole.SYSTEM) + 'This is a new conversation.\n');
process.stdout.write(aiDisplay + 'How can I help you today?');

await this.messages.clear();
}

process.stdout.write('\n');
}
} else {
this.showHelp();
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class AIGC {
const platform = getPlatform(this.platform);
const prompt = ChatPromptTemplate.fromMessages([
SystemMessagePromptTemplate.fromTemplate(
'You are a helpful assistant. Answer all questions to the best of your ability.\nIf the user wants to end the conversation or exit the current chat command, directly reply to the user "$command:exit$"'
'You are a helpful assistant. Answer all questions to the best of your ability.\nIf the user wants to end the conversation or exit the current chat command, directly reply to the user "$command:exit$".\nIf the user wants to start a new conversation, directly reply to the user "$command:clear$".'
),
new MessagesPlaceholder('messages'),
HumanMessagePromptTemplate.fromTemplate('{question}')
Expand Down

0 comments on commit faac796

Please sign in to comment.