-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
47 lines (37 loc) · 1.3 KB
/
Copy pathutils.py
File metadata and controls
47 lines (37 loc) · 1.3 KB
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
import hashlib
import smtplib
from email.message import EmailMessage
import logging
import os
import re,json
import uuid
from database import DatabaseManager
logger = logging.getLogger(__name__)
# ---- CONFIG ----
MODEL_PATH = "/home/touti/models/gpt-oss-20b-fp16.gguf"
SESSIONS_DIR = os.path.join(os.path.dirname('__file__'), 'sessions')
def message_hash(text: str) -> str:
"""Generate a unique hash for a message based on text """
base = f"{text.strip()}"
return hashlib.sha256(base.encode("utf-8")).hexdigest()
def get_json_session_path(chat_id: str) -> str:
return os.path.join(SESSIONS_DIR, f"{chat_id}.json")
def get_state_path(chat_id: str) -> str:
return os.path.join(SESSIONS_DIR, f"{chat_id}.pkl")
def extract_final_message(raw_content: str) -> str:
"""
Extract only the final assistant message from the model output.
"""
pattern = r"<\|start\|>assistant<\|channel\|>final<\|message\|>(.*)"
match = re.search(pattern, raw_content, re.DOTALL)
if match:
# Clean leading/trailing whitespace
return match.group(1).strip()
return raw_content.strip() # fallback
def is_valid_uuid(id_value):
try:
uuid_obj = uuid.UUID(id_value, version=4)
assert str(uuid_obj) == id_value
return True
except ValueError:
return False