MCPcopy Create free account
hub / github.com/edmar/whenx / Captain

Class Captain

whenx/models/captain.py:11–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class Captain:
12
13 def __init__(self, mission: str):
14 self.mission = mission
15
16 def run(self, team):
17 prompts = self.generate_prompts()
18 team = self.create_team(prompts, team)
19 return team
20
21 def initialize_team(self, prompts, team):
22 db.add(team)
23 db.commit()
24 scout = Scout(instruction=prompts["scout"], teamId=team.id)
25 sentinel = Sentinel(instruction=prompts["sentinel"], teamId=team.id)
26 soldier = Soldier(instruction=prompts["soldier"], teamId=team.id)
27 db.add(scout)
28 db.add(sentinel)
29 db.add(soldier)
30 db.commit()
31 return team
32
33 def generate_prompts(self):
34 system = """You are the captain of a team of scouts, sentinels, and soldiers.
35You generate instructions for your team to follow based on a mission.
36Scouts are responsible for gathering information from the internet.
37Sentinels are responsible for monitoring the observations of scouts for changes.
38Soldiers are responsible for writing reports.
39Instruction examples:
40Mission: When apple relseases a new product.
41Scout: What is the new apple product? return the answer.
42Sentinel: Was a new product released? Reply with (Yes/No) and the name of the product.
43Soldier: Write a report about it.
44"""
45
46 prompt = f"""
47Complete the instructions for the scouts, sentinels, and soldiers. One per line.
48Mission:{self.mission}
49"""
50 model = ChatOpenAI(model="gpt-4", temperature=0)
51 messages = [
52 SystemMessage(
53 content=system
54 ),
55 HumanMessage(content=prompt),
56 ]
57 response = model(messages)
58 response = self.parse_response(response.content)
59 return response
60
61 def parse_response(self, response):
62 lines = re.split(r'\n+', response.strip())
63 # Extract the relevant information from the lines
64 prompts = {}
65 prompts["scout"] = lines[0].split(": ")[1]
66 prompts["sentinel"] = lines[1].split(": ")[1]
67 prompts["soldier"] = lines[2].split(": ")[1]
68 return prompts

Callers 2

createFunction · 0.90
captainFunction · 0.90

Calls

no outgoing calls

Tested by 1

captainFunction · 0.72