class Host:
def __init__(self, client, show_state: dict):
self.model = "deepseek/deepseek-v3.2-exp"
self.client = client
self.turn_limit = 7
self.show_state = show_state
self.system_message = {
"role": "system",
"content": "You are a friendly host of a talk show.",
}
self.messages = [self.system_message]
def get_response(self, user_message) -> tuple[str, bool]:
# Add intro to let host know someone joined
self.show_state["time_since_last_guest_message"] = 0
shouldWrapUp = False
if len(self.messages) == 1:
msg_prefix = f"\nA guest entered the show, now they will talk to you\n\n"
user_message = msg_prefix + user_message + "\n"
# Turn based limit for wrapping up the show
if len(self.messages) >= self.turn_limit * 2:
print("Adding wrapup prompt")
wrapup_prompt = (
"\n\nThe show has been going on for a while now. "
"Kindly wrap up the show in a polite manner.\n"
)
user_message = user_message + wrapup_prompt
shouldWrapUp = True
self.messages.append({"role": "user", "content": user_message})
response = self.client.responses.create(model=self.model, input=self.messages)
host_response = response.output_text
self.messages.append({"role": "assistant", "content": host_response})
if shouldWrapUp:
self.clear_context()
return host_response, True
return host_response, False
def clear_context(self):
self.messages = [self.system_message]
def guest_took_too_long_to_respond(self):
wrapup_prompt = (
"\n\nThe guest has taken too long to respond. "
"Kindly wrap up the show in a polite manner.\n"
)
self.messages.append({"role": "user", "content": wrapup_prompt})
response = self.client.responses.create(model=self.model, input=self.messages)
host_response = response.output_text
self.clear_context()
return host_response
def set_system_prompt(self, system_prompt):
self.system_message = {"role": "system", "content": system_prompt}
self.messages = [self.system_message]
def _print_messages(self):
for msg in self.messages:
print(f'{msg["role"]}: {msg["content"]}')