Asilbek14 commited on
Commit
f6c62f1
·
verified ·
1 Parent(s): 8dba69a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -32,24 +32,26 @@ generator = pipeline(
32
  def format_prompt(chat_history, user_message, system_message, response_style):
33
  # Start with system message
34
  prompt = system_message + "\n\n"
35
-
36
- # Append previous conversation content only
37
  for turn in chat_history:
38
- prompt += f"{turn['content']}\n"
39
-
40
- # Append the new user message
41
- prompt += user_message
42
 
43
- # Optional: add response style instruction
 
 
 
44
  if response_style == "No explanation":
45
- prompt += " Provide only the answer."
46
  elif response_style == "Short explanation":
47
- prompt += " Provide a short one-sentence explanation."
48
  elif response_style == "Detailed explanation":
49
- prompt += " Provide a detailed explanation."
50
 
51
  return prompt
52
 
 
53
  # ---------------- CHAT FUNCTION ----------------
54
  def chat(user_message, chat_history, system_message, max_tokens, temperature, top_p, response_style):
55
  chat_history = chat_history or []
 
32
  def format_prompt(chat_history, user_message, system_message, response_style):
33
  # Start with system message
34
  prompt = system_message + "\n\n"
35
+
36
+ # Add only user messages (optional: you can also add last assistant reply if needed)
37
  for turn in chat_history:
38
+ if turn['role'] == 'user':
39
+ prompt += f"{turn['content']}\n"
 
 
40
 
41
+ # Add the new user message
42
+ prompt += f"{user_message}\n"
43
+
44
+ # Optionally instruct for explanation style
45
  if response_style == "No explanation":
46
+ prompt += " Answer concisely with no explanation."
47
  elif response_style == "Short explanation":
48
+ prompt += " Answer briefly with a one-sentence explanation."
49
  elif response_style == "Detailed explanation":
50
+ prompt += " Answer in detail with reasoning and examples."
51
 
52
  return prompt
53
 
54
+
55
  # ---------------- CHAT FUNCTION ----------------
56
  def chat(user_message, chat_history, system_message, max_tokens, temperature, top_p, response_style):
57
  chat_history = chat_history or []