Spaces:
Sleeping
Sleeping
Create synthesis_chain.py
Browse files
AI_Agent/chains/synthesis_chain.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AI_Agent/chains/synthesis_chain.py
|
| 2 |
+
class SynthesisChain:
|
| 3 |
+
def __init__(self, llm_adapter):
|
| 4 |
+
self.llm = llm_adapter
|
| 5 |
+
|
| 6 |
+
async def run(self, prompt, reasoning_text, contexts):
|
| 7 |
+
synth_prompt = (
|
| 8 |
+
"You are a synthesis assistant. Combine reasoning and contexts to produce a concise final answer.\n\n"
|
| 9 |
+
f"User prompt:\n{prompt}\n\n"
|
| 10 |
+
f"Reasoning:\n{reasoning_text}\n\n"
|
| 11 |
+
f"Contexts:\n" + "\n".join([f"- {c}" for c in contexts]) +
|
| 12 |
+
"\n\nFinal answer:"
|
| 13 |
+
)
|
| 14 |
+
out = await self.llm.generate(synth_prompt)
|
| 15 |
+
return {"answer": out["text"], "raw": out.get("raw")}
|