"""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))