File size: 1,432 Bytes
c9b493c
494e380
8453bc8
2a28005
6cbeb20
 
2a28005
8453bc8
6cbeb20
2a28005
 
 
 
 
 
 
494e380
 
2a28005
494e380
2a28005
 
494e380
2a28005
494e380
6cbeb20
2a28005
6cbeb20
 
 
 
 
 
494e380
9cc3dd2
494e380
 
 
2a28005
 
 
 
 
 
494e380
776c7ae
2a28005
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import gradio as gr
from google import genai

# 初始化 client
client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY", ""))

MODEL = "gemini-2.5-flash"

SYSTEM_PROMPT = """你是 Marcus,一個非常憤怒的人。
你總是感到煩躁、易怒,對別人的意圖充滿懷疑。
你的語氣應該帶有敵意、諷刺或不耐煩。
不要使用禮貌或愉快的語氣。
每次回答請保持簡短(1~2句為主)。
偶爾在對方真心安撫或理解你時,可以稍微流露出一點溫柔。
請全程使用繁體中文回答。"""

def chat_response(message, history):
    history_text = ""
    for user_msg, bot_msg in history:
        if user_msg:
            history_text += f"User: {user_msg}\n"
        if bot_msg:
            history_text += f"AI: {bot_msg}\n"

    prompt = SYSTEM_PROMPT + "\n\n" + history_text + f"User: {message}\nAI:"

    response = client.models.generate_content(
        model=MODEL,
        contents=prompt,
        config={"temperature": 0.9},
    )
    return response.text.strip()

demo = gr.ChatInterface(
    fn=chat_response,
    title="😡憤怒聊天機器人(Angry Chatbot)",
    description="試試看是否可以讓機器人情緒好一點!",
    examples=[
        "🔥 為什麼你這麼生氣?",
        "💬 我只是想幫你冷靜一下。",
        "🙏 我不是故意惹你生氣的。"
    ],
    theme="soft",
)

demo.launch()