Upload 2 files
Browse files- app.py +41 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import discord
|
| 3 |
+
from discord.ext import commands
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
+
|
| 6 |
+
# --- Hugging Face Client ---
|
| 7 |
+
client = InferenceClient(
|
| 8 |
+
provider="cerebras",
|
| 9 |
+
api_key=os.getenv("HF_TOKEN"),
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# --- Discord Bot Setup ---
|
| 13 |
+
intents = discord.Intents.default()
|
| 14 |
+
intents.message_content = True
|
| 15 |
+
|
| 16 |
+
bot = commands.Bot(command_prefix="!", intents=intents)
|
| 17 |
+
|
| 18 |
+
@bot.event
|
| 19 |
+
async def on_ready():
|
| 20 |
+
print(f"✅ Logged in as {bot.user}")
|
| 21 |
+
|
| 22 |
+
# --- Chat Command ---
|
| 23 |
+
@bot.command(name="ask")
|
| 24 |
+
async def ask(ctx, *, prompt: str):
|
| 25 |
+
try:
|
| 26 |
+
completion = client.chat.completions.create(
|
| 27 |
+
model="meta-llama/Llama-3.3-70B-Instruct",
|
| 28 |
+
messages=[
|
| 29 |
+
{"role": "user", "content": prompt}
|
| 30 |
+
],
|
| 31 |
+
max_tokens=500,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
reply = completion.choices[0].message.content
|
| 35 |
+
await ctx.reply(reply)
|
| 36 |
+
|
| 37 |
+
except Exception as e:
|
| 38 |
+
await ctx.reply(f"⚠️ Error: {e}")
|
| 39 |
+
|
| 40 |
+
# --- Run Bot ---
|
| 41 |
+
bot.run(os.getenv("DISCORD_TOKEN"))
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
discord.py
|
| 2 |
+
huggingface_hub
|