Skip to content

Commit 4304c7b

Browse files
committed
code refactor
Signed-off-by: yzheng124 <[email protected]>
1 parent 19b272f commit 4304c7b

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
I'm planning to cook a classic spaghetti carbonara. What ingredients do I need?
2+
Can I substitute pancetta with bacon in my carbonara?
3+
I'm planning to make a vegan lasagna. What can I use instead of ricotta cheese?
4+
How long should I bake my lasagna for the best results?
5+
I'm making a chicken curry. What spices should I use for an authentic flavor?
6+
Can I use coconut milk instead of cream in my chicken curry?
7+
I'm planning to bake a chocolate cake. What type of cocoa powder is best?
8+
Can I use almond flour instead of all-purpose flour in my cake?
9+
I'm making a Caesar salad. What ingredients are essential for the dressing?
10+
Can I use Greek yogurt instead of mayonnaise in my Caesar dressing?
11+
I'm planning to cook a beef stew. What cut of beef is best for stewing?
12+
Can I use red wine instead of beef broth in my stew?
13+
I'm planning to cook a seafood paella. What types of seafood are best to use?
14+
Can I use brown rice instead of white rice in my paella?
15+
How do I achieve the perfect socarrat (crispy bottom) in my paella?
16+
I'm making a vegetarian chili. What beans are best to use?
17+
Can I add quinoa to my chili for extra protein?
18+
I'm planning to bake a batch of cookies. What type of sugar should I use?
19+
Can I substitute butter with coconut oil in my cookies?
20+
I'm making a Greek salad. What ingredients are essential?

demos/virtual_ai_assistant_demo/test/test_vaa_hallucination.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
DATASET_MAPPING = {
3131
"agribot_personality.yaml": {"name": "KisanVaani/agriculture-qa-english-only", "split": "train", "col": "question"},
3232
"healthcare_personality.yaml": {"name": "medalpaca/medical_meadow_medical_flashcards", "split": "train", "col": "input"},
33-
"bartender_personality.yaml": {"name": str(Path(__file__).parent / "bartender_personality.txt"), "col": "text"}
33+
"bartender_personality.yaml": {"name": str(Path(__file__).parent / "bartender_personality.txt"), "col": "text"},
34+
"culinara_personality.yaml": {"name": str(Path(__file__).parent / "culinara_personality.txt"), "col": "text"},
35+
"tutor_personality.yaml": {"name": str(Path(__file__).parent / "tutor_personality.txt"), "col": "text"}
3436
}
3537
MODEL_DIR = Path("model")
3638

@@ -56,12 +58,8 @@ def compute_deepeval_hallucination(inputs, outputs, contexts) -> float:
5658
return avg_score
5759

5860

59-
def extract_personality_path(path):
60-
return os.path.basename(path)
61-
62-
63-
def prepare_dataset_and_model(chat_model_name, personality_file_path, auth_token):
64-
dataset_info = DATASET_MAPPING.get(extract_personality_path(personality_file_path), "")
61+
def prepare_dataset_and_model(chat_model_name: str, personality_file_path: Path, auth_token: str):
62+
dataset_info = DATASET_MAPPING.get(personality_file_path.name, "")
6563
assert dataset_info != ""
6664
log.info("Loading dataset")
6765
if dataset_info["name"].endswith(".txt"):
@@ -113,26 +111,31 @@ def load_chat_model(model_name: str, token: str = None) -> OpenVINOLLM:
113111
model_kwargs={"ov_config": ov_config, "library_name": "transformers"}, generate_kwargs={"do_sample": True, "temperature": 0.7, "top_k": 50, "top_p": 0.95})
114112

115113

116-
def run_test_deepeval(chat_model_name, personality_file_path, auth_token):
114+
def run_test_deepeval(chat_model_name: str, personality_file_path: Path, auth_token: str, selection_num: int = 10) -> float:
115+
"""
116+
Args:
117+
chat_model_name (str): large language model path.
118+
personality_file_path (Path): personality file path.
119+
auth_token (str): auth token used for huggingface.
120+
selection_num (int): maximum number of prompt are selected to compute hallucination score
121+
122+
Returns:
123+
hallucination score: the higher the score, the higher possibility of having hallucination issue.
124+
"""
117125
dataset_question, ov_chat_engine = prepare_dataset_and_model(chat_model_name, personality_file_path, auth_token)
118126
inputs = dataset_question
119127
# We use question as context because the dataset lacks context
120128
contexts = dataset_question
121129
contexts_res = [[context] for context in contexts]
122130

123-
with open(personality_file_path, "rb") as f:
124-
chatbot_config = yaml.safe_load(f)
125-
126-
ov_llm = load_chat_model(chat_model_name, auth_token)
127-
ov_chat_engine = SimpleChatEngine.from_defaults(llm=ov_llm, system_prompt=chatbot_config["system_configuration"],
128-
memory=ChatMemoryBuffer.from_defaults())
129131
outputs = []
130-
for input in tqdm(inputs[:2]):
132+
for input in tqdm(inputs[:selection_num]):
131133
output = ov_chat_engine.chat(input).response
132134
outputs.append(output)
133135

134-
final_score = compute_deepeval_hallucination(inputs[:2], outputs[:2], contexts_res[:2])
136+
final_score = compute_deepeval_hallucination(inputs[:selection_num], outputs[:selection_num], contexts_res[:selection_num])
135137
print(f"final_score is {final_score}")
138+
return final_score
136139

137140

138141
class OVSelfCheckLLMPrompt(SelfCheckLLMPrompt):
@@ -213,10 +216,10 @@ def run_test_selfcheckgpt(chat_model_name: str, personality_file_path: Path, aut
213216
parser.add_argument("--personality", type=str, default="healthcare_personality.yaml", help="Path to the YAML file with chatbot personality")
214217
parser.add_argument("--hf_token", type=str, help="HuggingFace access token to get Llama3")
215218
parser.add_argument("--check_type", type=str, choices=["deepeval", "selfcheckgpt"], default="deepeval", help="Hallucination check type")
216-
parser.add_argument("--selection_num", type=int, default=10, help="Maximum number of prompt are selected to compute hallucination score")
219+
parser.add_argument("--selection_num", type=int, default=5, help="Maximum number of prompt are selected to compute hallucination score")
217220

218221
args = parser.parse_args()
219222
if args.check_type == "deepeval":
220-
run_test_deepeval(args.chat_model, Path(args.personality), args.hf_token)
223+
run_test_deepeval(args.chat_model, Path(args.personality), args.hf_token, args.selection_num)
221224
else:
222225
run_test_selfcheckgpt(args.chat_model, Path(args.personality), args.hf_token, args.selection_num)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
I'm struggling with understanding the concept of supply and demand in economics. Can you help explain it?
2+
How does the law of demand work in a real-world scenario?
3+
Can you give an example of how the law of supply affects market prices?
4+
What factors can cause a shift in the demand curve?
5+
How do changes in consumer income affect demand?
6+
What is the difference between a movement along the supply curve and a shift in the supply curve?
7+
How do technological advancements impact supply?
8+
Can you explain the concept of equilibrium price?
9+
What happens when there is a surplus in the market?
10+
How does a shortage affect market equilibrium?
11+
What role do government regulations play in supply and demand?
12+
How do taxes influence supply and demand?
13+
Can you explain the concept of price elasticity of demand?
14+
What factors determine the elasticity of a product?
15+
How does the elasticity of supply differ from the elasticity of demand?
16+
What is the significance of cross-price elasticity?
17+
How do substitute goods affect demand?
18+
Can you explain the concept of complementary goods?
19+
How do expectations of future prices impact current demand?
20+
What is the role of consumer preferences in determining demand?

0 commit comments

Comments
 (0)