From 3c138f2b3b8e60be88751a5482acdbd6a5a669d5 Mon Sep 17 00:00:00 2001 From: Creat0r Date: Thu, 27 Nov 2025 18:18:43 +0100 Subject: [PATCH] first upload --- .gitignore | 3 ++ CloudGPT.openrc | 10 +++++ __pycache__/discord.cpython-313.pyc | Bin 0 -> 408 bytes __pycache__/skills.cpython-313.pyc | Bin 0 -> 1662 bytes bin/CloudGPT.py | 57 +++++++++++++++++++++++++ bin/__pycache__/skills.cpython-313.pyc | Bin 0 -> 1754 bytes bin/run.sh | 21 +++++++++ bin/skills.py | 50 ++++++++++++++++++++++ requirements.txt | 4 ++ 9 files changed, 145 insertions(+) create mode 100644 .gitignore create mode 100644 CloudGPT.openrc create mode 100644 __pycache__/discord.cpython-313.pyc create mode 100644 __pycache__/skills.cpython-313.pyc create mode 100644 bin/CloudGPT.py create mode 100644 bin/__pycache__/skills.cpython-313.pyc create mode 100644 bin/run.sh create mode 100644 bin/skills.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42541cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.venv +token.yaml +ollama-api.yaml \ No newline at end of file diff --git a/CloudGPT.openrc b/CloudGPT.openrc new file mode 100644 index 0000000..422d15b --- /dev/null +++ b/CloudGPT.openrc @@ -0,0 +1,10 @@ +#!/sbin/openrc-run + +name="$RC_SVCNAME" +command="/app/bin/run.sh" +command_background=true +pidfile="/run/$RC_SVCNAME" + +depend() { + need net +} diff --git a/__pycache__/discord.cpython-313.pyc b/__pycache__/discord.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..689ff217175258fbc9bac5238d44a8b1f6d5d744 GIT binary patch literal 408 zcmey&%ge<81Xq@+WYz)c#~=<2utFK1(}0Yr3^5ErOfV?~9RyQ_5MnTevWu958Df}o zSYT2ytUIEwkblduCoq zYF)S}e980Vb)(iHcAkQk^-^a?6(aoFVMrulpEM@NXa#@Uttix!N%8~)0neBc}00c&ILB}M&=?=5CH%< CR%x98 literal 0 HcmV?d00001 diff --git a/__pycache__/skills.cpython-313.pyc b/__pycache__/skills.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d69e82a6b5f0d633c74c3f706897caa797b3ca05 GIT binary patch literal 1662 zcmZ8hO>7fK6rTOD*IwI!-~<{V$uxn0+Y(4(hd6;&ZW<^*ArV_krCG_^*b{pj@2)#L z4#cOZhl-vGst^&U9I4s^haR|ct9shVMGD)r>d%Q2DY;bbrEfNNRr;iPZ{Ig>=FPnK z&F&@=Dgt@_;<$MvjL`4gX$$y)?5=~khcu)KR}ke^ydqo{sfdv#QAw9hwgO8LgmifT zX>vx`gNUGu;D@xZrsz@!8WYb5S|lsdkQP0RXjoH0D|$qWO@4@waR}B&AwJ$-PgOlO zfOG|h+Q!-zqq0yIQi>6& zK9(&JGMu@gX`fuR#)!5$Hk-ROF@8q-sBC=veq(U%>ebwAu8^C*RJby80~31%uNc%c z7OMo?4#O^CjRO_NYVPFe(@wQ&SjKSCvHV1?&MFQy8wN8SyP>>G3`!_YiN0KMT;?kk zVw4DVi><;0<>3XEVC;Sm>K^KY0_UN)!{TYd78ZgKuCDW#|A{8$1x?mMS;-c)a9*5( zd7~2{P052F0xv+IA#Gn%IC?CI2_?hvOF0R44D6Dygw9L-Xh}%L8b>eAe}Gp^1J4B|!t<+89UJd8$d~Ibp}aKIsS;l) zIyU2dJ5a8%Q;zFSj*OmJJXNeZ_0k21ide*TjWTilu*)bhEMI9MlykTK2B_a2Y`l2< zMLS!?V0f9BHo-ZY-E=6!WdhV#B9sj`4$n~PP|S?#vT2twb1cXqaz0<9j#Xnc23h?GC2q~JUE&MG<<-L={>AA@Jr6f@b<1E(f6pn_ zEx6yFTQLn+ubC?b)90yEriNvigc4hy=J$o8=lOtYyWGiuS{bVyS(8j&^&@ah%{@jjr?IHovbiVn` z^dsTx3lAr}ed(u>^xr!Yz<;>|aFkC+atM8^f_j3~+<^2%P2_r|Cx-<7-5Ub^3gvl` z0?NZwRp%z5eyB!Gn+2r=UIFidNI%i~C4kRQKZx0z{?fV#8;LV`;K2jctNhD8bmKV;gq zI`dWjyb8fL?Sa^@5bfnlf*VE7Sx%{5C2!Lcfbr6~HBit|LHH3xe?mPwDmpMLtabdX zbU#xMdWX(6)$^Ww{@3Wft!VF7;^>C*u){lX*6W+_;@Lk!k}9r+U+(V^GB1ZDp?_yT olH<1>OUZ{7jC1{??sFQyq9J5AKAJd^kAKKO4TOb^rhX literal 0 HcmV?d00001 diff --git a/bin/CloudGPT.py b/bin/CloudGPT.py new file mode 100644 index 0000000..dbeec08 --- /dev/null +++ b/bin/CloudGPT.py @@ -0,0 +1,57 @@ +import discord +from discord.ext import commands +import skills as skills +import asyncio +import yaml + +with open("token.yaml", "r") as yamlfile: + data = yaml.load(yamlfile, Loader=yaml.FullLoader) + +# ----------------------------- +# Discord Intents +# ----------------------------- +intents = discord.Intents.default() +intents.message_content = True + +bot = commands.Bot(command_prefix="!", intents=intents) + + +# ----------------------------- +# Events +# ----------------------------- +@bot.event +async def on_ready(): + print(f"Logged in as {bot.user} ✅") + +@bot.event +async def on_message(message): + # Bot ignoriert eigene Nachrichten + if message.author == bot.user: + return + + try: + # Wenn Nachricht ein Command ist, nur Commands verarbeiten + if message.content.startswith(bot.command_prefix): + await bot.process_commands(message) + return + + # Alles andere → skills.process_text + loop = asyncio.get_running_loop() + result = await loop.run_in_executor(None, skills.process_text, message.content) + + # Längere Ausgaben als Code-Block + if len(result) > 1900: + await message.channel.send(f"```\n{result}\n```") + else: + await message.channel.send(result) + + except Exception as e: + print(f"Error in on_message: {e}") + await message.channel.send(f"⚠️ Fehler: {e}") + + +# ----------------------------- +# Bot starten +# ----------------------------- + +bot.run(data[0]['token']) diff --git a/bin/__pycache__/skills.cpython-313.pyc b/bin/__pycache__/skills.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3cb87619a2afd272fa2ed5c4855ff40e57fb7ce8 GIT binary patch literal 1754 zcmZ8hO>7fK6rTO_+G{%@I6xsJ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ull -C /app + +if [ ! -d /app/.venv ]; +then + logger "generating python virtual-env" + python3 -m venv /app/.venv + echo '.venv' >> /app/.gitignore +fi + +source /app/.venv/bin/activate + +if [ -f /app/requirements.txt ]; +then + logger "updating python packages" + pip3 install -U -r /app/requirements.txt +fi + +logger "starting CloudGPT" +python3 /app/bin/CloudGPT.py 2>&1 | while IFS= read -r line; do logger "$line"; done diff --git a/bin/skills.py b/bin/skills.py new file mode 100644 index 0000000..43afabb --- /dev/null +++ b/bin/skills.py @@ -0,0 +1,50 @@ +import os +from ollama import Client +import yaml + +with open("ollama-api.yaml", "r") as yamlfile: + data = yaml.safe_load(yamlfile) + +# ----------------------------- +# Ollama Client +# ----------------------------- + +client = Client( + host="https://ollama.com", + headers={"Authorization": f"Bearer {data[0]['token']}"} +) + + +# ----------------------------- +# Ollama-Funktion +# ----------------------------- +def ask_ollama(prompt): + """GPT via Ollama Python Client""" + try: + messages = [{"role": "user", "content": prompt}] + response = client.chat("gpt-oss:120b-cloud", messages=messages, stream=False) + + # Absicherung: Prüfen ob key existiert + if "message" in response and "content" in response["message"]: + return response["message"]["content"] + elif "content" in response: + return response["content"] + else: + return "⚠️ Ollama hat keine Antwort geliefert." + except Exception as e: + return f"Error talking to GPT-oss: {str(e)}" + +# ----------------------------- +# Hauptfunktion zur Textverarbeitung +# ----------------------------- +def process_text(command): + command_lower = command.lower() + print("Command received:", command) + return ask_ollama(command) + +# ----------------------------- +# Lokaler Test +# ----------------------------- +if __name__ == "__main__": + user_input = input("Enter your command: ") + print(process_text(user_input)) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2d0bad1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +discord +pyyaml +ollama +asyncio