Update title generation prompt

This commit is contained in:
Matt Low 2024-05-23 05:59:46 +00:00
parent eec9eb41e9
commit 008fdc0d37

View File

@ -149,7 +149,9 @@ func FormatForExternalPrompt(messages []model.Message, system bool) string {
} }
func GenerateTitle(ctx *lmcli.Context, messages []model.Message) (string, error) { func GenerateTitle(ctx *lmcli.Context, messages []model.Message) (string, error) {
const prompt = `Above is an excerpt from a conversation between a user and AI assistant. Please reply with a short title (no more than 8 words) that reflects the topic of the conversation, read from the user's perspective. const prompt = `Above is an excerpt from a conversation between a user and AI assistant.
Reply with a short title (no more than 8 words) that reflects the topic of the conversation, read from the user's perspective.
Example conversation: Example conversation:
@ -163,11 +165,13 @@ Assistant:
Hello! How may I assist you? Hello! How may I assist you?
""" """
Example response: Your response:
""" """
Title: A brief introduction Title: A brief introduction
""" """
Respond only as shown above.
` `
conversation := FormatForExternalPrompt(messages, false) conversation := FormatForExternalPrompt(messages, false)
@ -193,9 +197,10 @@ Title: A brief introduction
return "", err return "", err
} }
response = strings.TrimPrefix(response, "Title: ") // TODO: validate response format
response = strings.Trim(response, "\"") response = strings.TrimPrefix(response, "Title:")
response = strings.TrimSpace(response) response = strings.TrimSpace(response)
response = strings.Trim(response, "\"")
return response, nil return response, nil
} }