Skip to content

Commit

Permalink
Improve aitldr plugin system prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
jlelse committed Jul 22, 2024
1 parent bc8a283 commit 8fdfeb3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ require (
github.com/valyala/fastjson v1.6.4 // indirect
go.mau.fi/util v0.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/image v0.18.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 h1:wDLEX9a7YQoKdKNQt88rtydkqDxeGaBUTnIYc3iG/mA=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
Expand Down
50 changes: 29 additions & 21 deletions plugins/aitldr/src/aitldr/aitldr.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func (p *plugin) Prio() int {
const postParam = "aitldr"

func (p *plugin) RenderPost(renderContext plugintypes.RenderContext, post plugintypes.Post, doc *goquery.Document) {
// Add re-generation button
if renderContext.IsLoggedIn() {
buttonBuf := bufferpool.Get()
defer bufferpool.Put(buttonBuf)
buttonHw := htmlbuilder.NewHtmlBuilder(buttonBuf)
buttonHw.WriteElementOpen("form", "method", "post", "action", "/x/aitldr")
buttonHw.WriteElementOpen("input", "type", "hidden", "name", "post", "value", post.GetPath())
buttonHw.WriteElementOpen("input", "type", "submit", "value", "Regenerate AI summary")
buttonHw.WriteElementClose("form")

doc.Find("#posteditactions").AppendHtml(buttonBuf.String())
}

// If the post has a summary, display it
tldr := post.GetFirstParameterValue(postParam)
if tldr == "" {
return
Expand Down Expand Up @@ -107,18 +121,6 @@ func (p *plugin) RenderPost(renderContext plugintypes.RenderContext, post plugin
hw.WriteElementsClose("i", "div")

doc.Find(".h-entry > article > .e-content").BeforeHtml(buf.String())

if renderContext.IsLoggedIn() {
buttonBuf := bufferpool.Get()
defer bufferpool.Put(buttonBuf)
buttonHw := htmlbuilder.NewHtmlBuilder(buttonBuf)
buttonHw.WriteElementOpen("form", "method", "post", "action", "/x/aitldr")
buttonHw.WriteElementOpen("input", "type", "hidden", "name", "post", "value", post.GetPath())
buttonHw.WriteElementOpen("input", "type", "submit", "value", "Regenerate AI summary")
buttonHw.WriteElementClose("form")

doc.Find("#posteditactions").AppendHtml(buttonBuf.String())
}
}

const customCSS = ".aitldr { border: 1px dashed; padding: 1em; }"
Expand Down Expand Up @@ -213,15 +215,21 @@ func (p *plugin) summarize(post plugintypes.Post) {
}

func (p *plugin) systemMessage() string {
prompt := "You are a summary writing plugin in a blogging system. " +
"Your task is to generate concise and effective summaries for long blog posts. " +
"When given a full blog post, extract the key points and present them in a clear, brief format. " +
"The summary must be in the same language as the blog post, have a maximum length of 250 characters, contain no linebreaks, and be plain text. " +
"Importantly, the summary should be written in the first person perspective, as if the blog author themselves are summarizing the post. " +
"Avoid phrases like 'The author states' or 'The blogger argues', and instead write as if the author is speaking. " +
"Maintain the original intent and tone of the blog post in your summary. " +
"Always respond with just the summary content."
return prompt
return `You are a summary writing plugin for a blogging platform.
Your task is to generate concise, first-person perspective summaries for lengthy blog posts, ensuring they capture the essence of the original content.
Guidelines:
1. Extract key points and present them in a clear, brief format.
2. Summaries must be in the same language as the blog post.
3. Limit the summary to a maximum of 250 characters, with no linebreaks.
4. Provide plain text without any formatting.
5. Write in the first person as if the author is summarizing their own post.
6. Avoid phrases like 'The author states' or 'The blogger argues.' Write as though the author is speaking directly.
7. Maintain the original intent and tone of the blog post.
8. If the blog post is shorter than 250 characters, return the original content as the summary.
Respond only with the summary content.`
}

func (p *plugin) createPrompt(post plugintypes.Post) string {
Expand Down

0 comments on commit 8fdfeb3

Please sign in to comment.