File size: 801 Bytes
c7f2c56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Render a question with locally retrieved, operator-authored notes."""

from runtime.reference import retrieve


def prompt(metadata, question, hits):
    notes = "\n\n".join(
        f"{h['title']}\nFurther reading: {h['url']}\nEditorial summary: {h['body']}"
        for h in hits
    )
    return (
        f"Answer the {metadata['topic']} question concisely. "
        "Use relevant information below and link the supporting reference. "
        "These summaries are paraphrases by Hyperion Gray. Use your own words. "
        "If the notes do not establish the answer, say what information is missing."
        f"\n\n{notes or '(No matching notes.)'}\n\nQuestion: {question}"
    )


def ground(database, metadata, question):
    return prompt(metadata, question, retrieve(database, question))