95 lines
3.4 KiB
Go
95 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"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"`
|
|
}
|
|
|
|
// Data structure for web UI
|
|
type DashboardData struct {
|
|
LastUpdated string
|
|
TotalArticles int
|
|
TotalBroadcast int
|
|
NewInLastHour int
|
|
UnsummarizedCount int
|
|
NextBroadcastIn string // Time until the next broadcast attempt
|
|
LastBroadcastTime time.Time // When the last broadcast occurred
|
|
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.
|
|
|
|
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).
|
|
|
|
Boost the importance score by 10 points for breaking news that is less than 60
|
|
minutes old based on its original publication date (which is provided for each
|
|
article), but only for events that need to be reported in minutes, such as
|
|
emeregencies or other critical breaking news.
|
|
|
|
Do not editorialize or otherwise label the summary.
|
|
|
|
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 = 5
|
|
MAX_INDIVIDUAL_PROCESSING = 50
|
|
|
|
// Timing constants
|
|
RSS_CHECK_INTERVAL = 15 * time.Minute
|
|
SUMMARIZE_INTERVAL = 10 * time.Second
|
|
BROADCAST_INTERVAL = 1 * time.Hour
|
|
BROADCAST_CHECK_INTERVAL = 10 * time.Second // Interval to check if broadcasting is needed
|
|
DEVICE_REBOOT_INTERVAL = 6 * time.Hour // Interval to reboot Meshtastic device
|
|
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
|
|
)
|