Skip to content

Commit

Permalink
feat: add new craft to filter out advertorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin-XKL committed May 6, 2024
1 parent 48f059b commit 9f2d996
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
24 changes: 24 additions & 0 deletions internal/adapter/llm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package adapter

import (
"fmt"
)

func CallGemini(prompt string, article string) (string, error) {
gemini, err := NewGeminiClient()
if err != nil {
return "", err
}
text := fmt.Sprintf("%s\n```%s```", prompt, article)
req := GeminiReqPayload{Contents: []Content{
{
Parts: []Part{{Text: &text}},
Role: nil,
},
}}
content, err := gemini.GenerateContent(req)
if err != nil {
return "", err
}
return content, nil
}
4 changes: 2 additions & 2 deletions internal/recipe/fulltext.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

type FulltextExtractor func(url string, timeout time.Duration) (string, error)

func trivialExtractor(url string, timeout time.Duration) (string, error) {
func TrivialExtractor(url string, timeout time.Duration) (string, error) {
article, err := readability.FromURL(url, timeout)
return article.Content, err
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func ExtractFulltextForFeed(c *gin.Context) {
fp := gofeed.NewParser()
parsedFeed, _ := fp.ParseURL(feedUrl)

ret := TransformFeed(parsedFeed, GetFulltextExtractor(trivialExtractor))
ret := TransformFeed(parsedFeed, GetFulltextExtractor(TrivialExtractor))

rssStr, err := ret.ToRss()
if err != nil {
Expand Down
17 changes: 1 addition & 16 deletions internal/recipe/introduction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,7 @@ add introduction for article,powered by google gemini
*/

func getIntroductionForArticle(prompt, article string) (string, error) {
gemini, err := adapter.NewGeminiClient()
if err != nil {
return "", err
}
text := fmt.Sprintf("%s\n```%s```", prompt, article)
req := adapter.GeminiReqPayload{Contents: []adapter.Content{
{
Parts: []adapter.Part{{Text: &text}},
Role: nil,
},
}}
content, err := gemini.GenerateContent(req)
if err != nil {
return "", err
}
return content, nil
return adapter.CallGemini(prompt, article)
}

func getMD5Hash(text string) string {
Expand Down
2 changes: 2 additions & 0 deletions internal/router/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ func RegisterRouters(router *gin.Engine) {
craftRouters.GET("/fulltext", recipe.ExtractFulltextForFeed)
craftRouters.GET("/fulltext-plus", recipe.ExtractFulltextPlusForFeed)
craftRouters.GET("/introduction", recipe.AddIntroductionForFeed)
craftRouters.GET("/ignore-advertorial", recipe.IgnoreAdvertorialArticle)
}

// admin api
adminApi := router.Group("/api/admin")
adminApi.Use(middleware.JwtAuthMiddleware(), corsMiddleware)
{
adminApi.GET("/admin-login-test", adminLoginTest)
adminApi.POST("/craft-debug/advertorial", recipe.DebugCheckIfAdvertorial)
}
}
func adminLoginTest(c *gin.Context) {
Expand Down

0 comments on commit 9f2d996

Please sign in to comment.