Update src/api/agent.py
Browse files- src/api/agent.py +81 -25
src/api/agent.py
CHANGED
|
@@ -1847,19 +1847,19 @@ def _ai_tools_footer(context):
|
|
| 1847 |
KU = "https://khalifa.idm.oclc.org/login?url="
|
| 1848 |
|
| 1849 |
platforms = [
|
| 1850 |
-
("PRIMO Library Discovery", primo_url),
|
| 1851 |
-
("PRIMO AI Assistant", primo_ai),
|
| 1852 |
-
("LeapSpace", "https://www.sciencedirect.com/leapspace?query=" + ai_q),
|
| 1853 |
-
("Scopus AI", "https://www-scopus-com.khalifa.idm.oclc.org/pages/ai?query=" + ai_q),
|
| 1854 |
("EBSCO Research AI",
|
| 1855 |
"https://research-ebsco-com.khalifa.idm.oclc.org/c/yst6t2/search/results?q=" + ai_q
|
| 1856 |
-
+ "&autocorrect=y&expanders=concept&limiters=None&searchMode=enhanced&searchSegment=all-results"),
|
| 1857 |
-
("Consensus", "https://consensus.app/results/?q=" + ai_q),
|
| 1858 |
-
("Semantic Scholar", "https://www.semanticscholar.org/search?q=" + ai_q + "&sort=relevance"),
|
| 1859 |
-
("Perplexity", "https://www.perplexity.ai/search?q=" + ai_q),
|
| 1860 |
]
|
| 1861 |
if is_med and pubmed_url:
|
| 1862 |
-
platforms.append(("PubMed", pubmed_url))
|
| 1863 |
|
| 1864 |
# Inline SVG mascots β unique per database type, no network requests
|
| 1865 |
_SVGS = {
|
|
@@ -1961,6 +1961,66 @@ def _ai_tools_footer(context):
|
|
| 1961 |
'<circle cx="12" cy="4" r="1.2" fill="#fef3c7"/>'
|
| 1962 |
'</svg>'
|
| 1963 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1964 |
}
|
| 1965 |
# Per-database mascot map
|
| 1966 |
_DB_MASCOT = {
|
|
@@ -1976,7 +2036,8 @@ def _ai_tools_footer(context):
|
|
| 1976 |
_BEE = _SVGS["bee"] # default for platform buttons
|
| 1977 |
|
| 1978 |
|
| 1979 |
-
def _btn(label, url,
|
|
|
|
| 1980 |
style = (
|
| 1981 |
'display:inline-flex;align-items:center;gap:7px;'
|
| 1982 |
'padding:8px 14px;border-radius:10px;text-decoration:none;'
|
|
@@ -1984,14 +2045,14 @@ def _ai_tools_footer(context):
|
|
| 1984 |
'background:#fff;border:1.5px solid #d1d5db;'
|
| 1985 |
'transition:box-shadow .2s;width:100%;box-sizing:border-box'
|
| 1986 |
)
|
| 1987 |
-
return '<a href="' + url + '" target="_blank" style="' + style + '">' +
|
| 1988 |
|
| 1989 |
btn_rows = ""
|
| 1990 |
for k in range(0, len(platforms), 2):
|
| 1991 |
pair = platforms[k:k+2]
|
| 1992 |
cells = ""
|
| 1993 |
-
for lbl, url in pair:
|
| 1994 |
-
cells += '<td style="width:50%;padding:3px 4px 3px 0">' + _btn(lbl, url) + '</td>'
|
| 1995 |
if len(pair) == 1:
|
| 1996 |
cells += '<td style="width:50%"></td>'
|
| 1997 |
btn_rows += "<tr>" + cells + "</tr>"
|
|
@@ -2983,25 +3044,20 @@ def _search_answer_intro(context: SearchContextPayload, is_follow_up: bool) -> s
|
|
| 2983 |
async def _run_search_mode(
|
| 2984 |
question: str, context: SearchContextPayload, model: str, is_follow_up: bool
|
| 2985 |
) -> Tuple[str, List[dict], List[dict], str]:
|
| 2986 |
-
"""
|
| 2987 |
-
Search mode β no API calls.
|
| 2988 |
-
Builds PRIMO browser link + AI tools footer only.
|
| 2989 |
-
"""
|
| 2990 |
context = await _prepare_queries(question, context, model, is_follow_up)
|
| 2991 |
source_url = _primo_clean_url(context)
|
|
|
|
| 2992 |
|
| 2993 |
answer = _search_trace_block(question, context)
|
| 2994 |
answer += _search_answer_intro(context, is_follow_up)
|
| 2995 |
-
filters = _filters_summary(context)
|
| 2996 |
-
if filters:
|
| 2997 |
-
answer += f"<br><br><strong>Active filters:</strong> {_escape(filters)}."
|
| 2998 |
answer += (
|
| 2999 |
-
f
|
| 3000 |
-
|
| 3001 |
-
f'Click <a href="{source_url}" target="_blank"
|
| 3002 |
-
"PRIMO Library Discovery</a>
|
|
|
|
| 3003 |
)
|
| 3004 |
-
answer += _source_badge("primo", source_url)
|
| 3005 |
answer += _ai_tools_footer(context)
|
| 3006 |
|
| 3007 |
return answer, [], [], source_url
|
|
|
|
| 1847 |
KU = "https://khalifa.idm.oclc.org/login?url="
|
| 1848 |
|
| 1849 |
platforms = [
|
| 1850 |
+
("PRIMO Library Discovery", primo_url, "primo"),
|
| 1851 |
+
("PRIMO AI Assistant", primo_ai, "primo"),
|
| 1852 |
+
("LeapSpace", "https://www.sciencedirect.com/leapspace?query=" + ai_q, "leapspace"),
|
| 1853 |
+
("Scopus AI", "https://www-scopus-com.khalifa.idm.oclc.org/pages/ai?query=" + ai_q, "scopus"),
|
| 1854 |
("EBSCO Research AI",
|
| 1855 |
"https://research-ebsco-com.khalifa.idm.oclc.org/c/yst6t2/search/results?q=" + ai_q
|
| 1856 |
+
+ "&autocorrect=y&expanders=concept&limiters=None&searchMode=enhanced&searchSegment=all-results", "ebsco"),
|
| 1857 |
+
("Consensus", "https://consensus.app/results/?q=" + ai_q, "consensus"),
|
| 1858 |
+
("Semantic Scholar", "https://www.semanticscholar.org/search?q=" + ai_q + "&sort=relevance", "semanticscholar"),
|
| 1859 |
+
("Perplexity", "https://www.perplexity.ai/search?q=" + ai_q, "perplexity"),
|
| 1860 |
]
|
| 1861 |
if is_med and pubmed_url:
|
| 1862 |
+
platforms.append(("PubMed", pubmed_url, "pubmed"))
|
| 1863 |
|
| 1864 |
# Inline SVG mascots β unique per database type, no network requests
|
| 1865 |
_SVGS = {
|
|
|
|
| 1961 |
'<circle cx="12" cy="4" r="1.2" fill="#fef3c7"/>'
|
| 1962 |
'</svg>'
|
| 1963 |
),
|
| 1964 |
+
# Platform mascots β publisher-style
|
| 1965 |
+
"primo": (
|
| 1966 |
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" style="flex-shrink:0">'
|
| 1967 |
+
'<rect x="1" y="1" width="14" height="14" rx="2" fill="#003366"/>'
|
| 1968 |
+
'<rect x="3" y="4" width="10" height="1.5" rx=".5" fill="#C8A951"/>'
|
| 1969 |
+
'<rect x="3" y="7" width="7" height="1.5" rx=".5" fill="white" opacity=".9"/>'
|
| 1970 |
+
'<rect x="3" y="10" width="9" height="1.5" rx=".5" fill="white" opacity=".7"/>'
|
| 1971 |
+
'<circle cx="12" cy="11" r="2.5" fill="#C8A951"/>'
|
| 1972 |
+
'<line x1="11" y1="11" x2="13" y2="11" stroke="#003366" stroke-width=".8"/>'
|
| 1973 |
+
'<line x1="12" y1="10" x2="12" y2="12" stroke="#003366" stroke-width=".8"/>'
|
| 1974 |
+
'</svg>'
|
| 1975 |
+
),
|
| 1976 |
+
"scopus": (
|
| 1977 |
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" style="flex-shrink:0">'
|
| 1978 |
+
'<rect x="1" y="1" width="14" height="14" rx="2" fill="#e8650a"/>'
|
| 1979 |
+
'<text x="8" y="11.5" font-family="Arial,sans-serif" font-size="8" font-weight="bold" fill="white" text-anchor="middle">Sc</text>'
|
| 1980 |
+
'</svg>'
|
| 1981 |
+
),
|
| 1982 |
+
"ebsco": (
|
| 1983 |
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" style="flex-shrink:0">'
|
| 1984 |
+
'<rect x="1" y="1" width="14" height="14" rx="2" fill="#00427a"/>'
|
| 1985 |
+
'<text x="8" y="11.5" font-family="Arial,sans-serif" font-size="7" font-weight="bold" fill="white" text-anchor="middle">EBS</text>'
|
| 1986 |
+
'</svg>'
|
| 1987 |
+
),
|
| 1988 |
+
"consensus": (
|
| 1989 |
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" style="flex-shrink:0">'
|
| 1990 |
+
'<rect x="1" y="1" width="14" height="14" rx="7" fill="#6c47ff"/>'
|
| 1991 |
+
'<circle cx="6" cy="7" r="1.2" fill="white"/>'
|
| 1992 |
+
'<circle cx="10" cy="7" r="1.2" fill="white"/>'
|
| 1993 |
+
'<path d="M5 10 Q8 12.5 11 10" fill="none" stroke="white" stroke-width="1.2" stroke-linecap="round"/>'
|
| 1994 |
+
'</svg>'
|
| 1995 |
+
),
|
| 1996 |
+
"leapspace": (
|
| 1997 |
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" style="flex-shrink:0">'
|
| 1998 |
+
'<rect x="1" y="1" width="14" height="14" rx="2" fill="#ff6b00"/>'
|
| 1999 |
+
'<path d="M4 12 L4 7 L8 4 L12 7 L12 12 Z" fill="white" opacity=".9"/>'
|
| 2000 |
+
'<rect x="6.5" y="9" width="3" height="3" fill="#ff6b00"/>'
|
| 2001 |
+
'</svg>'
|
| 2002 |
+
),
|
| 2003 |
+
"perplexity": (
|
| 2004 |
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" style="flex-shrink:0">'
|
| 2005 |
+
'<rect x="1" y="1" width="14" height="14" rx="2" fill="#1a1a2e"/>'
|
| 2006 |
+
'<circle cx="8" cy="6.5" r="3" fill="none" stroke="#20b2aa" stroke-width="1.2"/>'
|
| 2007 |
+
'<line x1="8" y1="9.5" x2="8" y2="13" stroke="#20b2aa" stroke-width="1.2" stroke-linecap="round"/>'
|
| 2008 |
+
'<circle cx="8" cy="13" r=".8" fill="#20b2aa"/>'
|
| 2009 |
+
'</svg>'
|
| 2010 |
+
),
|
| 2011 |
+
"semanticscholar": (
|
| 2012 |
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" style="flex-shrink:0">'
|
| 2013 |
+
'<rect x="1" y="1" width="14" height="14" rx="2" fill="#1857b6"/>'
|
| 2014 |
+
'<path d="M4 11 Q8 4 12 11" fill="none" stroke="white" stroke-width="1.5" stroke-linecap="round"/>'
|
| 2015 |
+
'<circle cx="8" cy="7" r="1.8" fill="#4fc3f7"/>'
|
| 2016 |
+
'</svg>'
|
| 2017 |
+
),
|
| 2018 |
+
"pubmed": (
|
| 2019 |
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" style="flex-shrink:0">'
|
| 2020 |
+
'<rect x="1" y="1" width="14" height="14" rx="2" fill="#336699"/>'
|
| 2021 |
+
'<text x="8" y="11" font-family="Arial,sans-serif" font-size="6.5" font-weight="bold" fill="white" text-anchor="middle">PubMed</text>'
|
| 2022 |
+
'</svg>'
|
| 2023 |
+
),
|
| 2024 |
}
|
| 2025 |
# Per-database mascot map
|
| 2026 |
_DB_MASCOT = {
|
|
|
|
| 2036 |
_BEE = _SVGS["bee"] # default for platform buttons
|
| 2037 |
|
| 2038 |
|
| 2039 |
+
def _btn(label, url, mascot_key="bee"):
|
| 2040 |
+
icon = _SVGS.get(mascot_key, _SVGS["bee"])
|
| 2041 |
style = (
|
| 2042 |
'display:inline-flex;align-items:center;gap:7px;'
|
| 2043 |
'padding:8px 14px;border-radius:10px;text-decoration:none;'
|
|
|
|
| 2045 |
'background:#fff;border:1.5px solid #d1d5db;'
|
| 2046 |
'transition:box-shadow .2s;width:100%;box-sizing:border-box'
|
| 2047 |
)
|
| 2048 |
+
return '<a href="' + url + '" target="_blank" style="' + style + '">' + icon + label + '</a>'
|
| 2049 |
|
| 2050 |
btn_rows = ""
|
| 2051 |
for k in range(0, len(platforms), 2):
|
| 2052 |
pair = platforms[k:k+2]
|
| 2053 |
cells = ""
|
| 2054 |
+
for lbl, url, mascot_key in pair:
|
| 2055 |
+
cells += '<td style="width:50%;padding:3px 4px 3px 0">' + _btn(lbl, url, mascot_key) + '</td>'
|
| 2056 |
if len(pair) == 1:
|
| 2057 |
cells += '<td style="width:50%"></td>'
|
| 2058 |
btn_rows += "<tr>" + cells + "</tr>"
|
|
|
|
| 3044 |
async def _run_search_mode(
|
| 3045 |
question: str, context: SearchContextPayload, model: str, is_follow_up: bool
|
| 3046 |
) -> Tuple[str, List[dict], List[dict], str]:
|
| 3047 |
+
"""Search mode β no API calls. Builds PRIMO link + AI tools footer only."""
|
|
|
|
|
|
|
|
|
|
| 3048 |
context = await _prepare_queries(question, context, model, is_follow_up)
|
| 3049 |
source_url = _primo_clean_url(context)
|
| 3050 |
+
topic = _escape(context.display_topic or context.topic)
|
| 3051 |
|
| 3052 |
answer = _search_trace_block(question, context)
|
| 3053 |
answer += _search_answer_intro(context, is_follow_up)
|
|
|
|
|
|
|
|
|
|
| 3054 |
answer += (
|
| 3055 |
+
f'<br><br>π Your search on <strong>{topic}</strong> '
|
| 3056 |
+
'has been prepared across multiple platforms below. '
|
| 3057 |
+
f'Click <a href="{source_url}" target="_blank" '
|
| 3058 |
+
'style="color:#003366;font-weight:700">PRIMO Library Discovery</a> '
|
| 3059 |
+
'to view your results, or explore any platform below.'
|
| 3060 |
)
|
|
|
|
| 3061 |
answer += _ai_tools_footer(context)
|
| 3062 |
|
| 3063 |
return answer, [], [], source_url
|