-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation of summary feature (#3)
- Loading branch information
Showing
16 changed files
with
675 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 0 additions & 71 deletions
71
src/conversation-prompt/create-conversation-completion-prompt.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from "./prompt.dto"; | ||
export * from "./conversation-prompt-service.dto"; | ||
export * from "./mention"; | ||
export { ConversationPromptService } from "./conversation-prompt.service"; |
32 changes: 32 additions & 0 deletions
32
src/conversation-prompt/prompts/create-conversation-completion-prompt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AIPersona, Conversation } from "../../types"; | ||
import { BOT_MENTION } from "../mention"; | ||
import { STATEMENT_SEPARATOR_TOKEN } from "./prompts.constants"; | ||
import { renderAIPersona } from "./render-ai-persona"; | ||
import { renderConversation } from "./render-conversation"; | ||
import { renderFormatAndExamples } from "./render-format-and-examples"; | ||
|
||
const CURRENT_CONVERSATION_PROMPT = `Continue the conversation, paying very close attention to things entities told you; such as their name, and personal details. Never say "${STATEMENT_SEPARATOR_TOKEN}". Current conversation:`; | ||
|
||
export type CreateConversationCompletionPromptInput = { | ||
aiPersona: AIPersona; | ||
exampleConversations?: Conversation[]; | ||
conversation: Conversation; | ||
}; | ||
|
||
export function createConversationCompletionPrompt({ | ||
aiPersona, | ||
conversation, | ||
exampleConversations, | ||
}: CreateConversationCompletionPromptInput): string { | ||
const hasSummary = !!conversation.summary; | ||
|
||
return ( | ||
renderAIPersona(aiPersona) + | ||
`\n${renderFormatAndExamples({ | ||
hasSummary, | ||
exampleConversations, | ||
})}` + | ||
`\n\n${CURRENT_CONVERSATION_PROMPT}\n\n` + | ||
(renderConversation(conversation) + `${BOT_MENTION}:`) | ||
); | ||
} |
62 changes: 62 additions & 0 deletions
62
src/conversation-prompt/prompts/create-conversation-summary-prompt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { AIPersona, Conversation } from "../../types"; | ||
import { STATEMENT_SEPARATOR_TOKEN } from "./prompts.constants"; | ||
import { renderAIPersona } from "./render-ai-persona"; | ||
import { renderConversation } from "./render-conversation"; | ||
import { renderFormatAndExamples } from "./render-format-and-examples"; | ||
|
||
export type CreateConversationSummaryPromptInput = { | ||
aiPersona: AIPersona; | ||
conversation: Conversation; | ||
}; | ||
|
||
const buildPrompt = ({ | ||
hasSummary, | ||
hasMultipleEntities, | ||
}: { | ||
hasSummary: boolean; | ||
hasMultipleEntities: boolean; | ||
}): string => { | ||
let prompt = ""; | ||
|
||
if (hasSummary) { | ||
prompt += | ||
"Summarize the conversation below. Make a detailed summary which only consists of the previous summary and later messages. "; | ||
} else { | ||
prompt += | ||
"Summarize the conversation below. Make a detailed summary of the existing messages. "; | ||
} | ||
|
||
prompt += `Do not summarize the instructions or examples. Do not add anything extra or something that was not discussed. Do not repeat details. Pay close attention to the things that entities told you; especially their personal details and code details. `; | ||
|
||
if (hasMultipleEntities) { | ||
prompt += `You must reference entities in the conversation with the "<@id>" format in the summary to differentiate their personal details and messages. `; | ||
} | ||
|
||
prompt += `Omit small talk and conversation status. Never say "${STATEMENT_SEPARATOR_TOKEN}":`; | ||
|
||
return prompt; | ||
}; | ||
|
||
export const createConversationSummaryPrompt = ({ | ||
aiPersona, | ||
conversation, | ||
}: CreateConversationSummaryPromptInput) => { | ||
const hasSummary = !!conversation.summary; | ||
const participantCount = conversation.messages.reduce( | ||
(set, { author }) => (author.type !== "BOT" ? set.add(author.id) : set), | ||
new Set<string>() | ||
).size; | ||
const prompt = buildPrompt({ | ||
hasSummary, | ||
hasMultipleEntities: participantCount > 1, | ||
}); | ||
|
||
return ( | ||
renderAIPersona(aiPersona) + | ||
`\n${renderFormatAndExamples({ | ||
hasSummary, | ||
})}` + | ||
`\n\n${prompt}\n\n` + | ||
(renderConversation(conversation) + `...\nSummary:`) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const STATEMENT_SEPARATOR_TOKEN = "<|endofstatement|>"; |
Oops, something went wrong.