Spaces:
Runtime error
Runtime error
ignore questioner
Browse files- chat/__init__.py +18 -5
- chat/togetherchat.py +2 -2
chat/__init__.py
CHANGED
|
@@ -31,6 +31,19 @@ class Actor:
|
|
| 31 |
|
| 32 |
|
| 33 |
def setup(scenario):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
st.title(scenario.title)
|
| 35 |
columns = st.columns(len(scenario.actors))
|
| 36 |
for actor, col in zip(scenario.actors, columns):
|
|
@@ -94,7 +107,7 @@ def main():
|
|
| 94 |
def main_loop(max_steps, model, scenario, temperature):
|
| 95 |
questioner = None
|
| 96 |
question = scenario.task
|
| 97 |
-
actor = target(scenario, question)
|
| 98 |
for step, _ in enumerate(range(max_steps), start=1):
|
| 99 |
with st.spinner(f"({step}/{max_steps}) Asking {actor.name}..."):
|
| 100 |
extended = f"{questioner} asks: {question}" if questioner else question
|
|
@@ -102,7 +115,7 @@ def main_loop(max_steps, model, scenario, temperature):
|
|
| 102 |
st.write(f":blue[{actor.name} says:] {answer}")
|
| 103 |
question = sanitize(answer)
|
| 104 |
questioner = actor.name
|
| 105 |
-
actor = target(scenario, question)
|
| 106 |
|
| 107 |
|
| 108 |
def closest_to_start(long_string, substrings):
|
|
@@ -110,7 +123,7 @@ def closest_to_start(long_string, substrings):
|
|
| 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
|
|
@@ -118,9 +131,9 @@ def closest_to_start(long_string, substrings):
|
|
| 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")
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
def setup(scenario):
|
| 34 |
+
st.markdown( # top margin hack
|
| 35 |
+
"""
|
| 36 |
+
<style>
|
| 37 |
+
.appview-container .main .block-container {{
|
| 38 |
+
padding-top: {padding_top}rem;
|
| 39 |
+
padding-bottom: {padding_bottom}rem;
|
| 40 |
+
}}
|
| 41 |
+
|
| 42 |
+
</style>""".format(
|
| 43 |
+
padding_top=1, padding_bottom=1
|
| 44 |
+
),
|
| 45 |
+
unsafe_allow_html=True,
|
| 46 |
+
)
|
| 47 |
st.title(scenario.title)
|
| 48 |
columns = st.columns(len(scenario.actors))
|
| 49 |
for actor, col in zip(scenario.actors, columns):
|
|
|
|
| 107 |
def main_loop(max_steps, model, scenario, temperature):
|
| 108 |
questioner = None
|
| 109 |
question = scenario.task
|
| 110 |
+
actor = target(scenario, question, questioner)
|
| 111 |
for step, _ in enumerate(range(max_steps), start=1):
|
| 112 |
with st.spinner(f"({step}/{max_steps}) Asking {actor.name}..."):
|
| 113 |
extended = f"{questioner} asks: {question}" if questioner else question
|
|
|
|
| 115 |
st.write(f":blue[{actor.name} says:] {answer}")
|
| 116 |
question = sanitize(answer)
|
| 117 |
questioner = actor.name
|
| 118 |
+
actor = target(scenario, question, questioner)
|
| 119 |
|
| 120 |
|
| 121 |
def closest_to_start(long_string, substrings):
|
|
|
|
| 123 |
closest_index = len(long_string)
|
| 124 |
closest_substring = None
|
| 125 |
for substring in substrings:
|
| 126 |
+
index = long_string.lower().find(substring.lower())
|
| 127 |
if index != -1 and index < closest_index:
|
| 128 |
closest_index = index
|
| 129 |
closest_substring = substring
|
|
|
|
| 131 |
|
| 132 |
|
| 133 |
# noinspection PyTypeChecker
|
| 134 |
+
def target(scenario: Scenario, question, questioner) -> Actor:
|
| 135 |
try:
|
| 136 |
+
name = closest_to_start(question, [actor.name for actor in scenario.actors if actor.name != questioner])
|
| 137 |
return [actor for actor in scenario.actors if actor.name == name][0]
|
| 138 |
except IndexError:
|
| 139 |
logger.warning(f"no actor found in question: {question}, trying to return the first actor")
|
chat/togetherchat.py
CHANGED
|
@@ -15,7 +15,7 @@ def models():
|
|
| 15 |
'teknium/OpenHermes-2p5-Mistral-7B',
|
| 16 |
'META-LLAMA/LLAMA-3-8B-CHAT-HF',
|
| 17 |
'microsoft/WizardLM-2-8x22B',
|
| 18 |
-
'WizardLM/WizardLM-13B-V1.2'
|
| 19 |
'Qwen/Qwen1.5-14B-Chat',
|
| 20 |
'togethercomputer/StripedHyena-Nous-7B',
|
| 21 |
'meta-llama/Llama-2-13b-chat-hf',
|
|
@@ -27,7 +27,7 @@ def models():
|
|
| 27 |
|
| 28 |
def ask(model, system_prompt, pre_prompt, question, temperature=0.7):
|
| 29 |
messages = [
|
| 30 |
-
{'role': 'system', 'content': f"{
|
| 31 |
{'role': 'user', 'content': f"{question}"},
|
| 32 |
]
|
| 33 |
logger.debug(f"<< {model} << {question}")
|
|
|
|
| 15 |
'teknium/OpenHermes-2p5-Mistral-7B',
|
| 16 |
'META-LLAMA/LLAMA-3-8B-CHAT-HF',
|
| 17 |
'microsoft/WizardLM-2-8x22B',
|
| 18 |
+
'WizardLM/WizardLM-13B-V1.2',
|
| 19 |
'Qwen/Qwen1.5-14B-Chat',
|
| 20 |
'togethercomputer/StripedHyena-Nous-7B',
|
| 21 |
'meta-llama/Llama-2-13b-chat-hf',
|
|
|
|
| 27 |
|
| 28 |
def ask(model, system_prompt, pre_prompt, question, temperature=0.7):
|
| 29 |
messages = [
|
| 30 |
+
{'role': 'system', 'content': f"{pre_prompt} {system_prompt}"},
|
| 31 |
{'role': 'user', 'content': f"{question}"},
|
| 32 |
]
|
| 33 |
logger.debug(f"<< {model} << {question}")
|