Skip to content

Commit c58b35a

Browse files
authored
Merge pull request #48 from Hegghammer/custom_summarize_prompt
2 parents 0b145e6 + 367a5a7 commit c58b35a

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ openai_api_key:
3636
openai_base_url:
3737
openai_model:
3838
summary_feeds:
39+
summary_prompt:
3940
show_images: false
4041
analyst_feeds:
4142
- https://feeds.bbci.co.uk/news/business/rss.xml
@@ -137,7 +138,9 @@ func bootstrapConfig() {
137138
if viper.IsSet("openai_model") {
138139
openaiModel = viper.Get("openai_model").(string)
139140
}
140-
141+
if viper.IsSet("summary_prompt") {
142+
summaryPrompt = viper.Get("summary_prompt").(string)
143+
}
141144
if viper.IsSet("summary_feeds") {
142145
summaryFeeds := viper.Get("summary_feeds")
143146

@@ -146,11 +149,12 @@ func bootstrapConfig() {
146149
myFeeds = append(myFeeds, RSS{url: url, limit: limit, summarize: true})
147150
}
148151
}
149-
150-
for _, feed := range feeds.([]any) {
151-
url, limit := getFeedAndLimit(feed.(string))
152-
myFeeds = append(myFeeds, RSS{url: url, limit: limit})
153-
}
152+
if feeds != nil {
153+
for _, feed := range feeds.([]any) {
154+
url, limit := getFeedAndLimit(feed.(string))
155+
myFeeds = append(myFeeds, RSS{url: url, limit: limit})
156+
}
157+
}
154158

155159
if viper.IsSet("google_news_keywords") {
156160
googleNewsKeywords := url.QueryEscape(viper.Get("google_news_keywords").(string))

feeds_writer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var show_images bool
2828
var sunrise_sunset bool
2929
var myFeeds []RSS
3030
var db *sql.DB
31+
var summaryPrompt string
3132

3233
type RSS struct {
3334
url string

summarize.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
readability "github.com/go-shiori/go-readability"
99
openai "github.com/sashabaranov/go-openai"
10+
"github.com/spf13/viper"
1011
)
1112

1213
func getSummaryFromLink(url string) string {
@@ -30,6 +31,12 @@ func summarize(text string) string {
3031
if len(text) < 200 {
3132
return ""
3233
}
34+
35+
prompt := summaryPrompt
36+
if prompt == "" {
37+
prompt = "Summarize the following text:"
38+
}
39+
3340
clientConfig := openai.DefaultConfig(openaiApiKey)
3441
if openaiBaseURL != "" {
3542
clientConfig.BaseURL = openaiBaseURL
@@ -46,7 +53,7 @@ func summarize(text string) string {
4653
Messages: []openai.ChatCompletionMessage{
4754
{
4855
Role: openai.ChatMessageRoleAssistant,
49-
Content: "Summarize the following text:",
56+
Content: prompt,
5057
},
5158
{
5259
Role: openai.ChatMessageRoleUser,

0 commit comments

Comments
 (0)