micsummarybot

package
v0.0.0-...-a5b6798 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
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

func SetLogLevel(level slog.Level)

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.

func SetLogger

func SetLogger(l *slog.Logger)

SetLogger allows an external package to set the logger for this package. Note: If you want to continue using SetLogLevel after calling SetLogger, you should create your custom logger with a LevelVar that can be controlled externally.

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

func LoadConfig(configPath string) (*Config, error)

LoadConfig は指定されたパスから設定ファイルを読み込み、Config構造体にパースします。記述されていない項目はデフォルト値が使われます

type DatabaseConfig

type DatabaseConfig struct {
	Path                  string `yaml:"path"`
	MaxDeferredRetryCount int    `yaml:"max_deferred_retry_count"`
}

type Document

type Document struct {
	URL  string
	Size int64 // バイト単位
}

Document はHTMLドキュメント内に添付されているドキュメントの情報を保持します。

type DocumentSummary

type DocumentSummary struct {
	Summary   string   `json:"summary"`
	Metadata  string   `json:"metadata"`
	KeyPoints []string `json:"keyPoints"`
}

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

type HTMLandDocuments struct {
	HTMLContent []byte
	Documents   []Document
}

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) AddItems

func (r *ItemRepository) AddItems(ctx context.Context, items []*gofeed.Item) (int, error)

AddItems は新しいRSSアイテムをデータベースに追加します。 URLが既存のレコードと重複する場合、新規追加は行いません。

func (*ItemRepository) Close

func (r *ItemRepository) Close() error

Close はデータベース接続を閉じます。

func (*ItemRepository) CountUnprocessedItems

func (r *ItemRepository) CountUnprocessedItems(ctx context.Context) (int, error)

func (*ItemRepository) GetItemByURL

func (r *ItemRepository) GetItemByURL(ctx context.Context, url string) (*Item, error)

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

func (r *ItemRepository) IsURLExists(ctx context.Context, url string) (bool, error)

IsURLExists

func (*ItemRepository) Update

func (r *ItemRepository) Update(ctx context.Context, item *Item) error

Update updates database content. It updates last_checked_at automatically

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 MastodonConfig struct {
	InstanceURL         string `yaml:"instance_url"`
	AccessToken         string `yaml:"access_token"`
	ClientID            string `yaml:"client_id"`
	ClientSecret        string `yaml:"client_secret"`
	PostTemplate        string `yaml:"post_template"`
	NoValuePostTemplate string `yaml:"no_value_post_template"`
}

type PostInfo

type PostInfo struct {
	Title   string
	Summary string
	URL     string
}

type RSSClient

type RSSClient struct {
	// contains filtered or unexported fields
}

RSSClient はRSSフィードの取得とパースを行うクライアント

func NewRSSClient

func NewRSSClient() *RSSClient

NewRSSClient は新しいRSSClientインスタンスを作成します。

func (*RSSClient) FetchFeed

func (c *RSSClient) FetchFeed(ctx context.Context, url string) ([]*gofeed.Item, error)

FetchFeed は指定されたURLからRSSフィードを取得し、パースします。

type RSSConfig

type RSSConfig struct {
	URL string `yaml:"url"`
}

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 StorageConfig struct {
	DownloadDir   string `yaml:"download_dir"`
	KeepLocalCopy bool   `yaml:"keep_local_copy"`
}

type SummarizeResult

type SummarizeResult struct {
	Documents    []DocumentSummary `json:"documents"`
	Omissibles   []string          `json:"omissibles"`
	FinalSummary string            `json:"final_summary"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL