mirror of
https://git.squeakyrat.moe/faggot-chan/
synced 2026-11-04 18:35:45 +01:00
made it so it reads the system prompt and parameters from a file (this was vibecoded but it works so it's okay)
This commit is contained in:
1 parent
6271325fde
commit
6004eadd61
2 files changed
+10
-16
No files matched your search
@@ -18,7 +18,8 @@ def ignore_connection_closed_ok(loop, context): #this doesn't fucking work
|
|||||||
loop.default_exception_handler(context)
|
loop.default_exception_handler(context)
|
||||||
|
|
||||||
|
|
||||||
system_prompt = "you are a funny discord user that uses discrd"
|
def load_system_prompt() -> str:
|
||||||
|
return Path("system_prompt.txt").read_text(encoding="utf-8")
|
||||||
|
|
||||||
FILES_DIR = Path("files")
|
FILES_DIR = Path("files")
|
||||||
LOG_DIR = FILES_DIR / "log"
|
LOG_DIR = FILES_DIR / "log"
|
||||||
@@ -91,13 +92,13 @@ def load_longterm() -> list[str]:
|
|||||||
log_error(f"[{timestamp()}] error reading longterm: {e}")
|
log_error(f"[{timestamp()}] error reading longterm: {e}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def build_payload(sys_prompt: str, user_input: str, rebuild: bool = False) -> str:
|
def build_payload(user_input: str, rebuild: bool = False) -> str:
|
||||||
global vector_db_ready
|
global vector_db_ready
|
||||||
should_rebuild = rebuild or not vector_db_ready # always rebuild on first ever message
|
should_rebuild = rebuild or not vector_db_ready # always rebuild on first ever message
|
||||||
if should_rebuild:
|
if should_rebuild:
|
||||||
vector_db_ready = True
|
vector_db_ready = True
|
||||||
return json.dumps({
|
return json.dumps({
|
||||||
"system_prompt": sys_prompt,
|
"system_prompt": load_system_prompt(),
|
||||||
"user_input": user_input,
|
"user_input": user_input,
|
||||||
"shortterm": load_shortterm(),
|
"shortterm": load_shortterm(),
|
||||||
"longterm": load_longterm(),
|
"longterm": load_longterm(),
|
||||||
@@ -184,7 +185,6 @@ async def random_dm():
|
|||||||
continue
|
continue
|
||||||
victim = random.choice(members)
|
victim = random.choice(members)
|
||||||
payload = build_payload(
|
payload = build_payload(
|
||||||
system_prompt,
|
|
||||||
f"System: you are sending a dm to {victim}, write a long, playful story or an over-the-top pun monologue about anything. "
|
f"System: you are sending a dm to {victim}, write a long, playful story or an over-the-top pun monologue about anything. "
|
||||||
"It should sound like something faggot-chan would post when she's bored — chaotic, funny, and full of personality (at least 20 words)."
|
"It should sound like something faggot-chan would post when she's bored — chaotic, funny, and full of personality (at least 20 words)."
|
||||||
"keep in mind this is a dm so make it a bit personal"
|
"keep in mind this is a dm so make it a bit personal"
|
||||||
@@ -215,7 +215,6 @@ async def random_message():
|
|||||||
channel = discord.utils.get(guild.text_channels, name="general")
|
channel = discord.utils.get(guild.text_channels, name="general")
|
||||||
if channel:
|
if channel:
|
||||||
payload = build_payload(
|
payload = build_payload(
|
||||||
system_prompt,
|
|
||||||
"System: write a long, playful story or an over-the-top pun monologue about cheese. or anything random"
|
"System: write a long, playful story or an over-the-top pun monologue about cheese. or anything random"
|
||||||
"it should sound like something faggot-chan would post when she's bored."
|
"it should sound like something faggot-chan would post when she's bored."
|
||||||
"chaotic, funny, and full of personality (at least 15 words and no more than 20)"
|
"chaotic, funny, and full of personality (at least 15 words and no more than 20)"
|
||||||
@@ -361,7 +360,7 @@ async def on_message(message):
|
|||||||
user_input = f'{message.author} replied to {replied_message.author} saying: "{replied_content}" with reply: "{content}"'
|
user_input = f'{message.author} replied to {replied_message.author} saying: "{replied_content}" with reply: "{content}"'
|
||||||
else:
|
else:
|
||||||
user_input = f"{message.author} said in DM: {content}"
|
user_input = f"{message.author} said in DM: {content}"
|
||||||
payload = build_payload(system_prompt, user_input, rebuild)
|
payload = build_payload(user_input, rebuild)
|
||||||
stop_typing = asyncio.Event()
|
stop_typing = asyncio.Event()
|
||||||
asyncio.create_task(keep_typing(message.channel, stop_typing))
|
asyncio.create_task(keep_typing(message.channel, stop_typing))
|
||||||
ok, result = await call_main(payload)
|
ok, result = await call_main(payload)
|
||||||
@@ -392,7 +391,7 @@ async def on_message(message):
|
|||||||
else:
|
else:
|
||||||
user_input = f"{message.author} said: {content}"
|
user_input = f"{message.author} said: {content}"
|
||||||
|
|
||||||
payload = build_payload(system_prompt, user_input, rebuild)
|
payload = build_payload(user_input, rebuild)
|
||||||
stop_typing = asyncio.Event()
|
stop_typing = asyncio.Event()
|
||||||
asyncio.create_task(keep_typing(message.channel, stop_typing))
|
asyncio.create_task(keep_typing(message.channel, stop_typing))
|
||||||
ok, result = await call_main(payload)
|
ok, result = await call_main(payload)
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import json
|
|||||||
import re # thank you claude
|
import re # thank you claude
|
||||||
import ollama
|
import ollama
|
||||||
import websockets
|
import websockets
|
||||||
|
from pathlib import Path
|
||||||
from websockets.server import serve
|
from websockets.server import serve
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
chatmodel = "hf.co/Stetsoncody/Llama-3.2-3B-Instruct-abliterated-GGUF:Q4_K_M"
|
chatmodel = "hf.co/Stetsoncody/Llama-3.2-3B-Instruct-abliterated-GGUF:Q4_K_M"
|
||||||
embedmodel = 'hf.co/CompendiumLabs/bge-base-en-v1.5-gguf'
|
embedmodel = 'hf.co/CompendiumLabs/bge-base-en-v1.5-gguf'
|
||||||
|
|
||||||
NUM_THREADS = 6 # hardcoded since threads.txt is gone, change if needed
|
|
||||||
|
|
||||||
def times() -> str:
|
def times() -> str:
|
||||||
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
@@ -151,17 +151,12 @@ async def ollamachat(websocket):
|
|||||||
|
|
||||||
messages.insert(0, {"role": "system", "content": system_prompt + rag_block})
|
messages.insert(0, {"role": "system", "content": system_prompt + rag_block})
|
||||||
|
|
||||||
|
params = json.loads(Path("config/params.json").read_text())
|
||||||
|
|
||||||
response = ollama.chat(
|
response = ollama.chat(
|
||||||
model=chatmodel,
|
model=chatmodel,
|
||||||
messages=messages,
|
messages=messages,
|
||||||
options={
|
options=params,
|
||||||
"temperature": 0.83,
|
|
||||||
"top_p": 0.9,
|
|
||||||
"top_k": 40,
|
|
||||||
"repeat_penalty": 1.1,
|
|
||||||
"num_predict": 1024,
|
|
||||||
"num_thread": NUM_THREADS,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# strip <think> blocks in case the model ignores think=False, thank you claude
|
# strip <think> blocks in case the model ignores think=False, thank you claude
|
||||||
|
|||||||
Reference in new issue
Block a user