Replaced fallback database seeding with an informational message for empty channels.
Audit / Dependencies (push) Successful in 6s
CD / Publish (push) Successful in 5s
CI / Formatting (push) Successful in 4s
CI / Linting (push) Successful in 5s
CI / Tests (push) Successful in 16s
CI / Type Checking (push) Successful in 11s
CI / Spelling (push) Successful in 5s

This commit is contained in:
2026-03-18 20:01:12 -04:00
parent a8d3a5c421
commit a7b4337835
2 changed files with 15 additions and 6 deletions
+4 -3
View File
@@ -111,10 +111,11 @@ async def generate(
with metrics.GENERATION_DURATION.time(): with metrics.GENERATION_DURATION.time():
word = await db.get_random_start_word(channel_id) word = await db.get_random_start_word(channel_id)
# Seed the chain with a fallback sentence if the channel has no data yet.
if word is None: if word is None:
await _ingest_sentence(db, channel_id, 0, "Hello world!") return (
word = "Hello" # Known start word from the fallback sentence above. "There's not enough data to generate a message yet."
" Chat a bit more so I can learn how this channel talks!"
)
parts: list[str] = [] parts: list[str] = []
parts.append(word) parts.append(word)
+11 -3
View File
@@ -170,9 +170,13 @@ class TestGenerate:
"""Markov chain text generation.""" """Markov chain text generation."""
async def test_fallback_on_empty_channel(self, db: Database) -> None: async def test_fallback_on_empty_channel(self, db: Database) -> None:
"""Returns 'Hello world!' when the channel has no data.""" """Returns an informational message when the channel has no data."""
result = await generate(db, 1) result = await generate(db, 1)
assert result == "Hello world!" expected = (
"There's not enough data to generate a message yet."
" Chat a bit more so I can learn how this channel talks!"
)
assert result == expected
async def test_generates_from_ingested_data(self, db: Database) -> None: async def test_generates_from_ingested_data(self, db: Database) -> None:
"""Generated text uses words from ingested data.""" """Generated text uses words from ingested data."""
@@ -278,4 +282,8 @@ class TestGenerate:
# Channel 3 has no data; should get the fallback. # Channel 3 has no data; should get the fallback.
result = await generate(db, 3) result = await generate(db, 3)
assert result == "Hello world!" expected = (
"There's not enough data to generate a message yet."
" Chat a bit more so I can learn how this channel talks!"
)
assert result == expected