Spaces:
Sleeping
Sleeping
Create reasoning_chain.py
Browse files
AI_Agent/chains/reasoning_chain.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AI_Agent/chains/reasoning_chain.py
|
| 2 |
+
class ReasoningChain:
|
| 3 |
+
def __init__(self, llm_adapter):
|
| 4 |
+
self.llm = llm_adapter
|
| 5 |
+
|
| 6 |
+
async def run(self, prompt, contexts):
|
| 7 |
+
reasoning_prompt = (
|
| 8 |
+
"You are a reasoning assistant.\n"
|
| 9 |
+
f"User prompt:\n{prompt}\n\n"
|
| 10 |
+
f"Context documents:\n" + "\n".join([f"- {c}" for c in contexts]) +
|
| 11 |
+
"\n\nProvide step-by-step reasoning and intermediate conclusions."
|
| 12 |
+
)
|
| 13 |
+
out = await self.llm.generate(reasoning_prompt)
|
| 14 |
+
return {"reasoning": out["text"], "raw": out.get("raw")}
|