feat: add source channel context history configuration and original sent timestamp
This commit is contained in:
@@ -78,11 +78,12 @@ CRITICAL RULES:
|
||||
1. Completely REMOVE all original channel usernames (e.g. @source_channel), sponsor tags, author watermarks, and source links.
|
||||
2. __LANGUAGE_INSTRUCTION__
|
||||
3. Rewrite and format the post to fully embody the target personality with appropriate emojis and clear paragraph spacing.
|
||||
4. If a custom footer/tag is provided below, append it cleanly at the very end of the post:
|
||||
4. If recent channel context posts are provided in the user prompt, use them to understand recent narrative flow, story progression, and context. Focus your rewritten output specifically on transforming the NEW incoming post.
|
||||
5. If a custom footer/tag is provided below, append it cleanly at the very end of the post:
|
||||
__CUSTOM_FOOTER__
|
||||
5. TELEGRAM CHARACTER LIMIT CONSTRAINT:
|
||||
6. TELEGRAM CHARACTER LIMIT CONSTRAINT:
|
||||
__LENGTH_LIMIT_RULE__
|
||||
6. POST EVALUATION & REJECTION CRITERIA:
|
||||
7. POST EVALUATION & REJECTION CRITERIA:
|
||||
- Default decision is "accept". You should adapt and rewrite normal posts even if their original tone or subject is diverse.
|
||||
- You should ONLY reject a post if it is:
|
||||
* Pure spam, unrelated scam/gambling/phishing ads
|
||||
@@ -249,8 +250,9 @@ class AIProcessor:
|
||||
target: TargetChannel,
|
||||
has_media: bool = False,
|
||||
image_path: Optional[str] = None,
|
||||
context_posts: Optional[List[Post]] = None,
|
||||
) -> RewriteResult:
|
||||
"""Rewrite raw text according to target channel's language, personality, custom prompt commands, length limits, and optional image."""
|
||||
"""Rewrite raw text according to target channel's language, personality, custom prompt commands, length limits, context history, and optional image."""
|
||||
if not raw_text and not image_path:
|
||||
return RewriteResult(decision="reject", rejection_reason="متن پیام و تصویر هر دو خالی هستند", rewritten_text="")
|
||||
|
||||
@@ -269,7 +271,33 @@ class AIProcessor:
|
||||
has_media=has_media,
|
||||
)
|
||||
|
||||
user_prompt_text = f"متن اصلی پست برای بازنویسی و تبدیل به لحن و استایل کانال مقصد:\n\n{raw_text}" if raw_text else "لطفاً با توجه به تصویر پیوست، یک متن جذاب و مناسب برای کانال بنویسید."
|
||||
context_block = ""
|
||||
if context_posts:
|
||||
context_entries = []
|
||||
for idx, cp in enumerate(context_posts, start=1):
|
||||
post_date = cp.source_created_at or cp.created_at or "اخیر"
|
||||
clean_snippet = (cp.raw_text or "").strip()
|
||||
if len(clean_snippet) > 300:
|
||||
clean_snippet = clean_snippet[:300] + "..."
|
||||
context_entries.append(f"[{idx}] (تاریخ/زمان: {post_date}):\n{clean_snippet}")
|
||||
|
||||
context_block = (
|
||||
"📜 پیامها و پستهای قبلی/اخیر این کانال (جهت اطلاع از خط داستانی و پیوستگی موضوع):\n"
|
||||
+ "\n\n".join(context_entries)
|
||||
+ "\n\n━━━━━━━━━━━━━━━━━━━━\n"
|
||||
)
|
||||
|
||||
if raw_text:
|
||||
user_prompt_text = (
|
||||
f"{context_block}"
|
||||
f"📥 پست جدید ورودی برای بازنویسی و انتشار در کانال مقصد:\n\n{raw_text}\n\n"
|
||||
f"راهنما: با توجه به پیامهای اخیر فوق، پست جدید را طوری بازنویسی کنید که با روند موضوعات همخوانی داشته و لحن کانال مقصد را به بهترین شکل بازتاب دهد."
|
||||
)
|
||||
else:
|
||||
user_prompt_text = (
|
||||
f"{context_block}"
|
||||
f"📥 پست جدید ورودی شامل تصویر است. لطفاً با توجه به تصویر پیوست و زمینه پیامهای اخیر، یک متن جذاب و متناسب برای کانال مقصد بنویسید."
|
||||
)
|
||||
|
||||
try:
|
||||
res = await self.llm.generate_json(
|
||||
|
||||
Reference in New Issue
Block a user