Spaces:
Runtime error
Runtime error
File size: 1,822 Bytes
496370a a29a66c c3c49d9 496370a c3c49d9 a29a66c c3c49d9 496370a c3c49d9 496370a c3c49d9 a29a66c 496370a c3c49d9 496370a c3c49d9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import os
import time
import socket
import requests
import discord
from discord import app_commands
def wait_for_internet(host="discord.com", port=443, timeout=60):
start = time.time()
while True:
try:
socket.getaddrinfo(host, port)
print("🌐 Internet ready")
return
except socket.gaierror:
if time.time() - start > timeout:
raise RuntimeError("❌ Internet not available")
print("⏳ Waiting for internet...")
time.sleep(5)
wait_for_internet()
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
HF_TOKEN = os.getenv("HF_TOKEN")
HF_MODEL = "mistralai/Mistral-7B-Instruct-v0.2"
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
def ask_llm(prompt: str) -> str:
headers = {
"Authorization": f"Bearer {HF_TOKEN}",
"Content-Type": "application/json"
}
payload = {
"inputs": f"Ответь философски:\n{prompt}"
}
r = requests.post(
f"https://api-inference.huggingface.co/models/{HF_MODEL}",
headers=headers,
json=payload,
timeout=60
)
if r.status_code != 200:
return "❌ LLM не ответил"
return r.json()[0]["generated_text"]
@tree.command(name="experiment", description="Философский эксперимент")
@app_commands.describe(question="Вопрос культу")
async def experiment(interaction: discord.Interaction, question: str):
await interaction.response.defer(thinking=True)
answer = ask_llm(question)
await interaction.followup.send(answer[:1900])
@client.event
async def on_ready():
await tree.sync()
print(f"🩸 CultCore online as {client.user}")
client.run(DISCORD_TOKEN) |