Edit on GitHub

agent_search_gateway.llm.prompts

Pure prompt builders for gateway LLM stages.

  1"""Pure prompt builders for gateway LLM stages."""
  2
  3from ..providers.contracts import ChatMessage
  4
  5
  6def judge_messages(candidate: str) -> tuple[ChatMessage, ...]:
  7    return (
  8        {
  9            "role": "system",
 10            "content": (
 11                "Decide whether the supplied text is usable main-body content for the target "
 12                "web page. Return JSON with boolean field ok and optional short string field "
 13                "reason."
 14            ),
 15        },
 16        {"role": "user", "content": f"Candidate content:\n{candidate}"},
 17    )
 18
 19
 20def safety_messages(content: str) -> tuple[ChatMessage, ...]:
 21    return (
 22        {
 23            "role": "system",
 24            "content": (
 25                "Decide whether the supplied final page content is safe to return. "
 26                "Return JSON with boolean field ok and optional short string field reason."
 27            ),
 28        },
 29        {"role": "user", "content": f"Final content:\n{content}"},
 30    )
 31
 32
 33def content_clean_messages(raw_content: str) -> tuple[ChatMessage, ...]:
 34    return (
 35        {
 36            "role": "system",
 37            "content": (
 38                "Return only the cleaned, readable main content from the supplied raw page text."
 39            ),
 40        },
 41        {"role": "user", "content": raw_content},
 42    )
 43
 44
 45def focus_summary_messages(content: str, focus: str) -> tuple[ChatMessage, ...]:
 46    normalized_focus = focus.strip()
 47    return (
 48        {
 49            "role": "system",
 50            "content": "Summarize only the supplied page content, emphasizing the requested focus.",
 51        },
 52        {
 53            "role": "user",
 54            "content": f"Focus: {normalized_focus}\n\nPage content:\n{content}",
 55        },
 56    )
 57
 58
 59def llm_search_messages(prompt: str) -> tuple[ChatMessage, ...]:
 60    return (
 61        {
 62            "role": "system",
 63            "content": (
 64                "Find relevant web results. Return only repeated blocks in this exact "
 65                "restricted format:\n## Result\nURL: https://example.com/page\n"
 66                "Abstract: concise non-empty summary\n"
 67                "Do not use Markdown links or other result formats."
 68            ),
 69        },
 70        {"role": "user", "content": prompt.strip()},
 71    )
 72
 73
 74def llm_paper_search_messages(prompt: str) -> tuple[ChatMessage, ...]:
 75    return (
 76        {
 77            "role": "system",
 78            "content": (
 79                "Find relevant academic papers. Return only repeated blocks in exactly this "
 80                "16-line restricted format, with every field present exactly once and in this "
 81                "order. "
 82                "Optional values may be empty. Authors and Topics are semicolon-separated. "
 83                "Dates are empty or YYYY-MM-DD. Citations are empty or a non-negative integer. "
 84                "Open Access is true, false, or unknown. Do not use Markdown links, Result blocks, "
 85                "or any text outside these blocks:\n"
 86                "## Paper\n"
 87                "Title: paper title\n"
 88                "Authors: Alice Author; Bob Author\n"
 89                "Abstract: concise abstract\n"
 90                "DOI: 10.1000/example\n"
 91                "arXiv: 2401.12345\n"
 92                "Published: 2024-01-02\n"
 93                "Updated: 2024-02-03\n"
 94                "URL: https://example.com/paper\n"
 95                "PDF: https://example.com/paper.pdf\n"
 96                "Venue: venue name\n"
 97                "Topics: topic one; topic two\n"
 98                "Citations: 0\n"
 99                "Open Access: unknown\n"
100                "OA Status: \n"
101                "License: "
102            ),
103        },
104        {"role": "user", "content": prompt.strip()},
105    )
def judge_messages(candidate: str) -> tuple[Mapping[str, str], ...]:
 7def judge_messages(candidate: str) -> tuple[ChatMessage, ...]:
 8    return (
 9        {
10            "role": "system",
11            "content": (
12                "Decide whether the supplied text is usable main-body content for the target "
13                "web page. Return JSON with boolean field ok and optional short string field "
14                "reason."
15            ),
16        },
17        {"role": "user", "content": f"Candidate content:\n{candidate}"},
18    )
def safety_messages(content: str) -> tuple[Mapping[str, str], ...]:
21def safety_messages(content: str) -> tuple[ChatMessage, ...]:
22    return (
23        {
24            "role": "system",
25            "content": (
26                "Decide whether the supplied final page content is safe to return. "
27                "Return JSON with boolean field ok and optional short string field reason."
28            ),
29        },
30        {"role": "user", "content": f"Final content:\n{content}"},
31    )
def content_clean_messages(raw_content: str) -> tuple[Mapping[str, str], ...]:
34def content_clean_messages(raw_content: str) -> tuple[ChatMessage, ...]:
35    return (
36        {
37            "role": "system",
38            "content": (
39                "Return only the cleaned, readable main content from the supplied raw page text."
40            ),
41        },
42        {"role": "user", "content": raw_content},
43    )
def focus_summary_messages(content: str, focus: str) -> tuple[Mapping[str, str], ...]:
46def focus_summary_messages(content: str, focus: str) -> tuple[ChatMessage, ...]:
47    normalized_focus = focus.strip()
48    return (
49        {
50            "role": "system",
51            "content": "Summarize only the supplied page content, emphasizing the requested focus.",
52        },
53        {
54            "role": "user",
55            "content": f"Focus: {normalized_focus}\n\nPage content:\n{content}",
56        },
57    )
def llm_search_messages(prompt: str) -> tuple[Mapping[str, str], ...]:
60def llm_search_messages(prompt: str) -> tuple[ChatMessage, ...]:
61    return (
62        {
63            "role": "system",
64            "content": (
65                "Find relevant web results. Return only repeated blocks in this exact "
66                "restricted format:\n## Result\nURL: https://example.com/page\n"
67                "Abstract: concise non-empty summary\n"
68                "Do not use Markdown links or other result formats."
69            ),
70        },
71        {"role": "user", "content": prompt.strip()},
72    )
def llm_paper_search_messages(prompt: str) -> tuple[Mapping[str, str], ...]:
 75def llm_paper_search_messages(prompt: str) -> tuple[ChatMessage, ...]:
 76    return (
 77        {
 78            "role": "system",
 79            "content": (
 80                "Find relevant academic papers. Return only repeated blocks in exactly this "
 81                "16-line restricted format, with every field present exactly once and in this "
 82                "order. "
 83                "Optional values may be empty. Authors and Topics are semicolon-separated. "
 84                "Dates are empty or YYYY-MM-DD. Citations are empty or a non-negative integer. "
 85                "Open Access is true, false, or unknown. Do not use Markdown links, Result blocks, "
 86                "or any text outside these blocks:\n"
 87                "## Paper\n"
 88                "Title: paper title\n"
 89                "Authors: Alice Author; Bob Author\n"
 90                "Abstract: concise abstract\n"
 91                "DOI: 10.1000/example\n"
 92                "arXiv: 2401.12345\n"
 93                "Published: 2024-01-02\n"
 94                "Updated: 2024-02-03\n"
 95                "URL: https://example.com/paper\n"
 96                "PDF: https://example.com/paper.pdf\n"
 97                "Venue: venue name\n"
 98                "Topics: topic one; topic two\n"
 99                "Citations: 0\n"
100                "Open Access: unknown\n"
101                "OA Status: \n"
102                "License: "
103            ),
104        },
105        {"role": "user", "content": prompt.strip()},
106    )