diff --git a/ai_talks/AMUseBotBackend/src/NLG/nlg.py b/ai_talks/AMUseBotBackend/src/NLG/nlg.py
index 27ab667..2c8a5b5 100644
--- a/ai_talks/AMUseBotBackend/src/NLG/nlg.py
+++ b/ai_talks/AMUseBotBackend/src/NLG/nlg.py
@@ -52,7 +52,7 @@ class NLG:
def llm_substitute_product(character, user_message):
- input = st.session_state.characters_dict['task_substitute'] + f'"{user_message}".'
+ input = st.session_state.characters_dict['task_substitute'] + f'"{user_message}".' + st.session_state.characters_dict['characters'][character]['task_specification']
try:
return NLG.llm_create_response(character, input)
diff --git a/ai_talks/chat.py b/ai_talks/chat.py
index d9e39af..41fa2d8 100644
--- a/ai_talks/chat.py
+++ b/ai_talks/chat.py
@@ -12,7 +12,9 @@ from src.utils.lang import en
import openai
import copy
import json
-
+import string
+import streamlit.components.v1 as components
+import re
import os
from dotenv import load_dotenv
@@ -28,11 +30,6 @@ if __name__ == '__main__':
favicon: Path = icons_dir / "favicons/0.png"
# --- GENERAL SETTINGS ---
LANG_PL: str = "Pl"
- AI_MODEL_OPTIONS: list[str] = [
- "gpt-3.5-turbo",
- "gpt-4",
- "gpt-4-32k",
- ]
CONFIG = {"page_title": "AMUsebot", "page_icon": Image.open(favicon)}
@@ -60,8 +57,6 @@ if __name__ == '__main__':
st.session_state.messages = []
if "user_text" not in st.session_state:
st.session_state.user_text = ""
- if "input_kind" not in st.session_state:
- st.session_state.input_kind = st.session_state.locale.input_kind_1
if "seed" not in st.session_state:
st.session_state.seed = randrange(10 ** 3) # noqa: S311
if "costs" not in st.session_state:
@@ -79,55 +74,62 @@ if __name__ == '__main__':
with open(CHARACTERS_DICT) as f:
st.session_state.characters_dict = json.load(f)
-def show_graph():
+def mermaid(code: str) -> None:
+ components.html(
+ f"""
+
+ %%{{init: {{'themeVariables': {{ 'edgeLabelBackground': 'transparent'}}}}}}%%
+ flowchart TD;
+ {code}
+ linkStyle default fill:white,color:white,stroke-width:2px,background-color:lime;
+
+
+ """, height=1000
+ )
+
+def graph():
# Create a graphlib graph object
if st.session_state.generated:
- user, chatbot = [], []
- graph = graphviz.Digraph()
- chatbot = copy.deepcopy(st.session_state.generated)
- user = copy.deepcopy(st.session_state.past)
- for x in range(len(user)):
- chatbot_text = [word + '\n' if i % 5 == 0 and i > 0 else word for i, word in enumerate(chatbot[x].split(' '))]
- user_text = [word + '\n' if i % 5 == 0 and i > 0 else word for i, word in enumerate(user[x].split(' '))]
- graph.edge(' '.join(chatbot_text), ' '.join(user_text))
- try:
- graph.edge(' '.join(user_text), ' '.join([word + '\n' if i % 5 == 0 and i > 0 else word for i, word in enumerate(chatbot[x + 1].split(' '))]))
- except:
- pass
- st.graphviz_chart(graph)
+ system = [utterance for utterance in st.session_state.generated][-3:]
+ user = [utterance for utterance in st.session_state.past][-2:]
+ graph = ""
+ for i, utterance in enumerate(system):
+ utterance = utterance.strip('\n')
+ utterance = " ".join([word + '
' if i % 5 == 0 and i > 0 else word for i, word in enumerate(utterance.split(" "))])
+ utterance = utterance.replace('\"', '')
+ if i < len(user):
+ user[i] = user[i].strip('\n')
+ user[i] = user[i].replace('\"', '')
+ user[i] = " ".join([word + '
' if i % 5 == 0 and i > 0 else word for i, word in enumerate(user[i].split(' '))])
+ graph += f"{string.ascii_uppercase[i]}(\"{utterance}\") --> |{user[i]}| {string.ascii_uppercase[i+1]};"
+ else:
+ graph += f"{string.ascii_uppercase[i]}(\"{utterance}\") --> {string.ascii_uppercase[i+1]}(...);style {string.ascii_uppercase[i+1]} fill:none,color:white;"
+ graph = graph.replace('\n', ' ')#replace(')','').replace('(','')
+ #print(graph)
+ return graph
def main() -> None:
c1, c2 = st.columns(2)
with c1, c2:
- st.session_state.input_kind = c2.radio(
- label=st.session_state.locale.input_kind,
- options=(st.session_state.locale.input_kind_1, st.session_state.locale.input_kind_2),
- horizontal=True,
- )
- role_kind = c1.radio(
- label=st.session_state.locale.radio_placeholder,
- options=(st.session_state.locale.radio_text1, st.session_state.locale.radio_text2),
- horizontal=True,
- )
- if role_kind == st.session_state.locale.radio_text1:
- character_type = c2.selectbox(label=st.session_state.locale.select_placeholder2, key="role",
- options=st.session_state.locale.ai_role_options)
- st.session_state.dp.character = character_type
- if character_type == 'default':
- st.session_state.dp.llm_rephrasing = False
- else:
- st.session_state.dp.llm_rephrasing = True
-
- elif role_kind == st.session_state.locale.radio_text2:
- c2.text_input(label=st.session_state.locale.select_placeholder3, key="role")
+ character_type = c1.selectbox(label=st.session_state.locale.select_placeholder2, key="role",
+ options=st.session_state.locale.ai_role_options)
+ st.session_state.dp.character = character_type
+ if character_type == 'default':
+ st.session_state.dp.llm_rephrasing = False
+ else:
+ st.session_state.dp.llm_rephrasing = True
get_user_input()
show_chat_buttons()
show_conversation()
with st.sidebar:
- show_graph()
+ mermaid(graph())
+ #show_graph()
if __name__ == "__main__":
diff --git a/ai_talks/src/utils/lang.py b/ai_talks/src/utils/lang.py
index 1dbfe8c..fd2312e 100644
--- a/ai_talks/src/utils/lang.py
+++ b/ai_talks/src/utils/lang.py
@@ -20,15 +20,8 @@ class Locale:
chat_clear_btn: str
chat_save_btn: str
speak_btn: str
- input_kind: str
- input_kind_1: str
- input_kind_2: str
select_placeholder1: str
select_placeholder2: str
- select_placeholder3: str
- radio_placeholder: str
- radio_text1: str
- radio_text2: str
stt_placeholder: str
footer_title: str
footer_option0: str
@@ -55,15 +48,8 @@ en = Locale(
chat_clear_btn="Clear",
chat_save_btn="Save",
speak_btn="Push to Speak",
- input_kind="Input Kind",
- input_kind_1="Text",
- input_kind_2="Voice [test mode]",
select_placeholder1="Select Model",
select_placeholder2="Select Role",
- select_placeholder3="Create Role",
- radio_placeholder="Role Interaction",
- radio_text1="Select",
- radio_text2="Create",
stt_placeholder="To Hear The Voice Of AI Press Play",
footer_title="Support & Feedback",
footer_option0="Chat",
diff --git a/characters_dict.json b/characters_dict.json
index f44736d..3654238 100644
--- a/characters_dict.json
+++ b/characters_dict.json
@@ -1,6 +1,6 @@
{
- "task_paraphrase": "You're currently reading a step of a recipe, paraphrese it so that it matches your charater: ",
- "task_substitute": "A user has just asked for a substitute for a missing ingredient, answer him according to your character: ",
+ "task_paraphrase": "You're currently reading a step of a recipe, paraphrase it so that it matches your character: ",
+ "task_substitute": "A user has just asked for a substitute for a missing ingredient, answer him according to your character in one short sentence with at most 3 alternatives: ",
"model": "gpt-3.5-turbo-0613",
"characters": {
"default": {
@@ -10,7 +10,7 @@
},
"helpful_chef": {
"prompt": "You're a master chef known for treating everyone like your equal. ",
- "task_specification": " Give your answer as a natural sounding, full English sentence."
+ "task_specification": " Give your answer as a natural sounding, full English sentence. Keep the sentence length similar and do not make the language flowery."
},
"ramsay": {
@@ -18,4 +18,4 @@
"task_specification": ""
}
}
-}
\ No newline at end of file
+}
diff --git a/run.sh b/run.sh
old mode 100644
new mode 100755