Spaces:
Sleeping
Sleeping
Update AI_Agent/coordinator.py
Browse files- AI_Agent/coordinator.py +8 -6
AI_Agent/coordinator.py
CHANGED
|
@@ -3,27 +3,31 @@ from AI_Agent.chains.retrieval_chain import RetrievalChain
|
|
| 3 |
from AI_Agent.chains.reasoning_chain import ReasoningChain
|
| 4 |
from AI_Agent.chains.synthesis_chain import SynthesisChain
|
| 5 |
from AI_Agent.chains.task_decomposer_chain import TaskDecomposerChain
|
|
|
|
| 6 |
from AI_Agent.llm_adapters.hf_adapter import HuggingFaceAdapter
|
| 7 |
from AI_Agent.vector_store.vector_store import SimpleVectorStore
|
| 8 |
-
from AI_Agent.chains.task_assigner_chain import TaskAssignerChain
|
| 9 |
|
| 10 |
import asyncio
|
| 11 |
|
| 12 |
class Coordinator:
|
| 13 |
def __init__(self):
|
|
|
|
| 14 |
self.vector_store = SimpleVectorStore()
|
| 15 |
self.vector_store.add_documents([
|
| 16 |
"Doc 1: Notes on building retrieval chains.",
|
| 17 |
"Doc 2: Sample LLM reasoning methods.",
|
| 18 |
"Doc 3: Multi-chain orchestration tips."
|
| 19 |
])
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
self.task_decomposer_chain = TaskDecomposerChain(self.llm)
|
|
|
|
| 22 |
self.retrieval_chain = RetrievalChain(self.vector_store)
|
| 23 |
self.reasoning_chain = ReasoningChain(self.llm)
|
| 24 |
self.synthesis_chain = SynthesisChain(self.llm)
|
| 25 |
-
self.task_assigner_chain = TaskAssignerChain(self.llm)
|
| 26 |
-
|
| 27 |
|
| 28 |
async def run_task(self, brief: str):
|
| 29 |
# Step 1: Task decomposition
|
|
@@ -55,7 +59,6 @@ class Coordinator:
|
|
| 55 |
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
-
import asyncio
|
| 59 |
coord = Coordinator()
|
| 60 |
brief = "Build a task management app with user authentication and task sharing"
|
| 61 |
result = asyncio.run(coord.run_task(brief))
|
|
@@ -63,4 +66,3 @@ if __name__ == "__main__":
|
|
| 63 |
print("Decomposed tasks:\n", result["decomposition"]["tasks_text"])
|
| 64 |
print("Assigned tasks:\n", result["assignment"]["assigned_tasks_text"])
|
| 65 |
print("Final synthesis:\n", result["synthesis"]["answer"])
|
| 66 |
-
|
|
|
|
| 3 |
from AI_Agent.chains.reasoning_chain import ReasoningChain
|
| 4 |
from AI_Agent.chains.synthesis_chain import SynthesisChain
|
| 5 |
from AI_Agent.chains.task_decomposer_chain import TaskDecomposerChain
|
| 6 |
+
from AI_Agent.chains.task_assigner_chain import TaskAssignerChain
|
| 7 |
from AI_Agent.llm_adapters.hf_adapter import HuggingFaceAdapter
|
| 8 |
from AI_Agent.vector_store.vector_store import SimpleVectorStore
|
|
|
|
| 9 |
|
| 10 |
import asyncio
|
| 11 |
|
| 12 |
class Coordinator:
|
| 13 |
def __init__(self):
|
| 14 |
+
# Initialize vector store with sample documents
|
| 15 |
self.vector_store = SimpleVectorStore()
|
| 16 |
self.vector_store.add_documents([
|
| 17 |
"Doc 1: Notes on building retrieval chains.",
|
| 18 |
"Doc 2: Sample LLM reasoning methods.",
|
| 19 |
"Doc 3: Multi-chain orchestration tips."
|
| 20 |
])
|
| 21 |
+
|
| 22 |
+
# Use the CPU-friendly Google Gemma 3n model
|
| 23 |
+
self.llm = HuggingFaceAdapter(model_name="google/gemma-3n-E2B-it")
|
| 24 |
+
|
| 25 |
+
# Initialize all chains
|
| 26 |
self.task_decomposer_chain = TaskDecomposerChain(self.llm)
|
| 27 |
+
self.task_assigner_chain = TaskAssignerChain(self.llm)
|
| 28 |
self.retrieval_chain = RetrievalChain(self.vector_store)
|
| 29 |
self.reasoning_chain = ReasoningChain(self.llm)
|
| 30 |
self.synthesis_chain = SynthesisChain(self.llm)
|
|
|
|
|
|
|
| 31 |
|
| 32 |
async def run_task(self, brief: str):
|
| 33 |
# Step 1: Task decomposition
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
|
|
|
| 62 |
coord = Coordinator()
|
| 63 |
brief = "Build a task management app with user authentication and task sharing"
|
| 64 |
result = asyncio.run(coord.run_task(brief))
|
|
|
|
| 66 |
print("Decomposed tasks:\n", result["decomposition"]["tasks_text"])
|
| 67 |
print("Assigned tasks:\n", result["assignment"]["assigned_tasks_text"])
|
| 68 |
print("Final synthesis:\n", result["synthesis"]["answer"])
|
|
|