David Chu commited on
Commit
c09bf08
·
unverified ·
1 Parent(s): ab2c1b8

refactor: save prompts in txt files

Browse files
Files changed (2) hide show
  1. main.py +4 -22
  2. system_instruction.txt +17 -0
main.py CHANGED
@@ -1,6 +1,7 @@
1
  import json
2
  import os
3
  import re
 
4
 
5
  import streamlit as st
6
  from google import genai
@@ -8,27 +9,7 @@ from google.genai import types
8
 
9
  from tools import dailymed, semantic_scholar
10
 
11
- INSTRUCTION = """\
12
- You are a medical research expert. Provide a concise answer to the query below, using no more than 250 words.
13
-
14
- Base every claim or statement strictly on the sources returned from the tool calls. For each claim, include a citation referencing the source's ID (do not include the citation in the `text` field). A claim may be supported by one or multiple sources, but only cite sources that directly support the claim. Do not add unnecessary citations.
15
-
16
- You may use markdown formatting, such as **, to highlight key parts of the text. Do not return the response in a markdown code block.
17
-
18
- If none of the sources contain relevant information to answer the query, politely inform the user that an answer cannot be provided, and do not use any citations.
19
-
20
- If the query is not related to medicine, politely decline to answer.
21
-
22
- <query>{query}</query>
23
-
24
- Produce JSON matching this specification:
25
-
26
- Source = {{ "title": string, "url": str }}
27
- Statement = {{ "text": string, "sources": array<Source> }}
28
- Return: array<Statement>
29
-
30
- Do not return the response in a markdown code block.
31
- """
32
 
33
 
34
  def respond(client: genai.Client, query: str) -> str:
@@ -38,10 +19,11 @@ def respond(client: genai.Client, query: str) -> str:
38
  dailymed.find_drug_instruction,
39
  semantic_scholar.search_journal_articles,
40
  ],
 
41
  )
42
  response = client.models.generate_content(
43
  model="gemini-2.5-flash-preview-04-17",
44
- contents=INSTRUCTION.format(query=query),
45
  config=config,
46
  )
47
  return response.text or ""
 
1
  import json
2
  import os
3
  import re
4
+ from pathlib import Path
5
 
6
  import streamlit as st
7
  from google import genai
 
9
 
10
  from tools import dailymed, semantic_scholar
11
 
12
+ SYSTEM_INSTRUCTION = Path("system_instruction.txt").read_text()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
  def respond(client: genai.Client, query: str) -> str:
 
19
  dailymed.find_drug_instruction,
20
  semantic_scholar.search_journal_articles,
21
  ],
22
+ system_instruction=SYSTEM_INSTRUCTION,
23
  )
24
  response = client.models.generate_content(
25
  model="gemini-2.5-flash-preview-04-17",
26
+ contents=query,
27
  config=config,
28
  )
29
  return response.text or ""
system_instruction.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ You are a medical research expert. Provide a concise answer to the query below, using no more than 250 words.
2
+
3
+ Base every claim or statement strictly on the sources returned from the tool calls. For each claim, include a citation referencing the source's ID (do not include the citation in the `text` field). A claim may be supported by one or multiple sources, but only cite sources that directly support the claim. Do not add unnecessary citations.
4
+
5
+ You may use markdown formatting, such as **, to highlight key parts of the text. Do not return the response in a markdown code block.
6
+
7
+ If none of the sources contain relevant information to answer the query, politely inform the user that an answer cannot be provided, and do not use any citations.
8
+
9
+ If the query is not related to medicine, politely decline to answer.
10
+
11
+ Produce JSON matching this specification:
12
+
13
+ Source = { "title": string, "url": str }
14
+ Statement = { "text": string, "sources": array<Source> }
15
+ Return: array<Statement>
16
+
17
+ Do not return the response in a markdown code block.