Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
49 |
-
|
|
|
|
|
50 |
elif isinstance(response, list) and len(response) > 0 and 'generated_text' in response[0]:
|
51 |
-
|
52 |
else:
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
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)
|
|