Documentation
¶
Index ¶
- Constants
- func SetLogLevel(level slog.Level)
- func SetLogger(l *slog.Logger)
- type Config
- type DatabaseConfig
- type Document
- type DocumentSummary
- type GeminiConfig
- type GenAIClient
- type HTMLandDocuments
- type Item
- type ItemReasonCode
- type ItemRepository
- func (r *ItemRepository) AddItems(ctx context.Context, items []*gofeed.Item) (int, error)
- func (r *ItemRepository) Close() error
- func (r *ItemRepository) CountUnprocessedItems(ctx context.Context) (int, error)
- func (r *ItemRepository) GetItemByURL(ctx context.Context, url string) (*Item, error)
- func (r *ItemRepository) GetItemForScreening(ctx context.Context) (*Item, error)
- func (r *ItemRepository) GetItemForSummarization(ctx context.Context) (*Item, error)
- func (r *ItemRepository) IsURLExists(ctx context.Context, url string) (bool, error)
- func (r *ItemRepository) Update(ctx context.Context, item *Item) error
- type ItemStatus
- type MICSummaryBot
- type MastodonClient
- type MastodonConfig
- type PostInfo
- type RSSClient
- type RSSConfig
- type ScreeningDecision
- type ScreeningResult
- type StorageConfig
- type SummarizeResult
Constants ¶
const ( // MaxDocumentSize represents the maximum file size (50MB) for documents // that can be uploaded to Gemini API. This limitation is imposed by // Google's Gemini API to ensure reasonable processing times and resource usage. // Documents larger than this size will be skipped during summarization. MaxDocumentSize = 50 * 1024 * 1024 // 50MB in bytes )
Variables ¶
This section is empty.
Functions ¶
func SetLogLevel ¶
SetLogLevel allows setting the log level dynamically without recreating the logger. This is safe to call concurrently. Note that this only works with the default package logger or custom loggers that were designed to work with this function.
Types ¶
type Config ¶
type Config struct { RSS RSSConfig `yaml:"rss"` Gemini GeminiConfig `yaml:"gemini"` Mastodon MastodonConfig `yaml:"mastodon"` Storage StorageConfig `yaml:"storage"` Database DatabaseConfig `yaml:"database"` }
Config は Bot の設定情報を保持する
func DefaultConfig ¶
func DefaultConfig() *Config
func LoadConfig ¶
LoadConfig は指定されたパスから設定ファイルを読み込み、Config構造体にパースします。記述されていない項目はデフォルト値が使われます
type DatabaseConfig ¶
type DocumentSummary ¶
type GeminiConfig ¶
type GeminiConfig struct { APIKey string `yaml:"api_key"` MaxTokens int `yaml:"max_tokens"` RetryCount int `yaml:"retry_count"` RetryIntervalSec int `yaml:"retry_interval_sec"` ScreeningModel string `yaml:"screening_model"` ScreeningPrompt string `yaml:"screening_prompt"` SummarizingModel string `yaml:"summarizing_model"` SummarizingPrompt string `yaml:"summarizing_prompt"` }
type GenAIClient ¶
type GenAIClient struct { Client *genai.Client MaxRetry int RetryIntervalSec int ScreeningModel string SummarizingModel string DownloadDir string KeepLocalCopy bool }
func NewGenAIClient ¶
func NewGenAIClient(gemini *GeminiConfig, storage *StorageConfig) (*GenAIClient, error)
NewGenAIClient は新しいGenAIClientインスタンスを作成します。
func (*GenAIClient) IsWorthSummarizing ¶
func (client *GenAIClient) IsWorthSummarizing(htmlAndDocs *HTMLandDocuments, promptTemplate string) (*ScreeningResult, error)
IsWorthSummarizing はHTMLandDocumentsが要約する価値のあるものか判定します。
func (*GenAIClient) SummarizeDocument ¶
func (client *GenAIClient) SummarizeDocument(htmlAndDocs *HTMLandDocuments, promptTemplate string) (SummarizeResult, error)
SummarizeDocument はHTMLandDocumentsを要約します。
type HTMLandDocuments ¶
HTMLandDocuments はHTMLコンテンツとその中に添付されているドキュメントのリストを保持します。
func GetHTMLSummary ¶
func GetHTMLSummary(targetURL string) (*HTMLandDocuments, error)
GetHTMLSummary は指定されたURLからHTMLを取得し、パースしてHTMLSummary構造体を返します。
type Item ¶
type Item struct { ID int URL string Title string PublishedAt time.Time Status ItemStatus Reason ItemReasonCode RetryCount int CreatedAt time.Time LastCheckedAt time.Time }
Item は items テーブルのレコードを表す構造体
type ItemReasonCode ¶
type ItemReasonCode int
ItemReasonCode はアイテムが先送りまたは処理済みになった理由を表すコード
const ( ReasonNone ItemReasonCode = iota // 0: 理由なし (通常はprocessedに遷移した場合) ReasonGeminiNotValuable // 1: Gemini判定: 要約する価値なし ReasonGeminiPageNotReady // 2: Gemini判定: ページがまだ完成していない ReasonDownloadFailed // 3: ファイルダウンロード失敗 ReasonLargeFileSkipped // 4: ファイルサイズが大きすぎるため要約スキップ ReasonAPIFailed // 5: Gemini/Mastodon API呼び出し失敗 ReasonRetryLimitExceeded // 6: リトライ回数上限超過 )
type ItemRepository ¶
type ItemRepository struct {
// contains filtered or unexported fields
}
ItemRepository は items テーブルへの操作を提供する
func NewItemRepository ¶
func NewItemRepository(dbPath string, maxDeferredRetryCount int) (*ItemRepository, error)
NewItemRepository は新しいItemRepositoryインスタンスを作成し、データベース接続を初期化します。 テーブルが存在しない場合は作成します。
func (*ItemRepository) CountUnprocessedItems ¶
func (r *ItemRepository) CountUnprocessedItems(ctx context.Context) (int, error)
func (*ItemRepository) GetItemByURL ¶
GetItemByURL
func (*ItemRepository) GetItemForScreening ¶
func (r *ItemRepository) GetItemForScreening(ctx context.Context) (*Item, error)
GetItemForScreening はスクリーニング対象のアイテムを取得します。
func (*ItemRepository) GetItemForSummarization ¶
func (r *ItemRepository) GetItemForSummarization(ctx context.Context) (*Item, error)
GetItemForSummarization は要約対象のアイテムを取得します。
func (*ItemRepository) IsURLExists ¶
IsURLExists
type ItemStatus ¶
type ItemStatus int
ItemStatus はアイテムの処理状態を表す
const ( StatusUnprocessed ItemStatus = iota // 0: unprocessed(未処理) StatusDeferred // 1: deferred(先送り) StatusPending // 2: pending(処理待ち) StatusProcessed // 3: processed(処理済み) )
type MICSummaryBot ¶
type MICSummaryBot struct {
// contains filtered or unexported fields
}
func NewMICSummaryBot ¶
func NewMICSummaryBot(config *Config) (*MICSummaryBot, error)
func (*MICSummaryBot) PostSummary ¶
func (b *MICSummaryBot) PostSummary(ctx context.Context) (err error)
func (*MICSummaryBot) RefreshFeedItems ¶
func (b *MICSummaryBot) RefreshFeedItems(ctx context.Context) error
func (*MICSummaryBot) ScreenItem ¶
func (b *MICSummaryBot) ScreenItem(ctx context.Context) (err error)
type MastodonClient ¶
type MastodonClient struct {
// contains filtered or unexported fields
}
MastodonClient is a client for posting to Mastodon.
func NewMastodonClient ¶
func NewMastodonClient(config *Config) (*MastodonClient, error)
NewMastodonClient initializes and returns a new MastodonClient.
func (*MastodonClient) PostNoValue ¶
func (c *MastodonClient) PostNoValue(ctx context.Context, item Item) error
PostNoValue posts a predefined message for items deemed not valuable.
func (*MastodonClient) PostSummary ¶
func (c *MastodonClient) PostSummary(ctx context.Context, task Item, summary SummarizeResult) error
PostSummary posts the summary result to Mastodon.
type MastodonConfig ¶
type RSSClient ¶
type RSSClient struct {
// contains filtered or unexported fields
}
RSSClient はRSSフィードの取得とパースを行うクライアント
type ScreeningDecision ¶
type ScreeningDecision string
const ( WorthSummarizingYes ScreeningDecision = "YES" WorthSummarizingNo ScreeningDecision = "NO" WorthSummarizingWait ScreeningDecision = "WAIT" )
type ScreeningResult ¶
type ScreeningResult struct { Criteria []struct { Name string `json:"name"` Result ScreeningDecision `json:"result"` } `json:"criteria"` FinalResult ScreeningDecision `json:"final_result"` }
type StorageConfig ¶
type SummarizeResult ¶
type SummarizeResult struct { Documents []DocumentSummary `json:"documents"` Omissibles []string `json:"omissibles"` FinalSummary string `json:"final_summary"` }