Z3ktrix commited on
Commit
b168951
Β·
verified Β·
1 Parent(s): ef5624b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -45,13 +45,19 @@ async def ask(ctx, *, question: str):
45
  prompt = f"Please provide a detailed response to the following question: {question}"
46
  await ctx.send(f"Question: {question}")
47
  response = query_huggingface(prompt)
48
- if 'generated_text' in response:
49
- await ctx.send(f"Response: {response['generated_text']}")
 
 
50
  elif isinstance(response, list) and len(response) > 0 and 'generated_text' in response[0]:
51
- await ctx.send(f"Response: {response[0]['generated_text']}")
52
  else:
53
- await ctx.send("Sorry, I couldn't generate a response.")
 
 
 
 
 
54
 
55
  # Run the bot
56
  bot.run(DISCORD_TOKEN)
57
-
 
45
  prompt = f"Please provide a detailed response to the following question: {question}"
46
  await ctx.send(f"Question: {question}")
47
  response = query_huggingface(prompt)
48
+
49
+ # Extract and clean the response
50
+ if isinstance(response, dict) and 'generated_text' in response:
51
+ response_text = response['generated_text']
52
  elif isinstance(response, list) and len(response) > 0 and 'generated_text' in response[0]:
53
+ response_text = response[0]['generated_text']
54
  else:
55
+ response_text = "Sorry, I couldn't generate a response."
56
+
57
+ # Remove the prompt from the response if present
58
+ clean_response = response_text.replace(prompt, '').strip()
59
+
60
+ await ctx.send(f"Response: {clean_response}")
61
 
62
  # Run the bot
63
  bot.run(DISCORD_TOKEN)