Spaces:
Runtime error
Runtime error
new scenario
Browse files- chat/__init__.py +35 -4
chat/__init__.py
CHANGED
@@ -5,6 +5,7 @@ from loguru import logger
|
|
5 |
|
6 |
# from .ollamachat import ask, models
|
7 |
from .togetherchat import ask, models
|
|
|
8 |
# from .transformerschat import ask, models
|
9 |
|
10 |
available_models = models()
|
@@ -56,6 +57,16 @@ def setup(scenario):
|
|
56 |
def main():
|
57 |
st.set_page_config(layout="wide")
|
58 |
scenarios = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
Scenario(
|
60 |
"The Small Village scenario", [
|
61 |
Actor("Priest", "You are the Priest. There are 3 people standing in a circle: the Priest (that's you), the Teacher and the Kid."),
|
@@ -72,7 +83,8 @@ def main():
|
|
72 |
],
|
73 |
"Always start your sentence with the name of the other person. Share your inner thoughts inside parentheses. NEVER start your sentence with your own name!",
|
74 |
"Find out the secret number!"
|
75 |
-
)
|
|
|
76 |
|
77 |
scenario = st.selectbox("scenario", scenarios)
|
78 |
model, max_steps, temperature = setup(scenario)
|
@@ -93,16 +105,35 @@ def main_loop(max_steps, model, scenario, temperature):
|
|
93 |
actor = target(scenario, question)
|
94 |
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
# noinspection PyTypeChecker
|
97 |
def target(scenario: Scenario, question) -> Actor:
|
98 |
try:
|
99 |
-
|
100 |
-
|
101 |
-
return [actor for actor in scenario.actors if actor.name == role][0]
|
102 |
except IndexError:
|
103 |
logger.warning(f"no actor found in question: {question}, trying to return the first actor")
|
104 |
return scenario.actors[0]
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
def sanitize(question):
|
108 |
return re.sub(r"(\b\w+\s+(says|asks):\s*)?", "",
|
|
|
5 |
|
6 |
# from .ollamachat import ask, models
|
7 |
from .togetherchat import ask, models
|
8 |
+
|
9 |
# from .transformerschat import ask, models
|
10 |
|
11 |
available_models = models()
|
|
|
57 |
def main():
|
58 |
st.set_page_config(layout="wide")
|
59 |
scenarios = [
|
60 |
+
Scenario(
|
61 |
+
"Murder in the library", [
|
62 |
+
Actor("Librarian", "You are the librarian. Today morning you found a dead body of an old lady laying on the floor. There is a visitor who just entered and a cleaning lady is standing in the corner."),
|
63 |
+
Actor("Visitor",
|
64 |
+
"You are a visitor in the library. You wish to borrow an interesting book for two weeks to read on your upcoming vacation. There is a librarian who you can ask and a cleaning lady standing in the corner."),
|
65 |
+
Actor("Cleaning lady", "You are the cleaning lady in the library. Today you came to work with a serious headache. There is a visitor and a librarian in the room."),
|
66 |
+
],
|
67 |
+
"You are an actor in this roleplaying game. Your full response is said out loud and other people hear it. ",
|
68 |
+
"Find out who committed the murder! You must find the clues by asking the two other people in the room."
|
69 |
+
),
|
70 |
Scenario(
|
71 |
"The Small Village scenario", [
|
72 |
Actor("Priest", "You are the Priest. There are 3 people standing in a circle: the Priest (that's you), the Teacher and the Kid."),
|
|
|
83 |
],
|
84 |
"Always start your sentence with the name of the other person. Share your inner thoughts inside parentheses. NEVER start your sentence with your own name!",
|
85 |
"Find out the secret number!"
|
86 |
+
)
|
87 |
+
]
|
88 |
|
89 |
scenario = st.selectbox("scenario", scenarios)
|
90 |
model, max_steps, temperature = setup(scenario)
|
|
|
105 |
actor = target(scenario, question)
|
106 |
|
107 |
|
108 |
+
def closest_to_start(long_string, substrings):
|
109 |
+
logger.debug(f"looking for {substrings} in {long_string}")
|
110 |
+
closest_index = len(long_string)
|
111 |
+
closest_substring = None
|
112 |
+
for substring in substrings:
|
113 |
+
index = long_string.find(substring)
|
114 |
+
if index != -1 and index < closest_index:
|
115 |
+
closest_index = index
|
116 |
+
closest_substring = substring
|
117 |
+
return closest_substring
|
118 |
+
|
119 |
+
|
120 |
# noinspection PyTypeChecker
|
121 |
def target(scenario: Scenario, question) -> Actor:
|
122 |
try:
|
123 |
+
name = closest_to_start(question, [actor.name for actor in scenario.actors])
|
124 |
+
return [actor for actor in scenario.actors if actor.name == name][0]
|
|
|
125 |
except IndexError:
|
126 |
logger.warning(f"no actor found in question: {question}, trying to return the first actor")
|
127 |
return scenario.actors[0]
|
128 |
|
129 |
+
# try:
|
130 |
+
# role = re.split(r'\s|,|:', question.strip())[0].strip()
|
131 |
+
# logger.debug(f"finding actor with role: {role} in actors: {[actor.name for actor in scenario.actors]}")
|
132 |
+
# return [actor for actor in scenario.actors if actor.name == role][0]
|
133 |
+
# except IndexError:
|
134 |
+
# logger.warning(f"no actor found in question: {question}, trying to return the first actor")
|
135 |
+
# return scenario.actors[0]
|
136 |
+
|
137 |
|
138 |
def sanitize(question):
|
139 |
return re.sub(r"(\b\w+\s+(says|asks):\s*)?", "",
|