Documentation
¶
Overview ¶
Package rf for handling RSS feeds
Index ¶
- Constants
- Variables
- func Prettify(v any) string
- func StandardizeJSON(b []byte) ([]byte, error)
- type CachedCooldown
- type CachedItem
- type Client
- func (c *Client) DeleteOldCachedItems() error
- func (c *Client) FetchFeeds(ctx context.Context, ignoreAlreadyCached bool, ...) ([]gofeed.Feed, error)
- func (c *Client) ListCachedItems(includeItemsMarkedAsRead bool) []CachedItem
- func (c *Client) MarkCachedItemsAsRead(items []CachedItem) error
- func (c *Client) PublishXML(title, link, description, author, email string, items []CachedItem) (bytes []byte, err error)
- func (c *Client) SetDesiredLanguage(lang string)
- func (c *Client) SetExaoneAPIKeys(apiKeys []string)
- func (c *Client) SetExaoneHTTPClient(client *http.Client)
- func (c *Client) SetExaoneModels(models []string)
- func (c *Client) SetGoogleAIModels(models []string)
- func (c *Client) SetSummarizeIntervalSeconds(seconds int)
- func (c *Client) SetVerbose(v bool)
- func (c *Client) SummarizeAndCacheFeeds(ctx context.Context, feeds []gofeed.Feed, urlScrapper ...*ssg.Scrapper) (err error)
- type FeedsItemsCache
Constants ¶
const ( ErrorPrefixSummaryFailedWithError = `Summary failed with error` PublishContentType = `application/rss+xml` )
Variables ¶
var ErrNoAvailableAPIKey = errors.New("no available api key/model (all in cooldown)")
ErrNoAvailableAPIKey is returned when every (key, model) combo is in cooldown.
var ErrNoProviderForTask = errors.New("no configured api key/model supports this content")
ErrNoProviderForTask is returned when no configured provider can do the task at all (eg. a PDF file with EXAONE api keys only).
NOTE: it is not retriable later, so the item is cached with the error message.
Functions ¶
func StandardizeJSON ¶
StandardizeJSON standardizes given JSON (JWCC) bytes.
Types ¶
type CachedCooldown ¶ added in v0.4.9
type CachedCooldown struct {
APIKeyHash string `gorm:"primaryKey"`
Model string `gorm:"primaryKey"`
Until time.Time // when the combo becomes usable again
Failures int // consecutive quota errors of the combo, for escalation
UpdatedAt time.Time
}
CachedCooldown is a persisted quota cooldown of a single (api key, model) combination, so that a restarted process does not immediately hit the same exhausted quota again.
NOTE: the api key itself is never stored, only `hashAPIKey` of it.
type CachedItem ¶
type CachedItem struct {
gorm.Model
Title string
Link string // url to the original article
Comments string // url to the community comments
GUID string `gorm:"uniqueIndex"`
Author string
PublishDate string
Description string
Summary string
MarkedAsRead bool `gorm:"index"`
}
CachedItem is a struct for a cached item
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client struct
func NewClient ¶
NewClient returns a new client with memory cache.
EXAONE API keys can be added with `SetExaoneAPIKeys`.
func NewClientWithDB ¶
func NewClientWithDB( googleAIAPIKeys []string, feedsURLs []string, dbFilepath string, ) (client *Client, err error)
NewClientWithDB returns a new client with SQLite DB cache.
func (*Client) DeleteOldCachedItems ¶
DeleteOldCachedItems deletes old cached items, and cooldowns which expired long ago.
func (*Client) FetchFeeds ¶
func (c *Client) FetchFeeds( ctx context.Context, ignoreAlreadyCached bool, ignoreItemsPublishedBeforeDays uint, ) ([]gofeed.Feed, error)
FetchFeeds fetches feeds.
func (*Client) ListCachedItems ¶
func (c *Client) ListCachedItems(includeItemsMarkedAsRead bool) []CachedItem
ListCachedItems lists cached items.
func (*Client) MarkCachedItemsAsRead ¶
func (c *Client) MarkCachedItemsAsRead(items []CachedItem) error
MarkCachedItemsAsRead marks given cached items as read.
func (*Client) PublishXML ¶
func (c *Client) PublishXML( title, link, description, author, email string, items []CachedItem, ) (bytes []byte, err error)
PublishXML returns XML bytes (application/rss+xml) of given cached items.
func (*Client) SetDesiredLanguage ¶
SetDesiredLanguage sets the client's desired language for summaries.
func (*Client) SetExaoneAPIKeys ¶ added in v0.5.0
SetExaoneAPIKeys sets the client's EXAONE API keys.
EXAONE combos are used for text contents only: files (eg. PDF), YouTube videos, and urls which could not be fetched are summarized with Gemini.
func (*Client) SetExaoneHTTPClient ¶ added in v0.5.1
SetExaoneHTTPClient sets the http client for EXAONE API requests (`http.DefaultClient` when nil).
Its transport may rewrite requests, eg. replace the 'Authorization' header with a renewed api key: then the keys given to `SetExaoneAPIKeys` can be placeholders, which only tell the combos apart.
func (*Client) SetExaoneModels ¶ added in v0.5.0
SetExaoneModels sets the client's EXAONE models.
func (*Client) SetGoogleAIModels ¶ added in v0.3.2
SetGoogleAIModels sets the client's Google AI models.
func (*Client) SetSummarizeIntervalSeconds ¶
SetSummarizeIntervalSeconds sets the client's summarize interval seconds.
func (*Client) SetVerbose ¶
SetVerbose sets the client's verbose mode.
func (*Client) SummarizeAndCacheFeeds ¶
func (c *Client) SummarizeAndCacheFeeds( ctx context.Context, feeds []gofeed.Feed, urlScrapper ...*ssg.Scrapper, ) (err error)
SummarizeAndCacheFeeds summarizes given feeds items and caches them.
Each feed item will be summarized with a timeout of `summarizeTimeoutSeconds` seconds.
If summary fails, the original content prepended with the error message will be cached.
If there was a retriable error(eg. model overloads or exhausted quota), it will return immediately. (remaining feed items will be retried later)
Exhausted quotas are handled by how long they last (see `deferralFor`):
- when the needed (key, model) combos recover within `longCooldownThreshold`, the item is retried later
- otherwise, the item is cached with the error message (and the time of recovery), so that a backlog does not use up the recovered quota at once and delay the new items again
type FeedsItemsCache ¶
type FeedsItemsCache interface {
Exists(guid string) bool
Save(item gofeed.Item, title, summary string) error
Fetch(guid string) *CachedItem
MarkAsRead(guid string) error
List(includeItemsMarkedAsRead bool) []CachedItem
DeleteOlderThan1Month() error
// LoadCooldowns lists all persisted (api key, model) cooldowns.
LoadCooldowns() []CachedCooldown
// SaveCooldown persists (or updates) the cooldown of one (api key, model).
SaveCooldown(cooldown CachedCooldown) error
// DeleteCooldown drops the persisted cooldown of one (api key, model).
DeleteCooldown(apiKeyHash, model string) error
SetVerbose(v bool)
}
FeedsItemsCache is an interface of feeds items' cache