kjozsa commited on
Commit
81e6627
1 Parent(s): 984d73d

refactor to Actor class

Browse files
Files changed (1) hide show
  1. app.py +44 -35
app.py CHANGED
@@ -31,45 +31,54 @@ def ask(model, system_prompt, pre_prompt, question):
31
  return response['message']['content']
32
 
33
 
34
- def main():
35
- sp1 = """There are 3 people standing in a circle: the Priest (that's you), the Teacher and the Kid."""
36
- sp2 = """There are 3 people standing in a circle: the Priest, the Teacher (that's you) and the Kid."""
37
- sp3 = """There are 3 people standing in a circle: the Priest, the Teacher and the Kid (that's you)."""
 
 
 
 
 
 
 
 
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
- with col1:
45
- st.title("the Priest,")
46
- model1 = st.selectbox("model", available_models, key="model1")
47
- system_prompt1 = st.text_area("system-prompt", sp1, key="sp1")
48
- pre_prompt1 = st.text_area("pre-prompt", pp1, key="pp1")
49
- question1 = st.text_area("question", qp1, key="qp1")
50
-
51
- with col2:
52
- st.title("the Teacher")
53
- model2 = st.selectbox("model", available_models, key="model2")
54
- system_prompt2 = st.text_area("system-prompt", sp2, key="sp2")
55
- pre_prompt2 = st.text_area("pre-prompt", pp2, key="pp2")
56
- # question2 = st.text_area("question", qp2, key="qp2")
57
-
58
- with col3:
59
- st.title("and the Kid")
60
- model3 = st.selectbox("model", available_models, key="model3")
61
- system_prompt3 = st.text_area("system-prompt", sp3, key="sp3")
62
- pre_prompt3 = st.text_area("pre-prompt", pp3, key="pp3")
63
- # question3 = st.text_area("question", qp3, key="qp3")
64
-
65
- with st.spinner("Thinking..."):
66
- answer1 = ask(model1, system_prompt1, pre_prompt1, question1)
67
- st.write(f":blue[Priest says:] {answer1}")
68
-
69
- qp2 = sanitize(answer1)
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):