Spaces:
Runtime error
Runtime error
refactor to Actor class
Browse files
app.py
CHANGED
@@ -31,45 +31,54 @@ def ask(model, system_prompt, pre_prompt, question):
|
|
31 |
return response['message']['content']
|
32 |
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
pp1 = pp2 = pp3 = "Ask the other two by always starting your sentence with their role. Share your inner thoughts inside parentheses."
|
40 |
-
qp1 = qp2 = qp3 = "Your task is to figure out their names and where they live. Do not ask directly, they must not realize what information you are after! SAY ONLY ONE SINGLE SENTENCE!"
|
41 |
|
|
|
|
|
|
|
|
|
|
|
42 |
st.set_page_config(layout="wide")
|
43 |
col1, col2, col3 = st.columns(3)
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
answer2 = ask(model2, system_prompt2, pre_prompt2, qp2)
|
72 |
-
st.write(f":blue[Teacher says:] {answer2}")
|
73 |
|
74 |
|
75 |
def sanitize(question):
|
|
|
31 |
return response['message']['content']
|
32 |
|
33 |
|
34 |
+
class Actor:
|
35 |
+
actors = {}
|
36 |
+
|
37 |
+
def __init__(self, role, model, system_prompt, pre_prompt):
|
38 |
+
self.role = role
|
39 |
+
self.model = model
|
40 |
+
self.system_prompt = system_prompt
|
41 |
+
self.pre_prompt = pre_prompt
|
42 |
+
Actor.actors[role] = self
|
43 |
+
|
44 |
+
def __class_getitem__(cls, item):
|
45 |
+
return cls.actors[item]
|
46 |
|
|
|
|
|
47 |
|
48 |
+
def setup(question):
|
49 |
+
pp1 = pp2 = pp3 = "Ask the other two by always starting your sentence with their role. Never start your sentence with your own name. Share your inner thoughts inside parentheses."
|
50 |
+
priest = Actor("Priest", available_models[0], "You are the Priest. There are 3 people standing in a circle: the Priest (that's you), the Teacher and the Kid.", pp1)
|
51 |
+
teacher = Actor("Teacher", available_models[0], "You are the Teacher. There are 3 people standing in a circle: the Priest, the Teacher (that's you) and the Kid.", pp2)
|
52 |
+
kid = Actor("Kid", available_models[0], "You are the Kid. There are 3 people standing in a circle: the Priest, the Teacher and the Kid (that's you).", pp3)
|
53 |
st.set_page_config(layout="wide")
|
54 |
col1, col2, col3 = st.columns(3)
|
55 |
+
for actor, col in [(priest, col1), (teacher, col2), (kid, col3)]:
|
56 |
+
with col:
|
57 |
+
role = actor.role
|
58 |
+
st.title(role)
|
59 |
+
actor.model = st.selectbox("model", available_models, key=f"{role}-model")
|
60 |
+
actor.system_prompt = st.text_area("system-prompt", actor.system_prompt, key=f"{role}-sp")
|
61 |
+
actor.pre_prompt = st.text_area("pre-prompt", actor.pre_prompt, key=f"{role}-pp")
|
62 |
+
st.text_input("Priest's task", f"{question}")
|
63 |
+
return question
|
64 |
+
|
65 |
+
|
66 |
+
def main():
|
67 |
+
question = setup("Priest, your task is to figure out their names and where they live. Do not ask directly, they must not realize what information you are after! SAY ONLY ONE SINGLE SENTENCE!")
|
68 |
+
|
69 |
+
role = target(question)
|
70 |
+
for count, _ in enumerate(range(10)):
|
71 |
+
with st.spinner(f"Asking {role}..."):
|
72 |
+
actor = Actor[role]
|
73 |
+
answer = ask(actor.model, actor.system_prompt, actor.pre_prompt, question)
|
74 |
+
st.write(f":blue[{actor.role} says:] {answer}")
|
75 |
+
question = sanitize(answer)
|
76 |
+
role = target(question)
|
77 |
+
count += 1
|
78 |
+
|
79 |
+
|
80 |
+
def target(question):
|
81 |
+
return re.split(r'\s|,|:', question)[0]
|
|
|
|
|
82 |
|
83 |
|
84 |
def sanitize(question):
|