Don't include system message when generating conversation title

This commit is contained in:
Matt Low 2023-11-29 04:51:38 +00:00
parent 4f37ed046b
commit c64bc370f4

View File

@ -31,7 +31,7 @@ func (m *Message) FriendlyRole() string {
func (c *Conversation) GenerateTitle() error { func (c *Conversation) GenerateTitle() error {
const header = "Generate a consise 4-5 word title for the conversation below." const header = "Generate a consise 4-5 word title for the conversation below."
prompt := fmt.Sprintf("%s\n\n---\n\n%s", header, c.FormatForExternalPrompting()) prompt := fmt.Sprintf("%s\n\n---\n\n%s", header, c.FormatForExternalPrompting(false))
messages := []Message{ messages := []Message{
{ {
@ -50,13 +50,16 @@ func (c *Conversation) GenerateTitle() error {
return nil return nil
} }
func (c *Conversation) FormatForExternalPrompting() string { func (c *Conversation) FormatForExternalPrompting(system bool) string {
sb := strings.Builder{} sb := strings.Builder{}
messages, err := store.Messages(c) messages, err := store.Messages(c)
if err != nil { if err != nil {
Fatal("Could not retrieve messages for conversation %v", c) Fatal("Could not retrieve messages for conversation %v", c)
} }
for _, message := range messages { for _, message := range messages {
if message.Role == MessageRoleSystem && !system {
continue
}
sb.WriteString(fmt.Sprintf("<%s>\n", message.FriendlyRole())) sb.WriteString(fmt.Sprintf("<%s>\n", message.FriendlyRole()))
sb.WriteString(fmt.Sprintf("\"\"\"\n%s\n\"\"\"\n\n", message.OriginalContent)) sb.WriteString(fmt.Sprintf("\"\"\"\n%s\n\"\"\"\n\n", message.OriginalContent))
} }