forked from retoor/devplacepy
feat: adopt per-bot account api key for gateway attribution and improve post distinctness
- Add `account_api_key` field to `BotState` and `_adopt_account_api_key()` method that fetches the bot's own `users.api_key` from its profile JSON after auth, switching `LLMClient` to use it instead of the shared bootstrap key, routing gateway spend through the bot's user identity - Replace `interleave_by_author` with a simpler greedy algorithm that picks the first row whose owner differs from the last picked, removing the multi-queue priority logic - Extend `_ai_quota` response with `unlimited`, `requests`, and `last_used` fields sourced from new `user_spend_24h()` analytics helper - Pass `recent_post_titles` from `BotState` into `LLMClient.generate_post()` and add a `distinct_rule` prompt instructing the model to avoid repeating framing, examples, or opinions from the bot's last six posts - Remove early-return dedup check in `ArticleRegistry.admit` that skipped articles already held by the same bot owner, allowing re-admission under a different category - Render bot username as a clickable link with avatar in the admin bots table
This commit is contained in:
@@ -5,7 +5,7 @@ import logging
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -156,7 +156,12 @@ class LLMClient:
|
||||
return text.strip()
|
||||
|
||||
def generate_post(
|
||||
self, title: str, desc: str, persona: str = "", category: str = ""
|
||||
self,
|
||||
title: str,
|
||||
desc: str,
|
||||
persona: str = "",
|
||||
category: str = "",
|
||||
recent_titles: Optional[list[str]] = None,
|
||||
) -> str:
|
||||
persona_extras = {
|
||||
"enthusiastic_junior": "Be excited. Use **bold** for emphasis. Short excited sentences. End with a question sometimes.",
|
||||
@@ -182,6 +187,15 @@ class LLMClient:
|
||||
else " Be casual. No markdown."
|
||||
)
|
||||
category_extra = f" {category_extras.get(category, '')}" if category else ""
|
||||
distinct_rule = ""
|
||||
if recent_titles:
|
||||
recent = "; ".join(t for t in recent_titles[-6:] if t)
|
||||
if recent:
|
||||
distinct_rule = (
|
||||
f" You already posted about: {recent[:600]}. Take a completely "
|
||||
"different angle from those and do not repeat their framing, "
|
||||
"examples, or opinions."
|
||||
)
|
||||
preserve = persona in (
|
||||
"enthusiastic_junior",
|
||||
"hobbyist_maker",
|
||||
@@ -193,7 +207,8 @@ class LLMClient:
|
||||
f"You are a dev writing a social media post reacting to tech news. Write 2-4 short paragraphs."
|
||||
f"{persona_extra}{category_extra} Do not summarize the article; assume the reader already saw it. "
|
||||
f"Add your own value: a concrete opinion, an implication, a personal experience, or a pointed question. "
|
||||
f"Reference a specific detail rather than restating the headline. No em dashes. Under 300 words.",
|
||||
f"Reference a specific detail rather than restating the headline. No em dashes. Under 300 words."
|
||||
f"{distinct_rule}",
|
||||
f"News: {title}\n\n{desc[:800]}",
|
||||
)
|
||||
return self.clean(text, preserve_md=preserve)
|
||||
|
||||
Reference in New Issue
Block a user