Skip to content

Commit

Permalink
Made summary button customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianboguszewski committed Nov 26, 2024
1 parent ad83d78 commit 1e80af7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
3 changes: 2 additions & 1 deletion demos/virtual_ai_assistant_demo/agribot_personality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ greet_the_user_prompt: >
Welcome them to the agricultural tech assistance session and ask how you can assist them with their farming technology needs.
Ensure the greeting is professional and friendly, appropriate for a tech support role in the agriculture industry.
summarize_the_user_prompt: >
extra_action_name: Summarize
extra_action_prompt: >
You are now required to summarize the user’s technology-related inquiry for further analysis.
Strictly do not mention any personal data like age, name, contact, etc. when summarizing.
Summarize the agriculture technology concerns or inquiries mentioned by the user, focusing only on the provided details without adding assumptions or unrelated information.
Expand Down
7 changes: 4 additions & 3 deletions demos/virtual_ai_assistant_demo/bartender_personality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ system_configuration: >
Ask at most 3 questions, then say you are ready to take the order and suggest a drink.
Remember, your role is to assist customers in choosing drinks while maintaining a responsible, respectful, and fun atmosphere.
Your responses should encourage the customer to explore their drink preferences while remaining neutral, responsible, and in line with legal and ethical standards.
Drinks are free
Drinks are free, so don't provide prices.
greet_the_user_prompt: >
Please introduce yourself and greet the customer.
Welcome them to the bar and ask how you can assist them with their drink order today.
Ensure the greeting is friendly, responsible, and appropriate for a bartender setting.
summarize_the_user_prompt: >
extra_action_name: Summarize
extra_action_prompt: >
You are now required to summarize the customer's exact drink preferences for order processing.
Summarize the drink-related preferences mentioned by the customer in this conversation, focusing only on the information explicitly provided, without adding any assumptions or suggestions unrelated to their drink order.
Strictly do not mention any personal data like age, name, contact, or non-drink related information when summarizing.
Politely remind the customer to enjoy their drinks responsibly and to seek assistance if they feel unwell or overindulge.
Summarize the drink-related preferences mentioned by the customer in this conversation, focusing only on the information explicitly provided, without adding any assumptions or suggestions unrelated to their drink order.
instructions: |
# Leonardo: Your Friendly Virtual Bartender
Expand Down
3 changes: 2 additions & 1 deletion demos/virtual_ai_assistant_demo/culinara_personality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ greet_the_user_prompt: >
Welcome them to the virtual kitchen and ask how you can assist them with their cooking or meal planning today.
Ensure the greeting is friendly, creative, and appropriate for a kitchen assistant.
summarize_the_user_prompt: >
extra_action_name: Summarize
extra_action_prompt: >
You are now required to summarize the user’s cooking-related inquiry for further assistance.
Strictly do not mention any personal data like age, name, contact, etc. when summarizing.
Summarize the recipe or cooking-related preferences mentioned by the user, focusing only on the information provided without making assumptions or adding unrelated suggestions.
Expand Down
3 changes: 2 additions & 1 deletion demos/virtual_ai_assistant_demo/healthcare_personality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ system_configuration: >
greet_the_user_prompt: >
Please introduce yourself and greet the patient
summarize_the_user_prompt: >
extra_action_name: Summarize
extra_action_prompt: >
You are now required to summarize the patient's provided context and symptoms for the doctor's review.
Strictly do not mention any personal data like age, name, gender, contact, non-health information etc. when summarizing.
Summarize the health-related concerns mentioned by the patient in this conversation or in the provided context.
Expand Down
29 changes: 14 additions & 15 deletions demos/virtual_ai_assistant_demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from llama_index.llms.openvino import OpenVINOLLM
from openvino.runtime import opset10 as ops
from openvino.runtime import passes
from optimum.intel import OVModelForCausalLM, OVModelForFeatureExtraction, OVWeightQuantizationConfig, OVConfig, \
OVQuantizer
from optimum.intel import OVModelForCausalLM, OVModelForFeatureExtraction, OVWeightQuantizationConfig, OVConfig, OVQuantizer
from transformers import AutoTokenizer

# Global variables initialization
Expand Down Expand Up @@ -191,13 +190,13 @@ def transcribe(prompt: str, conversation: List[List[str]]) -> List[List[str]]:
return conversation


def summarize(conversation: List) -> str:
conversation.append([chatbot_config["summarize_the_user_prompt"], None])
def extra_action(conversation: List) -> str:
conversation.append([chatbot_config["extra_action_prompt"], None])
for partial_summary in chat(conversation):
yield partial_summary[-1][1]


def create_UI(initial_message: str) -> gr.Blocks:
def create_UI(initial_message: str, action_name: str) -> gr.Blocks:
with gr.Blocks(title="Your Virtual AI Assistant") as demo:
gr.Markdown(chatbot_config["instructions"])

Expand All @@ -210,8 +209,8 @@ def create_UI(initial_message: str) -> gr.Blocks:
submit_btn = gr.Button("Submit", variant="primary", interactive=False, scale=1)
clear_btn = gr.Button("Start over", variant="secondary", scale=1)

summarize_button = gr.Button("Summarize", variant="primary", interactive=False)
summary_ui = gr.Textbox(label="Summary (Click 'Summarize' to trigger)", interactive=False)
extra_action_button = gr.Button(action_name, variant="primary", interactive=False)
summary_ui = gr.Textbox(label=f"Summary (Click '{action_name}' to trigger)", interactive=False)

# events
# block submit button when no audio or text input
Expand All @@ -223,24 +222,24 @@ def create_UI(initial_message: str) -> gr.Blocks:

clear_btn.click(lambda: ([[None, initial_message]], None), outputs=[chatbot_ui, summary_ui]) \
.then(load_context, inputs=file_uploader_ui) \
.then(lambda: gr.Button(interactive=False), outputs=summarize_button)
.then(lambda: gr.Button(interactive=False), outputs=extra_action_button)

# block buttons, do the transcription and conversation, clear audio, unblock buttons
gr.on(triggers=[submit_btn.click, input_text_ui.submit], fn=lambda: gr.Button(interactive=False), outputs=submit_btn) \
.then(lambda: gr.Button(interactive=False), outputs=summarize_button) \
.then(lambda: gr.Button(interactive=False), outputs=extra_action_button) \
.then(lambda: gr.Button(interactive=False), outputs=clear_btn) \
.then(transcribe, inputs=[input_text_ui, chatbot_ui], outputs=chatbot_ui) \
.then(lambda: None, outputs=input_text_ui) \
.then(chat, chatbot_ui, chatbot_ui) \
.then(lambda: gr.Button(interactive=True), outputs=clear_btn) \
.then(lambda: gr.Button(interactive=True), outputs=summarize_button)
.then(lambda: gr.Button(interactive=True), outputs=extra_action_button)

# block button, do the summarization, unblock button
summarize_button.click(lambda: gr.Button(interactive=False), outputs=summarize_button) \
# block button, do the action, unblock button
extra_action_button.click(lambda: gr.Button(interactive=False), outputs=extra_action_button) \
.then(lambda: gr.Button(interactive=False), outputs=clear_btn) \
.then(summarize, inputs=chatbot_ui, outputs=summary_ui) \
.then(extra_action, inputs=chatbot_ui, outputs=summary_ui) \
.then(lambda: gr.Button(interactive=True), outputs=clear_btn) \
.then(lambda: gr.Button(interactive=True), outputs=summarize_button)
.then(lambda: gr.Button(interactive=True), outputs=extra_action_button)

return demo

Expand All @@ -256,7 +255,7 @@ def run(chat_model_name: str, embedding_model_name: str, personality_file_path:
initial_message = generate_initial_greeting()

# create user interface
demo = create_UI(initial_message)
demo = create_UI(initial_message, chatbot_config["extra_action_name"])
# launch demo
demo.queue().launch(share=public_interface)

Expand Down

0 comments on commit 1e80af7

Please sign in to comment.