98 lines
3.2 KiB
Go
98 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
type Article struct {
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Link string `json:"link"`
|
|
Published time.Time `json:"published"` // When we first saw the article
|
|
OriginalDate time.Time `json:"originalDate"` // Original publication date from the feed
|
|
Source string `json:"source"`
|
|
FirstSeen time.Time `json:"firstseen"`
|
|
Seen time.Time `json:"seen"`
|
|
Summary string `json:"summary"`
|
|
Importance int `json:"importance"`
|
|
ID string `json:"id"`
|
|
BroadcastTime time.Time `json:"broadcastTime,omitempty"`
|
|
}
|
|
|
|
type LogEntry struct {
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Event string `json:"event"`
|
|
Details map[string]interface{} `json:"details"`
|
|
}
|
|
|
|
// LogRingBuffer holds the most recent log entries in a circular buffer
|
|
type LogRingBuffer struct {
|
|
entries []LogEntry
|
|
size int
|
|
position int
|
|
count int
|
|
mutex sync.Mutex
|
|
}
|
|
|
|
// Data structure for web UI
|
|
type DashboardData struct {
|
|
LastUpdated string
|
|
TotalArticles int
|
|
TotalBroadcast int
|
|
NewInLastHour int
|
|
UnsummarizedCount int
|
|
NextUp []Article
|
|
History []Article
|
|
RecentLogs []LogEntry
|
|
}
|
|
|
|
const (
|
|
dbPath = "articles.db"
|
|
|
|
// LLM prompts
|
|
ARTICLES_PROMPT = `Summarize each of these news items in under 165
|
|
characters, optimizing for information density (common news headline
|
|
abbreviations OK) and rate their importance from 1 to 100.
|
|
|
|
100 means most important; 1 means least important.
|
|
|
|
Never rate over 90 unless it is a massive event such as: war outbreak,
|
|
revolution, death of a head of state, large-scale natural disaster, mass
|
|
casualty terrorism, etc.
|
|
|
|
IMPORTANT: Rank any headlines primarily promoting commercial products or
|
|
services as 1 (lowest importance).
|
|
|
|
Rank any article with a headline that poses a question without providing an
|
|
answer (as an attempt to lure a reader into clicking a link) as 1 (lowest
|
|
importance).
|
|
|
|
IMPORTANT: Boost the importance score by 10-20 points for breaking news that is less
|
|
than 60 minutes old based on its original publication date (which is provided for each article).
|
|
This helps ensure timely distribution of very recent news.
|
|
|
|
For each article, return a JSON object with "id", "summary", and "importance"
|
|
fields. Return your response as a JSON array of objects like: [{"id":
|
|
"article_id", "summary": "...", "importance": 42}, ...]
|
|
|
|
Here are the articles:
|
|
`
|
|
|
|
SYSTEM_PROMPT = "You are a news analyst."
|
|
BATCH_SIZE = 10
|
|
MAX_INDIVIDUAL_PROCESSING = 50
|
|
|
|
// Timing constants
|
|
RSS_CHECK_INTERVAL = 15 * time.Minute
|
|
SUMMARIZE_INTERVAL = 10 * time.Second
|
|
BROADCAST_INTERVAL = 1 * time.Hour
|
|
STARTUP_DELAY = 60 * time.Second // Delay before first broadcast
|
|
BROADCAST_PREPARATION_DELAY = 30 * time.Second // Delay before executing broadcast command
|
|
ARTICLE_FRESHNESS_WINDOW = 24 * time.Hour // Time window for considering articles fresh
|
|
|
|
// Other constants
|
|
MAX_MESSAGE_LENGTH = 200 // Maximum length of broadcast messages in characters
|
|
MAX_LOG_ENTRIES = 1000 // Maximum number of log entries to keep in memory
|
|
)
|