Spaces:
Sleeping
Sleeping
Create summaru.py
Browse files- generators/summaru.py +15 -0
generators/summaru.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rag.retriever import retrieve, format_citations
|
| 2 |
+
from rag.prompts import SUMMARY_SYS, SUMMARY_USER
|
| 3 |
+
from app.deps import gen
|
| 4 |
+
|
| 5 |
+
def make_summary(query: str):
|
| 6 |
+
hits = retrieve(query, top_k=10)
|
| 7 |
+
links = format_citations(hits) # [(id, url)]
|
| 8 |
+
link_lines = "\n".join([f"[{i}] {u}" for i,u in links])
|
| 9 |
+
ctx = "\n".join([f"[chunk:{h['chunk_id']}] {h['text']}" for h in hits])
|
| 10 |
+
|
| 11 |
+
prompt = [{"role":"system","content":SUMMARY_SYS},
|
| 12 |
+
{"role":"user","content":SUMMARY_USER.format(links=link_lines, contexts=ctx)}]
|
| 13 |
+
|
| 14 |
+
out = gen(prompt, do_sample=False, temperature=0.2)[0]["generated_text"]
|
| 15 |
+
return out, links
|