ervijayraghuwanshi commited on
Commit
9aba8de
1 Parent(s): 6841cf8

Update app.py

Browse files

updating prompt

Files changed (1) hide show
  1. app.py +49 -1
app.py CHANGED
@@ -5,7 +5,7 @@ client = InferenceClient(
5
  "mistralai/Mistral-7B-Instruct-v0.2"
6
  )
7
 
8
-
9
  def format_prompt(message, history):
10
  prompt = "<s>"
11
  for user_prompt, bot_response in history:
@@ -13,6 +13,54 @@ def format_prompt(message, history):
13
  prompt += f" {bot_response}</s> "
14
  prompt += f"[INST] {message} [/INST]"
15
  return prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  def generate(
18
  prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
 
5
  "mistralai/Mistral-7B-Instruct-v0.2"
6
  )
7
 
8
+ """
9
  def format_prompt(message, history):
10
  prompt = "<s>"
11
  for user_prompt, bot_response in history:
 
13
  prompt += f" {bot_response}</s> "
14
  prompt += f"[INST] {message} [/INST]"
15
  return prompt
16
+ """
17
+
18
+ def format_prompt(message, history):
19
+ """
20
+ Formats a prompt for the chatbot based on history and a provided template.
21
+
22
+ Args:
23
+ message (str): The user's current message.
24
+ history (list): A list of tuples containing past user prompts and bot responses.
25
+
26
+ Returns:
27
+ str: The formatted prompt for the chatbot.
28
+ """
29
+
30
+ prompt = "<s>[INST]\n" # Newline after opening prompt tag for readability
31
+
32
+ # Introduction (replace placeholders with actual content if needed)
33
+ prompt += f"""**Introduction:**
34
+
35
+ Hi there! I'm Bard, your friendly AI assistant. I'm conducting a product survey
36
+ to understand customer preferences for recently purchased items.
37
+
38
+ This survey focuses on phones. Could you tell me a bit about the phone you
39
+ recently purchased?
40
+ \n"""
41
+
42
+ # Add past conversation history
43
+ for user_prompt, bot_response in history:
44
+ prompt += f"[INST] {user_prompt} [/INST]\n{bot_response}\n"
45
+
46
+ # Add current user message
47
+ prompt += f"[INST] {message} [/INST]\n"
48
+
49
+ # Prompt continuation based on current survey stage
50
+ # (Replace with your logic to determine the next question based on history)
51
+ current_question = len(history) + 1
52
+ if current_question == 1:
53
+ prompt += "1. What type of phone did you purchase (brand and model)?"
54
+ elif current_question == 2:
55
+ prompt += "2. Where did you buy your phone from (online store or physical store)?"
56
+ # ... Add logic for remaining questions (3-13) ...
57
+ else:
58
+ prompt += "Thank you for your participation! The survey is now complete."
59
+
60
+ prompt += "\n[/INST]</s>" # Closing prompt and tags
61
+
62
+ return prompt
63
+
64
 
65
  def generate(
66
  prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,