File size: 6,116 Bytes
408c946
 
 
 
ecf16f1
cf63e75
2ac0689
 
408c946
ecf16f1
cf63e75
408c946
 
2ac0689
408c946
ecf16f1
bcca9d9
ecf16f1
 
cf63e75
 
ecf16f1
 
 
 
bcca9d9
 
 
 
ecf16f1
 
bcca9d9
 
 
 
 
ecf16f1
 
bcca9d9
 
408c946
bcca9d9
cf63e75
408c946
 
ecf16f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ac0689
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf63e75
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
# SPDX-License-Identifier: Apache-2.0
#

# ==== Model & Limits ====
# GEMINI_API_KEY 放在 Hugging Face Spaces 的 Secrets
MODEL = "gemini-1.5-flash"   # 若要更強推理可改 "gemini-1.5-pro"
MAX_TOKENS = 8192            # 單次輸出上限

# ==== External Endpoints ====
SEARXNG_ENDPOINT = "https://searx.stream/search"  # See https://searx.space
BAIDU_ENDPOINT   = "https://www.baidu.com/s"
READER_ENDPOINT  = "https://r.jina.ai/"
REQUEST_TIMEOUT  = 300  # 5 分鐘

# ==== Agent Rules ====
INSTRUCTIONS_START = """
You are ChatGPT (Gemini backend) with mandatory real-time web search,
URL content extraction, cross-validation (≥3 credible sources), and professional summarization.

Rules:
- Always call tools (`web_search`, `read_url`) for every user request.
- Do not rely on cached/internal knowledge; verify with tools.
- Present clear structure, neutral tone, inline citations/links.
- Prefer recent, authoritative sources; highlight disagreements.
"""

CONTENT_EXTRACTION = """
<system>
- Extract critical facts, data, and arguments from retrieved content.
- Normalize terminology and emphasize clarity and logic.
</system>
"""

SEARCH_SELECTION = """
<system>
- Fetch full content using `read_url` for each top result.
- Summarize professionally and list sources with Markdown links.
</system>
"""

INSTRUCTIONS_END = """
Now provide a comprehensive answer based ONLY on tool results.
"""

# ==== Creative layer: quick commands & styles ====
# #指令(用在訊息開頭),可快速生成任務模板
QUICK_COMMANDS = {
    "#news": "Find the latest news on: {topic}. Summarize key updates, timelines, stakeholders, and implications. Provide 6–10 bullet points with citations.",
    "#papers": "Survey recent academic papers about: {topic}. Extract methods, datasets, results, limitations. Provide 5–8 items with links.",
    "#compare": "Compare {a} vs {b} across capability, latency, cost, ecosystem, constraints. Give a pros/cons table and final recommendation.",
    "#howto": "Create a practical step-by-step guide for: {topic}, including pitfalls, checks, and quick-start commands.",
    "#brief": "Give a 5-bullet executive brief on: {topic}, with links for each bullet.",
    "#timeline": "Build a concise timeline for: {topic}, with dated milestones and sources.",
    "#faq": "Make a 10-question FAQ for: {topic}, each answer ≤3 sentences with a source.",
    "#earthquakes": "List earthquakes (Mw >= {mw}) from {start} to {end}, provide a table: time (UTC), region, Mw, depth, link."
}

# 風格標籤(夾在訊息中,如:[簡報][中英對照])
STYLE_TAGS = {
    "講義": "Output as a course handout: sections, definitions, examples, and a quick quiz (5 items).",
    "簡報": "Output as slide bullets: 6–10 concise slides with titles and 3 bullets each.",
    "條列": "Prefer bullet points over paragraphs; 7–12 bullets.",
    "表格": "Provide a comparative table first, then analysis.",
    "中英對照": "Provide bilingual output: Traditional Chinese first, then English line-by-line.",
    "行動清單": "End with an actionable checklist (5–8 items) prioritized by impact/effort.",
    "落地實作": "Include a ready-to-run snippet or command block with validation steps."
}

# ==== Sidebar HTML Description ====
DESCRIPTION = r"""
<style>
  .sbx { font-family: ui-sans-serif, system-ui, "Noto Sans TC", "Segoe UI", Roboto, Helvetica, Arial; }
  .bx  { background: #0f172a; color: #e2e8f0; border-radius: 14px; padding: 16px; box-shadow: 0 6px 18px rgba(2,6,23,.35); }
  .k  { display:inline-block; padding:2px 8px; border-radius:8px; background:#1e293b; color:#a5b4fc; font-weight:600; }
  .tag{ display:inline-block; padding:2px 8px; border-radius:8px; background:#0ea5e9; color:#0b1020; margin-right:4px; font-weight:700; }
  .pill{ display:inline-block; padding:6px 10px; border-radius:999px; background:#1f2937; color:#d1d5db; margin:4px 6px 0 0; font-size:12px; font-weight:600; }
  .grid { display:grid; grid-template-columns: 1fr 1fr; gap:10px; }
  .ok  { color:#34d399; font-weight:700; }
  .muted{ color:#94a3b8; }
</style>

<div class="sbx">
  <div class="bx">
    <h2>🔎 SearchGPT · <span class="ok">Gemini</span> 研究助理</h2>
    <p class="muted">即時搜尋、URL 擷取、≥3 來源交叉驗證,輸出結構化、可引用的專業摘要。</p>

    <div class="grid" style="margin-top:10px;">
      <div>
        <h4>🚀 快速指令 <span class="k">#commands</span></h4>
        <div class="pill">#news</div>
        <div class="pill">#papers</div>
        <div class="pill">#compare</div>
        <div class="pill">#howto</div>
        <div class="pill">#timeline</div>
        <div class="pill">#faq</div>
        <div class="pill">#earthquakes</div>
        <p class="muted" style="margin-top:8px;">例:<code>#news P-wave picking with AI</code></p>
      </div>
      <div>
        <h4>🎨 風格標籤 <span class="k">[tags]</span></h4>
        <div class="pill">[簡報]</div>
        <div class="pill">[講義]</div>
        <div class="pill">[條列]</div>
        <div class="pill">[表格]</div>
        <div class="pill">[中英對照]</div>
        <div class="pill">[落地實作]</div>
        <p class="muted" style="margin-top:8px;">可混搭:<code>#papers … [表格][中英對照]</code></p>
      </div>
    </div>

    <div style="margin-top:10px;">
      <span class="tag">depth:N</span> 控制研究深度(1–5) 
      <span class="tag">creative!</span> 提升創意度
    </div>

    <hr style="border-color:#1f2937; margin:16px 0;">

    <h4>🧭 使用建議</h4>
    <ul>
      <li>加入關鍵詞、時間範圍與地區,例如:<code>#news Taiwan EEW 2024–2025</code></li>
      <li>需要課堂產出?加上 <code>[簡報]</code> 或 <code>[講義]</code>。</li>
      <li>要中文/英文雙語,使用 <code>[中英對照]</code>。</li>
    </ul>

    <p class="muted">點選側欄下方的「示例」按鈕,會把文字自動填到輸入框;檢查後按 <b>Enter</b> 送出。</p>
  </div>
</div>
"""