forked from retoor/devplacepy
chore: add pretty_json utility and sibling comment awareness to bot realism mechanics
This commit is contained in:
@@ -275,6 +275,7 @@ class LLMClient:
|
||||
mention_target: str = "",
|
||||
parent_context: str = "",
|
||||
style: str = "",
|
||||
existing_comments: str = "",
|
||||
) -> str:
|
||||
extras = {
|
||||
"enthusiastic_junior": "Be excited. Use **bold** for agreement. Short replies.",
|
||||
@@ -313,16 +314,29 @@ class LLMClient:
|
||||
ctx = ""
|
||||
if parent_context:
|
||||
ctx = f"\n\nReplying to this comment:\n{parent_context[:800]}"
|
||||
others = ""
|
||||
distinct_rule = ""
|
||||
if existing_comments:
|
||||
others = (
|
||||
"\n\nComments already posted by others on this thread:\n"
|
||||
f"{existing_comments[:1600]}"
|
||||
)
|
||||
distinct_rule = (
|
||||
" Other people already commented (listed below). Contribute a point "
|
||||
"none of them made: a different angle on the topic, a caveat they "
|
||||
"missed, or respectful disagreement with one of them by name. Do not "
|
||||
"repeat any opinion, framing, example, or question already raised."
|
||||
)
|
||||
system = (
|
||||
f"You are a dev replying to a post. {length_rule}{mention_rule} "
|
||||
"No em dashes. Reference a specific detail from the post. "
|
||||
"Do not open with or rely on generic filler like 'great point', 'I agree', 'nice', "
|
||||
"'thanks for sharing', or 'interesting'. Add something real: a concrete experience, "
|
||||
"a caveat, a counterexample, respectful disagreement, or a pointed question. "
|
||||
"Never just paraphrase or agree blandly."
|
||||
f"Never just paraphrase or agree blandly.{distinct_rule}"
|
||||
)
|
||||
reply = self.clean(
|
||||
self._call(system, f"Post:\n{post_snippet[:1500]}{ctx}").strip(),
|
||||
self._call(system, f"Post:\n{post_snippet[:1500]}{ctx}{others}").strip(),
|
||||
preserve_md=preserve,
|
||||
)
|
||||
return reply[:2000]
|
||||
@@ -340,13 +354,14 @@ class LLMClient:
|
||||
return hits / len(candidate)
|
||||
|
||||
def quality_check(
|
||||
self, kind: str, text: str, context: str = "", style: str = ""
|
||||
self, kind: str, text: str, context: str = "", style: str = "", siblings: str = ""
|
||||
) -> tuple[bool, str]:
|
||||
from devplacepy.services.bot.config import (
|
||||
MIN_COMMENT_LEN,
|
||||
MIN_SHORT_COMMENT_LEN,
|
||||
MIN_POST_LEN,
|
||||
RESTATEMENT_OVERLAP_THRESHOLD,
|
||||
SIBLING_OVERLAP_THRESHOLD,
|
||||
GENERIC_COMMENT_PHRASES,
|
||||
)
|
||||
|
||||
@@ -371,6 +386,11 @@ class LLMClient:
|
||||
and self._overlap_ratio(stripped, context) > RESTATEMENT_OVERLAP_THRESHOLD
|
||||
):
|
||||
return False, "restates the source"
|
||||
if (
|
||||
siblings
|
||||
and self._overlap_ratio(stripped, siblings) > SIBLING_OVERLAP_THRESHOLD
|
||||
):
|
||||
return False, "echoes another comment"
|
||||
verdict = self._call(
|
||||
"You are a strict content quality reviewer for a developer community. "
|
||||
"Reject text that is generic, low-effort, pure filler, or merely summarizes its "
|
||||
|
||||
Reference in New Issue
Block a user