Spaces:
Paused
Paused
Make the models work in parallel 4
Browse files- __pycache__/crew.cpython-310.pyc +0 -0
- crew.py +3 -7
__pycache__/crew.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/crew.cpython-310.pyc and b/__pycache__/crew.cpython-310.pyc differ
|
|
|
crew.py
CHANGED
|
@@ -146,8 +146,6 @@ class GAIACrew():
|
|
| 146 |
|
| 147 |
import concurrent.futures
|
| 148 |
|
| 149 |
-
import concurrent.futures
|
| 150 |
-
|
| 151 |
def run_parallel_crew(question: str, file_path: str):
|
| 152 |
"""
|
| 153 |
1) Prepares the prompt (including file data if any).
|
|
@@ -172,16 +170,15 @@ def run_parallel_crew(question: str, file_path: str):
|
|
| 172 |
agents = crew_instance.agents
|
| 173 |
|
| 174 |
# Build (name, agent) pairs
|
| 175 |
-
pairs
|
| 176 |
workers = [agent for name, agent in pairs if name != "manager_agent"]
|
| 177 |
manager = next(agent for name, agent in pairs if name == "manager_agent")
|
| 178 |
|
| 179 |
# 3) Run workers in parallel
|
| 180 |
-
inputs = {"question": final_question}
|
| 181 |
results = {}
|
| 182 |
with concurrent.futures.ThreadPoolExecutor(max_workers=len(workers)) as pool:
|
| 183 |
futures = {
|
| 184 |
-
pool.submit(lambda ag: ag.kickoff(
|
| 185 |
for name, ag in pairs if name != "manager_agent"
|
| 186 |
}
|
| 187 |
for fut in concurrent.futures.as_completed(futures):
|
|
@@ -202,11 +199,10 @@ def run_parallel_crew(question: str, file_path: str):
|
|
| 202 |
)
|
| 203 |
|
| 204 |
# 5) Run the manager for the final answer
|
| 205 |
-
final = manager.kickoff(
|
| 206 |
return get_final_answer(FINAL_ANSWER_MODEL, question, str(final))
|
| 207 |
|
| 208 |
|
| 209 |
-
|
| 210 |
def get_final_answer(model, question, answer):
|
| 211 |
prompt_template = """
|
| 212 |
You are an expert question answering assistant. Given a question and an initial answer, your task is to provide the final answer.
|
|
|
|
| 146 |
|
| 147 |
import concurrent.futures
|
| 148 |
|
|
|
|
|
|
|
| 149 |
def run_parallel_crew(question: str, file_path: str):
|
| 150 |
"""
|
| 151 |
1) Prepares the prompt (including file data if any).
|
|
|
|
| 170 |
agents = crew_instance.agents
|
| 171 |
|
| 172 |
# Build (name, agent) pairs
|
| 173 |
+
pairs = list(zip(names, agents))
|
| 174 |
workers = [agent for name, agent in pairs if name != "manager_agent"]
|
| 175 |
manager = next(agent for name, agent in pairs if name == "manager_agent")
|
| 176 |
|
| 177 |
# 3) Run workers in parallel
|
|
|
|
| 178 |
results = {}
|
| 179 |
with concurrent.futures.ThreadPoolExecutor(max_workers=len(workers)) as pool:
|
| 180 |
futures = {
|
| 181 |
+
pool.submit(lambda ag: ag.kickoff({"question": final_question}), ag): name
|
| 182 |
for name, ag in pairs if name != "manager_agent"
|
| 183 |
}
|
| 184 |
for fut in concurrent.futures.as_completed(futures):
|
|
|
|
| 199 |
)
|
| 200 |
|
| 201 |
# 5) Run the manager for the final answer
|
| 202 |
+
final = manager.kickoff({"question": manager_prompt})
|
| 203 |
return get_final_answer(FINAL_ANSWER_MODEL, question, str(final))
|
| 204 |
|
| 205 |
|
|
|
|
| 206 |
def get_final_answer(model, question, answer):
|
| 207 |
prompt_template = """
|
| 208 |
You are an expert question answering assistant. Given a question and an initial answer, your task is to provide the final answer.
|