Spaces:
Runtime error
Runtime error
max steps slider, trying to refine prompts
Browse files- chat/__init__.py +14 -8
- test_sanitize.py → chat/test_sanitize.py +2 -1
chat/__init__.py
CHANGED
@@ -2,8 +2,9 @@ import re
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from loguru import logger
|
5 |
-
|
6 |
-
|
|
|
7 |
|
8 |
available_models = models()
|
9 |
|
@@ -23,7 +24,7 @@ class Actor:
|
|
23 |
|
24 |
|
25 |
def setup(question):
|
26 |
-
pp1 = pp2 = pp3 = "
|
27 |
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)
|
28 |
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)
|
29 |
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)
|
@@ -36,20 +37,23 @@ def setup(question):
|
|
36 |
actor.model = st.selectbox("model", available_models, key=f"{role}-model")
|
37 |
actor.system_prompt = st.text_area("system-prompt", actor.system_prompt, key=f"{role}-sp")
|
38 |
actor.pre_prompt = st.text_area("pre-prompt", actor.pre_prompt, key=f"{role}-pp")
|
|
|
39 |
st.text_input("Priest's task", f"{question}")
|
40 |
-
return question
|
41 |
|
42 |
|
43 |
def main():
|
44 |
-
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!")
|
|
|
45 |
|
46 |
actor = target(sanitize(question))
|
47 |
-
max_steps = 1
|
48 |
for step, _ in enumerate(range(max_steps), start=1):
|
49 |
with st.spinner(f"({step}/{max_steps}) Asking {actor.role}..."):
|
50 |
-
|
|
|
51 |
st.write(f":blue[{actor.role} says:] {answer}")
|
52 |
question = sanitize(answer)
|
|
|
53 |
actor = target(question)
|
54 |
|
55 |
|
@@ -64,4 +68,6 @@ def target(question) -> Actor:
|
|
64 |
|
65 |
|
66 |
def sanitize(question):
|
67 |
-
return re.sub(r"\(
|
|
|
|
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from loguru import logger
|
5 |
+
from .ollamachat import ask, models
|
6 |
+
|
7 |
+
# from .transformerschat import ask, models
|
8 |
|
9 |
available_models = models()
|
10 |
|
|
|
24 |
|
25 |
|
26 |
def setup(question):
|
27 |
+
pp1 = pp2 = pp3 = "Answer questions as precisely as you can! If you want to ask anyone, always start your sentence with their role. Never start your sentence with your own name. Share your inner thoughts inside parentheses. SAY ONLY ONE SINGLE SENTENCE!"
|
28 |
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)
|
29 |
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)
|
30 |
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)
|
|
|
37 |
actor.model = st.selectbox("model", available_models, key=f"{role}-model")
|
38 |
actor.system_prompt = st.text_area("system-prompt", actor.system_prompt, key=f"{role}-sp")
|
39 |
actor.pre_prompt = st.text_area("pre-prompt", actor.pre_prompt, key=f"{role}-pp")
|
40 |
+
max_steps = st.slider("max-steps", min_value=1, max_value=10, value=6, key="max-steps")
|
41 |
st.text_input("Priest's task", f"{question}")
|
42 |
+
return question, max_steps
|
43 |
|
44 |
|
45 |
def main():
|
46 |
+
question, max_steps = 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!")
|
47 |
+
questioner = None
|
48 |
|
49 |
actor = target(sanitize(question))
|
|
|
50 |
for step, _ in enumerate(range(max_steps), start=1):
|
51 |
with st.spinner(f"({step}/{max_steps}) Asking {actor.role}..."):
|
52 |
+
extended = f"{questioner} asks: {question}" if questioner else question
|
53 |
+
answer = ask(actor.model, actor.system_prompt, actor.pre_prompt, extended)
|
54 |
st.write(f":blue[{actor.role} says:] {answer}")
|
55 |
question = sanitize(answer)
|
56 |
+
questioner = actor.role
|
57 |
actor = target(question)
|
58 |
|
59 |
|
|
|
68 |
|
69 |
|
70 |
def sanitize(question):
|
71 |
+
return re.sub(r"(\b\w+\s+(says|asks):\s*)?", "",
|
72 |
+
re.sub(r"(\b\w+\s+says:\s*)?\([^)]*\)", "", question)
|
73 |
+
)
|
test_sanitize.py → chat/test_sanitize.py
RENAMED
@@ -1,4 +1,4 @@
|
|
1 |
-
from
|
2 |
|
3 |
|
4 |
def test_sanitize():
|
@@ -8,6 +8,7 @@ def test_sanitize():
|
|
8 |
assert 'qwertyui' == sanitize('qwertyui')
|
9 |
assert 'qwertyui ' == sanitize('qwertyui (abcdef)')
|
10 |
assert 'qwertyui poiuy' == sanitize('qwertyui (abcdef) poiuy')
|
|
|
11 |
|
12 |
assert '"Teacher, I heard about a fascinating story from someone who lives in the city. Can you guess who it might be?" ' == sanitize(
|
13 |
'"Teacher, I heard about a fascinating story from someone who lives in the city. Can you guess who it might be?" (I want to find out if the Teacher can make any...)')
|
|
|
1 |
+
from chat import sanitize, target
|
2 |
|
3 |
|
4 |
def test_sanitize():
|
|
|
8 |
assert 'qwertyui' == sanitize('qwertyui')
|
9 |
assert 'qwertyui ' == sanitize('qwertyui (abcdef)')
|
10 |
assert 'qwertyui poiuy' == sanitize('qwertyui (abcdef) poiuy')
|
11 |
+
assert 'qwertyui poiuy' == sanitize('Priest says: qwertyui (abcdef) poiuy')
|
12 |
|
13 |
assert '"Teacher, I heard about a fascinating story from someone who lives in the city. Can you guess who it might be?" ' == sanitize(
|
14 |
'"Teacher, I heard about a fascinating story from someone who lives in the city. Can you guess who it might be?" (I want to find out if the Teacher can make any...)')
|