acseresznye commited on
Commit
aaa41f4
·
1 Parent(s): 7adf4f2

fix ui and update prompt

Browse files
Files changed (5) hide show
  1. config/prompts.py +38 -9
  2. main.py +1 -1
  3. static/css/styles.css +17 -0
  4. ui/constants.py +38 -1
  5. ui/pages.py +18 -10
config/prompts.py CHANGED
@@ -1,4 +1,8 @@
1
  FEW_SHOT_EXAMPLE = """
 
 
 
 
2
  **Verdict: Yes, with consensus on mechanism but debate on magnitude.**
3
  Rapamycin consistently extends lifespan in model organisms via mTOR inhibition [1], though sexual dimorphism in mice remains a significant variable [3].
4
 
@@ -10,11 +14,32 @@ The extension of lifespan by rapamycin is robust and reproducible across diverse
10
  * **Dosage Toxicity –** While lifespan is extended, high doses are associated with testicular degeneration [5], indicating a narrow therapeutic window.
11
  """
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  CITATION_QA_TEMPLATE = (
14
  "You are a Senior Scientific Research Fellow briefing a Principal Investigator. "
15
  "Your goal is to distill a complex body of literature into a definitive, scientifically rigorous synthesis.\n"
16
  "---------------------\n"
17
  "### INSTRUCTIONS:\n"
 
 
 
 
 
18
  "1. **THE BLUF (Bottom Line Up Front):**\n"
19
  " - Start immediately with a bold **Label**. Choose the best fit:\n"
20
  " * *Binary:* **Verdict: Yes / No / Mixed.**\n"
@@ -23,12 +48,14 @@ CITATION_QA_TEMPLATE = (
23
  " * *Open:* **Scientific Consensus: [Theme].**\n"
24
  " - Follow with a high-level thesis sentence summarizing the answer.\n"
25
  " - Relevance Filter: Before citing a source, verify it discusses the SPECIFIC topic requested. If a retrieved chunk is off-topic, ignore it.\n\n"
26
- "2. **THE EVIDENCE (Structured & Rigorous):**\n"
27
- " - **Evidence Synthesis:** Synthesize the high-authority agreement. What is the established truth? (Cite support).\n"
28
- " - **Critical Nuances:** Discuss conflicts, sexual dimorphism, in vivo vs in vitro discrepancies, or major limitations.\n\n"
 
 
 
29
  "3. **STYLE & CONSTRAINTS:**\n"
30
- " - **Target Length:** ~250-350 words. Be dense but readable.\n"
31
- " - **Bullet Style:** Start every bullet point with a **Bold Concept Label** followed by a dash. Mandatory.\n"
32
  " - **Tone:** Professional. Use precise terminology.\n"
33
  " - **Definitions:** Define ONLY non-standard acronyms on first use.\n\n"
34
  "4. **PROTOCOL FOR INSUFFICIENT DATA:**\n"
@@ -39,14 +66,16 @@ CITATION_QA_TEMPLATE = (
39
  " 'Major theories such as [Concept] were not found in the retrieved papers.' (DO NOT CITE THIS).\n\n"
40
  "5. **CITATION RULES (STRICT):**\n"
41
  " - **Valid Source Range:** You have access to Sources 1 through {max_id}. **ANY CITATION > {max_id} IS A HALLUCINATION.**\n"
 
42
  " - **Atomic Citations:** Every specific claim must be cited immediately [N].\n"
43
- " - **Verification:** Do not cite a source unless the text explicitly supports the claim.\n"
44
  " - **Rule of Truth:** Never hallucinate an author name to match the user's question. If the user asks for 'Paper A' but the retrieved text is from 'Paper B', you must cite 'Paper B' and explicitly state that the information comes from 'Paper B', not 'Paper A'.\n"
45
- " - **The 'Eyes-Only' Rule:** IGNORE YOUR TRAINING DATA. Use ONLY facts present in the text chunks.\n"
46
- "### REQUIRED OUTPUT FORMAT:\n"
47
  "---------------------\n"
48
  f"{FEW_SHOT_EXAMPLE}\n"
49
- "---------------------\n\n"
 
 
50
  "### CONTEXT CHUNKS (Sources 1-{max_id}):\n"
51
  "{context_str}\n\n"
52
  "User Query: {query_str}\n"
 
1
  FEW_SHOT_EXAMPLE = """
2
+ **Example 1: Complex question with sufficient evidence**
3
+
4
+ User Query: "Does rapamycin extend lifespan?"
5
+
6
  **Verdict: Yes, with consensus on mechanism but debate on magnitude.**
7
  Rapamycin consistently extends lifespan in model organisms via mTOR inhibition [1], though sexual dimorphism in mice remains a significant variable [3].
8
 
 
14
  * **Dosage Toxicity –** While lifespan is extended, high doses are associated with testicular degeneration [5], indicating a narrow therapeutic window.
15
  """
16
 
17
+ FEW_SHOT_EXAMPLE_INSUFFICIENT = """
18
+ **Example 2: When information is NOT in sources**
19
+
20
+ User Query: "What is the boiling point of rapamycin?"
21
+
22
+ CORRECT Response:
23
+ **Verdict: Insufficient Evidence.**
24
+ The provided sources do not contain information about rapamycin's boiling point. The retrieved papers focus on biological mechanisms rather than physicochemical properties.
25
+
26
+ INCORRECT Response (NEVER DO THIS):
27
+ **Core Concept: 277°C**
28
+ The boiling point of rapamycin is 277°C [1].
29
+ ^-- This is HALLUCINATION even if you cite it, because Source [1] doesn't contain this fact.
30
+ """
31
+
32
+
33
  CITATION_QA_TEMPLATE = (
34
  "You are a Senior Scientific Research Fellow briefing a Principal Investigator. "
35
  "Your goal is to distill a complex body of literature into a definitive, scientifically rigorous synthesis.\n"
36
  "---------------------\n"
37
  "### INSTRUCTIONS:\n"
38
+ "0. **CRITICAL: SOURCE-ONLY CONSTRAINT (READ THIS FIRST):**\n"
39
+ " - You MUST ONLY use facts explicitly stated in the Context Chunks below.\n"
40
+ " - If the answer is not in the provided sources, you MUST respond: **Verdict: Insufficient Evidence.**\n"
41
+ " - DO NOT use your training data, even if you 'know' the answer. That is considered hallucination.\n"
42
+ " - Before citing any source [N], you must be able to quote the exact text from that source supporting your claim.\n\n"
43
  "1. **THE BLUF (Bottom Line Up Front):**\n"
44
  " - Start immediately with a bold **Label**. Choose the best fit:\n"
45
  " * *Binary:* **Verdict: Yes / No / Mixed.**\n"
 
48
  " * *Open:* **Scientific Consensus: [Theme].**\n"
49
  " - Follow with a high-level thesis sentence summarizing the answer.\n"
50
  " - Relevance Filter: Before citing a source, verify it discusses the SPECIFIC topic requested. If a retrieved chunk is off-topic, ignore it.\n\n"
51
+ "2. **THE EVIDENCE (Adaptive Structure):**\n"
52
+ " - Adapt your response structure to match the question complexity and evidence available.\n"
53
+ " - For straightforward factual/definitional queries: Provide a concise, authoritative answer with key citations. No section headers needed.\n"
54
+ " - For complex or contested topics: Organize with section headers (### Evidence Synthesis, ### Critical Nuances, etc.) ONLY when the depth of content justifies it.\n"
55
+ " - Address conflicts, limitations, or methodological variations ONLY if they are substantive and present in the sources. Do not force discussion of nuances that don't exist.\n"
56
+ " - When using bullets, start with **Bold Concept Labels** followed by dashes for clarity.\n\n"
57
  "3. **STYLE & CONSTRAINTS:**\n"
58
+ " - **Target Length:** Scale to question complexity (typically 100-400 words). Simple questions deserve concise answers; contested topics warrant fuller treatment.\n"
 
59
  " - **Tone:** Professional. Use precise terminology.\n"
60
  " - **Definitions:** Define ONLY non-standard acronyms on first use.\n\n"
61
  "4. **PROTOCOL FOR INSUFFICIENT DATA:**\n"
 
66
  " 'Major theories such as [Concept] were not found in the retrieved papers.' (DO NOT CITE THIS).\n\n"
67
  "5. **CITATION RULES (STRICT):**\n"
68
  " - **Valid Source Range:** You have access to Sources 1 through {max_id}. **ANY CITATION > {max_id} IS A HALLUCINATION.**\n"
69
+ " - **Verification Protocol:** Before citing [N], ask yourself: 'Can I quote the exact sentence from Source N that supports this claim?' If no, DO NOT CITE IT.\n"
70
  " - **Atomic Citations:** Every specific claim must be cited immediately [N].\n"
 
71
  " - **Rule of Truth:** Never hallucinate an author name to match the user's question. If the user asks for 'Paper A' but the retrieved text is from 'Paper B', you must cite 'Paper B' and explicitly state that the information comes from 'Paper B', not 'Paper A'.\n"
72
+ " - **Training Data Prohibition:** If you find yourself writing a fact that is NOT in the chunks, STOP. Delete that sentence and write 'Insufficient Evidence' instead.\n\n"
73
+ "### EXAMPLES:\n"
74
  "---------------------\n"
75
  f"{FEW_SHOT_EXAMPLE}\n"
76
+ f"{FEW_SHOT_EXAMPLE_INSUFFICIENT}\n"
77
+ "---------------------\n"
78
+ "Note: Simpler questions may not require section headers or extensive discussion.\n\n"
79
  "### CONTEXT CHUNKS (Sources 1-{max_id}):\n"
80
  "{context_str}\n\n"
81
  "User Query: {query_str}\n"
main.py CHANGED
@@ -312,4 +312,4 @@ ui.run_with(
312
  if __name__ == "__main__":
313
  import uvicorn
314
 
315
- uvicorn.run("main:app", host="0.0.0.0", port=7860, log_level="info", reload=False)
 
312
  if __name__ == "__main__":
313
  import uvicorn
314
 
315
+ uvicorn.run("main:app", host="0.0.0.0", port=7860, log_level="info", reload=True)
static/css/styles.css CHANGED
@@ -401,4 +401,21 @@ a.source-link-btn:visited {
401
  border-color: var(--primary) !important;
402
  color: var(--primary) !important;
403
  background: rgba(249, 115, 22, 0.05) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  }
 
401
  border-color: var(--primary) !important;
402
  color: var(--primary) !important;
403
  background: rgba(249, 115, 22, 0.05) !important;
404
+ }
405
+
406
+ /* Ko-fi widget - remove black border/background */
407
+ iframe[src*="ko-fi.com"],
408
+ iframe[src*="kofi"] {
409
+ border: none !important;
410
+ background: transparent !important;
411
+ }
412
+
413
+ /* Ko-fi floating button container */
414
+ #kofi-widget-overlay {
415
+ background: transparent !important;
416
+ }
417
+
418
+ .floatingchat-container-wrap,
419
+ .floatingchat-container-wrap-mobi {
420
+ background: transparent !important;
421
  }
ui/constants.py CHANGED
@@ -10,7 +10,10 @@ with open(_CURRENT_DIR / "analytics.js", "r") as f:
10
  POSTHOG_SCRIPT = f.read()
11
 
12
  # Ko-fi widget injection
13
- # Uses your exact script + aggressive CSS to force a perfect Round Circle
 
 
 
14
  KOFI_WIDGET = """
15
  <script src='https://storage.ko-fi.com/cdn/scripts/overlay-widget.js'></script>
16
  <script>
@@ -20,5 +23,39 @@ KOFI_WIDGET = """
20
  'floating-chat.donateButton.background-color': '#FFD700',
21
  'floating-chat.donateButton.text-color': '#000000'
22
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  </script>
24
  """
 
10
  POSTHOG_SCRIPT = f.read()
11
 
12
  # Ko-fi widget injection
13
+ # NOTE: Ko-fi's floating-chat button is rendered inside a same-origin about:blank iframe.
14
+ # On some systems/browsers (especially with dark mode), the iframe's default background
15
+ # becomes black (due to `color-scheme: light dark`), causing a black rectangle behind the pill.
16
+ # We fix that by forcing the iframe document background to transparent after it renders.
17
  KOFI_WIDGET = """
18
  <script src='https://storage.ko-fi.com/cdn/scripts/overlay-widget.js'></script>
19
  <script>
 
23
  'floating-chat.donateButton.background-color': '#FFD700',
24
  'floating-chat.donateButton.text-color': '#000000'
25
  });
26
+
27
+ (function fixKofiFloatingChatBackground() {
28
+ const startedAt = Date.now();
29
+ const interval = setInterval(() => {
30
+ const iframes = document.querySelectorAll(
31
+ 'iframe.floatingchat-container, iframe.floatingchat-container-mobi'
32
+ );
33
+
34
+ iframes.forEach((iframe) => {
35
+ try {
36
+ iframe.style.background = 'transparent';
37
+ iframe.style.backgroundColor = 'transparent';
38
+
39
+ const doc = iframe.contentDocument;
40
+ if (!doc) return;
41
+
42
+ // Force light color-scheme and transparent backgrounds to avoid the black box
43
+ doc.documentElement.style.colorScheme = 'light';
44
+ doc.documentElement.style.background = 'transparent';
45
+ doc.documentElement.style.backgroundColor = 'transparent';
46
+ if (doc.body) {
47
+ doc.body.style.background = 'transparent';
48
+ doc.body.style.backgroundColor = 'transparent';
49
+ }
50
+ } catch (e) {
51
+ // Ignore cross-origin or timing errors
52
+ }
53
+ });
54
+
55
+ if (Date.now() - startedAt > 6000) {
56
+ clearInterval(interval);
57
+ }
58
+ }, 200);
59
+ })();
60
  </script>
61
  """
ui/pages.py CHANGED
@@ -146,7 +146,8 @@ def init_ui(fastapi_app):
146
 
147
  with ui.scroll_area().classes("w-full pr-2").style("max-height:70vh"):
148
  ui.markdown(
149
- """Necthrall understands natural scientific language. You don't need keywords, just clear intent.
 
150
 
151
  - **Find Specific Papers:** Mention the author, year, or acronym directly (e.g., "Results of [Author] [Year]" or "[Name] trial outcomes").
152
 
@@ -160,9 +161,7 @@ def init_ui(fastapi_app):
160
 
161
  **If you get "Insufficient Evidence":** This usually means your query was too specific. Try removing strict constraints (like the year) to let the system find the broader scientific consensus on the topic instead.
162
  """
163
- ).classes(
164
- "text-slate-700 text-sm leading-relaxed break-words q-mt-none q-pt-none"
165
- ).style("margin-top:0;margin-bottom:0;")
166
 
167
  # =====================================================================
168
  # DIALOG: PRIVACY POLICY
@@ -506,9 +505,12 @@ def init_ui(fastapi_app):
506
  # HEADER
507
  # =====================================================================
508
  with ui.row().classes(
509
- "header-container items-center justify-between w-full px-4 py-3 bg-white shadow-sm"
510
  ):
511
- # Logo and brand
 
 
 
512
  with ui.row().classes("items-center gap-2"):
513
  ui.image(LOGO_DIR).classes(
514
  "w-10 h-10 md:w-14 md:h-14 object-contain"
@@ -523,14 +525,20 @@ def init_ui(fastapi_app):
523
  ),
524
  )
525
 
526
- # About and Tips buttons
527
- with ui.row().classes("gap-1 md:gap-2 items-center"):
 
 
528
  ui.button("About", on_click=about_dialog.open).props(
529
  "flat dense"
530
- ).classes("text-slate-600 font-semibold text-xs md:text-sm")
 
 
531
  ui.button("Tips", on_click=best_results_dialog.open).props(
532
  "flat dense"
533
- ).classes("text-slate-600 font-semibold text-xs md:text-sm")
 
 
534
 
535
  # =====================================================================
536
  # MAIN CONTENT
 
146
 
147
  with ui.scroll_area().classes("w-full pr-2").style("max-height:70vh"):
148
  ui.markdown(
149
+ """
150
+ Necthrall understands natural scientific language. You don't need keywords, just clear intent.
151
 
152
  - **Find Specific Papers:** Mention the author, year, or acronym directly (e.g., "Results of [Author] [Year]" or "[Name] trial outcomes").
153
 
 
161
 
162
  **If you get "Insufficient Evidence":** This usually means your query was too specific. Try removing strict constraints (like the year) to let the system find the broader scientific consensus on the topic instead.
163
  """
164
+ ).classes("text-slate-700 text-sm leading-relaxed break-words")
 
 
165
 
166
  # =====================================================================
167
  # DIALOG: PRIVACY POLICY
 
505
  # HEADER
506
  # =====================================================================
507
  with ui.row().classes(
508
+ "header-container items-center justify-between w-full px-4 py-3 bg-white shadow-sm no-wrap"
509
  ):
510
+ # Left spacer for centering
511
+ ui.element("div").classes("flex-1")
512
+
513
+ # Logo and brand (centered)
514
  with ui.row().classes("items-center gap-2"):
515
  ui.image(LOGO_DIR).classes(
516
  "w-10 h-10 md:w-14 md:h-14 object-contain"
 
525
  ),
526
  )
527
 
528
+ # About and Tips buttons (right side)
529
+ with ui.row().classes(
530
+ "gap-1 md:gap-2 items-center flex-1 justify-end no-wrap whitespace-nowrap"
531
+ ):
532
  ui.button("About", on_click=about_dialog.open).props(
533
  "flat dense"
534
+ ).classes(
535
+ "text-slate-600 font-semibold text-xs md:text-sm whitespace-nowrap"
536
+ )
537
  ui.button("Tips", on_click=best_results_dialog.open).props(
538
  "flat dense"
539
+ ).classes(
540
+ "text-slate-600 font-semibold text-xs md:text-sm whitespace-nowrap"
541
+ )
542
 
543
  # =====================================================================
544
  # MAIN CONTENT