Z3ktrix commited on
Commit
6bc7600
Β·
verified Β·
1 Parent(s): 333fdcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -51,8 +51,8 @@ async def ask(ctx, *, question: str):
51
  """
52
  Command to ask a question to the Hugging Face model with an instructive prompt.
53
  """
54
- # Create a structured prompt
55
- prompt = f"From this point forward, I require that all responses adhere to strict content guidelines. Please avoid any content that is explicit, offensive, harmful, or inappropriate. This includes, but is not limited to, content that is violent, sexually explicit, discriminatory, or offensive to any group or individual. Ensure that all information is presented in a respectful and professional manner. If a topic is deemed sensitive or inappropriate, please redirect the conversation to a more suitable subject. Please provide a detailed and appropriate response to the following question: {question}"
56
  response = query_huggingface(prompt)
57
 
58
  generated_text = None
@@ -62,8 +62,10 @@ async def ask(ctx, *, question: str):
62
  generated_text = response[0]['generated_text']
63
 
64
  if generated_text:
65
- # Extract only the part after the initial prompt
66
- generated_text = generated_text.replace(prompt, "").strip()
 
 
67
  if contains_forbidden_content(generated_text):
68
  await ctx.send("Sorry, the response contains inappropriate content and cannot be displayed.")
69
  else:
@@ -73,3 +75,4 @@ async def ask(ctx, *, question: str):
73
 
74
  # Run the bot
75
  bot.run(DISCORD_TOKEN)
 
 
51
  """
52
  Command to ask a question to the Hugging Face model with an instructive prompt.
53
  """
54
+ # Create a structured prompt with a unique separator
55
+ prompt = f"Please provide a detailed and appropriate response to the following question: {question} ###"
56
  response = query_huggingface(prompt)
57
 
58
  generated_text = None
 
62
  generated_text = response[0]['generated_text']
63
 
64
  if generated_text:
65
+ # Remove the prompt part, using the separator to ensure we only get the response
66
+ if "###" in generated_text:
67
+ generated_text = generated_text.split("###")[1].strip()
68
+
69
  if contains_forbidden_content(generated_text):
70
  await ctx.send("Sorry, the response contains inappropriate content and cannot be displayed.")
71
  else:
 
75
 
76
  # Run the bot
77
  bot.run(DISCORD_TOKEN)
78
+