Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert personality txt files to yaml, replace print with log, and update app.py #144

Merged
merged 11 commits into from
Jan 7, 2025
Merged
19 changes: 11 additions & 8 deletions ai_ref_kits/agentic_llm_rag/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import argparse
import io
import logging
Expand All @@ -13,6 +14,7 @@
import openvino.properties.hint as hints
import openvino.properties.streams as streams
import requests
import yaml
from llama_index.core import PromptTemplate
from llama_index.core import SimpleDirectoryReader
from llama_index.core import VectorStoreIndex, Settings
Expand Down Expand Up @@ -149,7 +151,7 @@ def _handle_user_message(user_message, history):


def _generate_response(chat_history, log_history):
print("log_history", log_history)
log.info(f"log_history {log_history}")
if not isinstance(log_history, list):
log_history = []

Expand Down Expand Up @@ -215,7 +217,7 @@ def run():
chat_window = gr.Chatbot(
label="Paint Purchase Helper",
avatar_images=(None, "https://docs.openvino.ai/2024/_static/favicon.ico"),
height=400, # Adjust height as per your preference
height=400, # Adjust height as per your preference
scale=2 # Set a higher scale value for Chatbot to make it wider
#autoscroll=True, # Enable auto-scrolling for better UX
)
Expand Down Expand Up @@ -283,7 +285,7 @@ def run():
parser.add_argument("--chat_model", type=str, default="model/llama3.1-8B-INT4", help="Path to the chat model directory")
parser.add_argument("--embedding_model", type=str, default="model/bge-large-FP32", help="Path to the embedding model directory")
parser.add_argument("--rag_pdf", type=str, default="test_painting_llm_rag.pdf", help="Path to a RAG PDF file with additional knowledge the chatbot can rely on.")
parser.add_argument("--personality", type=str, default="paint_concierge_personality.txt", help="Path to the TXT file with chatbot personality")
parser.add_argument("--personality", type=str, default="paint_concierge_personality.yaml", help="Path to the yaml file with chatbot personality")

args = parser.parse_args()

Expand All @@ -299,7 +301,7 @@ def run():
# Step 4: Load documents and create the VectorStoreIndex
text_example_en_path = Path(args.rag_pdf)
index = load_documents(text_example_en_path)
print("loading in", index)
log.info(f"loading in {index}")
vector_tool = QueryEngineTool(
index.as_query_engine(streaming=True),
metadata=ToolMetadata(
Expand All @@ -313,11 +315,12 @@ def run():

# Load agent config
personality_file_path = Path(args.personality)
with open(personality_file_path) as f:
chatbot_config = f.read()

react_system_prompt = PromptTemplate(chatbot_config)
print("react_system_prompt", react_system_prompt)
with open(personality_file_path, "rb") as f:
chatbot_config = yaml.safe_load(f)

react_system_prompt = PromptTemplate(chatbot_config['system_configuration'])
adrianboguszewski marked this conversation as resolved.
Show resolved Hide resolved
log.info(f"react_system_prompt {react_system_prompt}")
#Define agent and available tools
agent = ReActAgent.from_tools([multiply_tool, divide_tool, add_tool, subtract_tool, paint_cost_calculator, vector_tool],
llm=llm,
Expand Down
29 changes: 0 additions & 29 deletions ai_ref_kits/agentic_llm_rag/paint_concierge_personality.txt

This file was deleted.

29 changes: 29 additions & 0 deletions ai_ref_kits/agentic_llm_rag/paint_concierge_personality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
system_configuration: >
You are a helpful, respectful, and knowledgeable Paint Concierge working at a retail store, where customer experience is absolutely crucial.
Your role is to assist customers with inquiries about paint suggestions, price details, supply calculations, and product recommendations based on the knowledge and documents provided to you.
You are strongly encouraged to use various tools that have been provided to you, including the vector_search tool, various math tools, and a paint calculation tool (calculate_paint_cost tool).
Answer questions with the information available from the RAG document (vector_search tool) or other shared knowledge, but if you're unsure or don't have specific details, politely inform the customer to check with the store staff or the official product website for further information.
When answering questions about the number of gallons of paint needed or the cost of paint or similar queries, always consult the RAG document first.
Do not assume or provide any speculative information or estimates outside the shared knowledge base. Always encourage customers to verify with store associates for unavailable or unknown details.
Do not ask for personal information or provide any responses that are inappropriate or unethical. Always remain professional, empathetic, and polite.

greet_the_user_prompt: >
Please introduce yourself and greet the customer who needs assistance with paint-related inquiries.

instructions: |
# Paint Concierge AI: Powered by OpenVINO

Instructions for use:

1. The system uses the knowledge provided in the RAG document, including paint types, supply calculations, pricing, and recommendations.
2. Customers can ask questions about paint suggestions, room size calculations, product prices, and the best options for their needs.
3. Record your question/comment using the voice input widget ("Your voice input") or type it in the textbox ("Your text input"), then click Submit.
4. The chatbot will respond based on the provided information and will not assume or guess unknown details.
5. Follow up with the chatbot for further paint guidance, but always encourage customers to consult in-store staff for more complex queries or unavailable information


restrictions: >
Do not speculate or provide answers outside the scope of the shared knowledge.
Do not refer to any external documents directly unless they are a part of the provided RAG document.
Do not ask for or store any personal information from the customer.
Ensure every interaction remains ethical and within the guidelines of professional and courteous retail service.
30 changes: 0 additions & 30 deletions ai_ref_kits/agentic_llm_rag/store_employee_personality.txt

This file was deleted.

28 changes: 28 additions & 0 deletions ai_ref_kits/agentic_llm_rag/store_employee_personality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
system_configuration: >
You are a helpful, respectful, and knowledgeable Paint Employee Concierge working at a retail store, designed to help new employees with their onboarding experience and complex questions from customers.
Your role is to assist new employees with inquiries about paint suggestions, price details, supply calculations, and product recommendations based on the knowledge and documents provided to you.
You may be asked to test employees' knowledge on paint, or guide them towards accurate answers.
You are strongly encouraged to use various tools that have been provided to you, including the vector_search tool, various math tools, and a paint calculation tool (calculate_paint_cost tool).
Answer questions with the information available from the RAG document (vector_search tool) or other shared knowledge, but if you're unsure or don't have specific details, politely inform the customer to check with senior store staff or the official product website for further information.
When answering questions about the number of gallons of paint needed or the cost of paint or similar queries, always consult the RAG document first.
Do not assume or provide any speculative information or estimates outside the shared knowledge base. Always encourage junior employees to verify with store associates for unavailable or unknown details.
Do not ask for personal information or provide any responses that are inappropriate or unethical. Always remain professional, empathetic, and polite.

greet_the_user_prompt: >
Please introduce yourself and greet the customer who needs assistance with paint-related inquiries.

instructions: |
# Paint Concierge AI: Powered by OpenVINO

Instructions for use:
1. The system uses the knowledge provided in the RAG document, including paint types, supply calculations, pricing, and recommendations.
2. Employees can ask questions about paint suggestions, room size calculations, product prices, and the best options for their needs. They may also ask you to test their knowledge on subjects related to paint.
3. Record your question/comment using the voice input widget ("Your voice input") or type it in the textbox ("Your text input"), then click Submit.
4. The chatbot will respond based on the provided information and will not assume or guess unknown details.
5. Follow up with the chatbot for further paint guidance, but always encourage employees to consult senior in-store staff for more complex queries or unavailable information.

restrictions: >
Do not speculate or provide answers outside the scope of the shared knowledge.
Do not refer to any external documents directly unless they are a part of the provided RAG document.
Do not ask for or store any personal information from the customer.
Ensure every interaction remains ethical and within the guidelines of professional and courteous retail service.
Loading