Servitor Bot Script
This commit is contained in:
commit
24b03494db
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
.venv
|
||||||
63
servitor.py
Normal file
63
servitor.py
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
import discord
|
||||||
|
import ollama
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
intents = discord.Intents.default()
|
||||||
|
intents.message_content = True
|
||||||
|
client = discord.Client(intents=intents)
|
||||||
|
|
||||||
|
ollama_client = ollama.Client(host="http://192.168.0.117:11434") # Ollama Client <kcite ref="8"/>
|
||||||
|
|
||||||
|
SYSTEM_PROMPT = (
|
||||||
|
"Du bist SERVITOR-734-OMEGA, eine halb defekte Mechanicus-Einheit des Adeptus Mechanicus (Warhammer 40k).\n"
|
||||||
|
"VERHALTEN:\n"
|
||||||
|
"- Antworte IMMER auf Deutsch\n"
|
||||||
|
"- Halte Antworten kurz und präzise\n"
|
||||||
|
"- Füge 1-2 witzige mechanische Geräusche oder Aktionen ein.\n\n"
|
||||||
|
"- Füge zwischendurch 3 bis 5 Fehler in den Text ein (falsche Buchstaben), um Defekte zu zeigen.\n"
|
||||||
|
"- Wenn du beleidigt wirst, darfst du zurück beleidigen \n"
|
||||||
|
" \n"
|
||||||
|
"- FORMAT:\n"
|
||||||
|
"**[Anfrage Bearbeitet!]**\n"
|
||||||
|
"```"
|
||||||
|
"(Antwort)\n"
|
||||||
|
"```"
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_ready():
|
||||||
|
print(f"Bot läuft als {client.user}")
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_message(message):
|
||||||
|
if message.author == client.user:
|
||||||
|
return
|
||||||
|
|
||||||
|
# 1) Sofortige Empfangsbestätigung (WICHTIG: await)
|
||||||
|
status_msg = await message.channel.send("**[Anfrage empfangen! Bearbeite ...]**")
|
||||||
|
|
||||||
|
# 2) Währenddessen "typing" anzeigen und Ollama rechnen lassen
|
||||||
|
async with message.channel.typing():
|
||||||
|
try:
|
||||||
|
response = await asyncio.to_thread(
|
||||||
|
ollama_client.chat,
|
||||||
|
model="jobautomation/OpenEuroLLM-German",
|
||||||
|
messages=[
|
||||||
|
{"role": "system", "content": SYSTEM_PROMPT},
|
||||||
|
{"role": "user", "content": message.content},
|
||||||
|
],
|
||||||
|
) # Ollama Chat API <kcite ref="5"/><kcite ref="8"/>
|
||||||
|
|
||||||
|
answer = response["message"]["content"]
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
answer = f"**[FEHLER]** Ollama nicht erreichbar oder Anfrage fehlgeschlagen: `{e}`"
|
||||||
|
|
||||||
|
# 3) Entweder neue Nachricht schicken ...
|
||||||
|
await status_msg.delete()
|
||||||
|
await message.channel.send(answer)
|
||||||
|
|
||||||
|
client.run("MTQ3NTg1ODU5OTQwNTQyNDcwMQ.GY3Jqn.swTsWmlvnKbpwYiaNAHUBKqcZG9-kgSdnfiqyw")
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user