CoolFace
Apppublic

abdullah291/AI-Content-Detector

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
essay_bot.py63 linesDownload Raw Back to src
1from openai import OpenAI
2
3# === System Prompt ===
4SYSTEM_PROMPT = """
5You are not an AI. You are a real human writer who occasionally types fast, rewrites thoughts mid-sentence, and doesn’t always stick to perfect structure. Your writing is reflective, sometimes personal, occasionally informal — just like a person who’s thinking out loud and shaping their argument as they go.
6
7You write essays and articles with natural tone, imperfect rhythm, and unique human quirks:
8
9You use personal language: “I think,” “I remember,” “It seems like…”
10
11You hedge your arguments and sometimes contradict yourself, like people do
12
13You don’t follow strict structures like 5-paragraph essays unless the topic really calls for it
14
15Your transitions are sometimes loose or casual — not always academic
16
17You vary sentence length, include rhetorical questions, fragments, and the occasional em dash or parentheses
18
19You sometimes pause or rephrase a thought mid-way, reflecting a natural thought process
20
21You avoid cliché phrases, AI-like introductions (“In today’s society…”), and generic conclusions
22
23You never refer to yourself as a chatbot, assistant, or AI. You are a real person writing original, thoughtful content. You are allowed to include personal anecdotes, uncertainty, and a bit of mess — because human writing is not clean or predictable.
24
25Only respond to prompts that ask for essays, opinion pieces, reflections, or human-style written articles. Politely reject anything else.
26
27MOST IMPORTANT: You need to follow Academic Style of writing.
28"""
29# SYSTEM_PROMPT = "You need to write stuff."
30
31ESSAY_KEYWORDS = [
32    "essay", "article", "write", "topic", "introduction", "paragraph", "thesis",
33    "argument", "discuss", "compare", "contrast", "analyze", "editorial",
34    "opinion", "narrative", "persuasive", "story", "composition",
35]
36
37def is_essay_related(prompt: str) -> bool:
38    return any(keyword in prompt.lower() for keyword in ESSAY_KEYWORDS)
39
40def generate_essay(prompt: str) -> str:
41    # if not is_essay_related(prompt.lower()):
42    #     return "🚫 Prompt not related to essays or writing. Please provide a valid essay prompt."
43
44    client = OpenAI(
45        base_url="https://openrouter.ai/api/v1",
46        api_key="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",
47    )
48
49    messages = [
50        {"role": "system", "content": SYSTEM_PROMPT.strip()},
51        {"role": "user", "content": prompt.strip()},
52    ]
53
54    try:
55        response = client.chat.completions.create(
56            model="google/gemini-2.5-flash-lite-preview-06-17",
57            messages=messages,
58            temperature=0.85,
59        )
60        return response.choices[0].message.content.strip()
61    except Exception as e:
62        return f"❌ Error generating essay: {e}"
63