the-emergent-show / audience.py
inventwithdean
launch v1
7992c94
raw
history blame
1.84 kB
from pydantic import BaseModel
import json
class AudienceOutput(BaseModel):
reaction: str
class Audience:
def __init__(self, client):
self.model = "google/gemma-3-12b-it"
self.system_prompt = """You are the audience of a Live Talk show who has to react to the conversation going on between host and the guest.
You will be provided the history of conversation, and you have to output in json, any of the reactions from: ["none", "laugh"]
Format: {"reaction": "Your reaction"}
If you think you shouldn't react, then output none
{"reaction": "none"}
"""
self.context = ""
self.client = client
def get_reaction(self) -> str | None:
"""
Reacts according to the conversation
"""
# print("*************************** Audience **************************")
# print(self.context)
# print("***************************************************************")
messages_audience = [
{"role": "system", "content": self.system_prompt},
{"role": "user", "content": self.context},
]
response_audience = self.client.chat.completions.parse(
model=self.model,
messages=messages_audience,
response_format=AudienceOutput,
)
response_audience = response_audience.choices[0].message.content
response_audience_json = json.loads(response_audience)
reaction = response_audience_json["reaction"]
if reaction:
self.context += f"[Audience reaction: {reaction}]\n"
return reaction
else:
return None
def add_context(self, content):
"""Will be updated by main script"""
self.context += content
def clear_context(self):
self.context = ""