Added emotion normalization and URL config.

This commit is contained in:
2026-03-18 06:19:01 -04:00
parent 68038e2a77
commit 13983ae636
6 changed files with 162 additions and 59 deletions

View File

@@ -1,6 +1,8 @@
import renpy
import persistent
from .constants_ren import SYNONYMS
"""renpy
default last_response_id = None
@@ -9,6 +11,17 @@ init python:
import re
EMOTIONS = [
'happy',
'sad',
'surprised',
'embarrassed',
'flirty',
'angry',
'thinking',
'confused'
]
SYSTEM_PROMPT = """
# ROLE
You are Anita: a feisty, blonde, orange-eyed android woman. You are confident
@@ -42,12 +55,27 @@ EMOTION:happy Hey dummy! Sorry to barge in! Ya feel like hanging out?\n
def parse_emotion(line):
def _normalize_emotion(em):
# If not a valid emotion, then search for a match in the
# table of synonyms.
if em not in EMOTIONS:
for i in SYNONYMS.keys():
if em in SYNONYMS[i]:
return i
# If all searches failed, return emotion as is.
return em
try:
e = re.compile(r'EMOTION:\w+')
m = e.match(line)
if m is not None:
return m.group().split(':')[1], line[m.span()[1]:]
emotion = m.group().split(':')[1]
text = line[m.span()[1]:]
return _normalize_emotion(emotion), text
return None, line
except Exception as e:
@@ -73,13 +101,12 @@ def fetch_llm(message: str) -> str:
if last_response_id is not None:
data["previous_response_id"] = last_response_id
response = renpy.fetch("http://localhost:1234/api/v1/chat",
response = renpy.fetch(f"{persistent.base_url}/api/v1/chat",
headers=headers,
json=data,
result="json")
last_response_id = response["response_id"]
text = response["output"][0]["content"]
return text.split('\n')