From 8fdfeb34f2849ef3590b99a9eb8c8371a99cea43 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Mon, 22 Jul 2024 13:46:10 +0200 Subject: [PATCH] Improve aitldr plugin system prompt --- go.mod | 2 +- go.sum | 4 +-- plugins/aitldr/src/aitldr/aitldr.go | 50 +++++++++++++++++------------ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index bf0157d..2a0a59f 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 3910548..df74a2a 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/plugins/aitldr/src/aitldr/aitldr.go b/plugins/aitldr/src/aitldr/aitldr.go index c174cb0..441fd21 100644 --- a/plugins/aitldr/src/aitldr/aitldr.go +++ b/plugins/aitldr/src/aitldr/aitldr.go @@ -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 @@ -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; }" @@ -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 {