Spaces:
Runtime error
Runtime error
File size: 1,410 Bytes
4962437 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
from concurrent.futures import ThreadPoolExecutor
from termcolor import colored
from tabulate import tabulate
class GodMode:
"""
GodMode
-----
Architecture:
How it works:
1. GodMode receives a task from the user.
2. GodMode distributes the task to all LLMs.
3. GodMode collects the responses from all LLMs.
4. GodMode prints the responses from all LLMs.
Parameters:
llms: list of LLMs
Methods:
run(task): distribute task to all LLMs and collect responses
print_responses(task): print responses from all LLMs
Usage:
god_mode = GodMode(llms)
god_mode.run(task)
god_mode.print_responses(task)
"""
def __init__(
self,
llms
):
self.llms = llms
def run(self, task):
with ThreadPoolExecutor() as executor:
responses = executor.map(lambda llm: llm(task), self.llms)
return list(responses)
def print_responses(self, task):
"""Prints the responses in a tabular format"""
responses = self.run_all(task)
table = []
for i, response in enumerate(responses):
table.append([f"LLM {i+1}", response])
print(
colored(
tabulate(
table,
headers=["LLM", "Response"],
tablefmt="pretty"
), "cyan"
)
)
|