David Chu
commited on
refactor: improve footnote formatting
Browse files
main.py
CHANGED
@@ -9,13 +9,11 @@ from google.genai import types
|
|
9 |
from tools import dailymed, semantic_scholar
|
10 |
|
11 |
INSTRUCTION = """\
|
12 |
-
You are a medical research expert.
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
You can use markdown format, such as **, to highlight the key part of the answer. But do not return the response in a markdown code block.
|
19 |
|
20 |
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.
|
21 |
|
@@ -68,14 +66,21 @@ def format_output(response: str) -> tuple[str, str]:
|
|
68 |
answer = ""
|
69 |
citations = {}
|
70 |
for statement in statements:
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
for source in statement.get("sources", []):
|
73 |
source_str = f"[{source['title']}]({source['url']})"
|
74 |
if not (citation_id := citations.get(source_str)):
|
75 |
citation_id = len(citations) + 1
|
76 |
citations[source_str] = citation_id
|
77 |
-
|
78 |
-
|
|
|
79 |
except KeyError as err:
|
80 |
print(err)
|
81 |
return response, ""
|
@@ -87,7 +92,7 @@ def format_output(response: str) -> tuple[str, str]:
|
|
87 |
def main():
|
88 |
gemini_client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
|
89 |
|
90 |
-
st.title("
|
91 |
with st.form("search", border=False):
|
92 |
query = st.text_input("Your medical question")
|
93 |
submit = st.form_submit_button("Ask")
|
|
|
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 |
|
|
|
66 |
answer = ""
|
67 |
citations = {}
|
68 |
for statement in statements:
|
69 |
+
text = statement["text"].strip()
|
70 |
+
answer = (
|
71 |
+
answer + f"\n{text}"
|
72 |
+
if text.startswith("*") or text.startswith("-")
|
73 |
+
else answer + f" {text}"
|
74 |
+
)
|
75 |
+
citation_ids = []
|
76 |
for source in statement.get("sources", []):
|
77 |
source_str = f"[{source['title']}]({source['url']})"
|
78 |
if not (citation_id := citations.get(source_str)):
|
79 |
citation_id = len(citations) + 1
|
80 |
citations[source_str] = citation_id
|
81 |
+
citation_ids.append(citation_id)
|
82 |
+
if citation_ids:
|
83 |
+
answer += " ".join(f"[^{i}]" for i in sorted(citation_ids))
|
84 |
except KeyError as err:
|
85 |
print(err)
|
86 |
return response, ""
|
|
|
92 |
def main():
|
93 |
gemini_client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
|
94 |
|
95 |
+
st.title("Elna")
|
96 |
with st.form("search", border=False):
|
97 |
query = st.text_input("Your medical question")
|
98 |
submit = st.form_submit_button("Ask")
|