michailroussos commited on
Commit
584beb9
·
1 Parent(s): 6195f56
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -18,6 +18,8 @@ FastLanguageModel.for_inference(model) # Enable optimized inference
18
  def respond(message, history, system_message, max_tokens, temperature, top_p):
19
  # Add the system message and include previous conversation history
20
  messages = [{"role": "system", "content": system_message}]
 
 
21
  if history:
22
  for entry in history:
23
  messages.append({"role": "user", "content": entry["user"]})
@@ -46,28 +48,30 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
46
  )
47
  response = tokenizer.decode(generated_tokens[0], skip_special_tokens=True)
48
 
49
- # Clean the response to remove any unwanted system content (if any)
50
- response = response.replace("system", "").strip()
 
 
 
51
 
52
- # Update history
53
  if history is None:
54
  history = []
55
  history.append({"user": message, "assistant": response})
56
 
57
- print("history:")
58
- print(history)
59
 
60
- # Format history for Gradio (strictly enforce the role-content format)
61
  formatted_history = []
62
  for entry in history:
63
  formatted_history.append({"role": "user", "content": entry["user"]})
64
  formatted_history.append({"role": "assistant", "content": entry["assistant"]})
65
 
66
- print("formatted_history:")
67
- print(formatted_history)
68
- # Return formatted history
69
- return formatted_history
70
 
 
 
71
 
72
 
73
  # Define the Gradio interface
 
18
  def respond(message, history, system_message, max_tokens, temperature, top_p):
19
  # Add the system message and include previous conversation history
20
  messages = [{"role": "system", "content": system_message}]
21
+
22
+ # Append the previous conversation to the message context
23
  if history:
24
  for entry in history:
25
  messages.append({"role": "user", "content": entry["user"]})
 
48
  )
49
  response = tokenizer.decode(generated_tokens[0], skip_special_tokens=True)
50
 
51
+ # Debug: Print the raw assistant response
52
+ print("Raw Assistant Response:", response)
53
+
54
+ # Clean up the assistant response (strip out unwanted system info)
55
+ response = response.replace("Cutting Knowledge Date", "").replace("You are a helpful assistant.", "").strip()
56
 
57
+ # Update history with the new interaction
58
  if history is None:
59
  history = []
60
  history.append({"user": message, "assistant": response})
61
 
62
+ print("Updated History:", history)
 
63
 
64
+ # Format history for Gradio (enforcing role-content format)
65
  formatted_history = []
66
  for entry in history:
67
  formatted_history.append({"role": "user", "content": entry["user"]})
68
  formatted_history.append({"role": "assistant", "content": entry["assistant"]})
69
 
70
+ # Debug: Print the formatted history
71
+ print("Formatted History:", formatted_history)
 
 
72
 
73
+ # Return the formatted history
74
+ return formatted_history
75
 
76
 
77
  # Define the Gradio interface