feat: implement initiate option in sendMessage
This commit is contained in:
@@ -218,10 +218,11 @@ export class Brain {
|
|||||||
async sendMessage(
|
async sendMessage(
|
||||||
history: ReadonlyArray<MessageHistoryEntry>,
|
history: ReadonlyArray<MessageHistoryEntry>,
|
||||||
newMessages: ReadonlyArray<MessageHistoryEntry>,
|
newMessages: ReadonlyArray<MessageHistoryEntry>,
|
||||||
options: { now?: Date; maxSteps?: number } = {},
|
options: { now?: Date; maxSteps?: number; initiate?: boolean } = {},
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
const now = options.now ?? new Date();
|
const now = options.now ?? new Date();
|
||||||
const maxSteps = options.maxSteps ?? 8;
|
const maxSteps = options.maxSteps ?? 8;
|
||||||
|
const initiate = options.initiate ?? false;
|
||||||
|
|
||||||
const replyMessages: string[] = [];
|
const replyMessages: string[] = [];
|
||||||
const tools: ChatFunctionTool[] = buildSendMessageTools();
|
const tools: ChatFunctionTool[] = buildSendMessageTools();
|
||||||
@@ -237,16 +238,27 @@ export class Brain {
|
|||||||
const scheduleBlock = await this.buildScheduleBlock(now);
|
const scheduleBlock = await this.buildScheduleBlock(now);
|
||||||
const datetimeBlock = formatDatetime(now);
|
const datetimeBlock = formatDatetime(now);
|
||||||
|
|
||||||
const instruction = await loadPrompt("SEND_MESSAGE");
|
const instruction = initiate
|
||||||
const userPrompt = [
|
? await loadPrompt("START_CONVERSATION")
|
||||||
`Current date and time: ${datetimeBlock}`,
|
: await loadPrompt("SEND_MESSAGE");
|
||||||
scheduleBlock,
|
const userPrompt = initiate
|
||||||
memoryBlock,
|
? [
|
||||||
`Conversation so far:`,
|
`Current date and time: ${datetimeBlock}`,
|
||||||
historyBlock.length > 0 ? historyBlock : "(no prior messages)",
|
scheduleBlock,
|
||||||
`New user message(s) to which you must reply:`,
|
memoryBlock,
|
||||||
newBlock.length > 0 ? newBlock : "(none — open turn)",
|
`Conversation so far:`,
|
||||||
].join("\n\n");
|
historyBlock.length > 0 ? historyBlock : "(no prior messages)",
|
||||||
|
`You are opening this chat. The user has not sent a message.`,
|
||||||
|
].join("\n\n")
|
||||||
|
: [
|
||||||
|
`Current date and time: ${datetimeBlock}`,
|
||||||
|
scheduleBlock,
|
||||||
|
memoryBlock,
|
||||||
|
`Conversation so far:`,
|
||||||
|
historyBlock.length > 0 ? historyBlock : "(no prior messages)",
|
||||||
|
`New user message(s) to which you must reply:`,
|
||||||
|
newBlock.length > 0 ? newBlock : "(none — open turn)",
|
||||||
|
].join("\n\n");
|
||||||
|
|
||||||
const messages: ChatMessages[] = [
|
const messages: ChatMessages[] = [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user