Compare commits
No commits in common. "f5a2192a258a0059ba13ea6f631306e2a3050aee" and "f8512ad91e910f339b25ee79afa37ca70fc89b9f" have entirely different histories.
f5a2192a25
...
f8512ad91e
2 changed files with 7 additions and 50 deletions
54
app.py
54
app.py
|
|
@ -2,7 +2,6 @@ import os
|
|||
import select
|
||||
import sys
|
||||
import time
|
||||
import unicodedata
|
||||
from collections import deque
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
|
|
@ -54,9 +53,7 @@ TOOL_REGISTRY = {
|
|||
"module": "intelligent_tool",
|
||||
"class": "IntelligentCommunicationTool",
|
||||
"kwargs": {
|
||||
"model": os.environ.get(
|
||||
"MISTLE_LLM_MODEL", "mistral/mistral-small"
|
||||
)
|
||||
"model": os.environ.get("MISTLE_LLM_MODEL", "mistral/mistral-small")
|
||||
},
|
||||
"description": "Uses an LLM to craft a polite reply to private tells.",
|
||||
},
|
||||
|
|
@ -64,9 +61,7 @@ TOOL_REGISTRY = {
|
|||
"module": "intelligent_tool",
|
||||
"class": "IntelligentCommunicationTool",
|
||||
"kwargs": {
|
||||
"model": os.environ.get(
|
||||
"MISTLE_LLM_MODEL", "mistral/mistral-small"
|
||||
)
|
||||
"model": os.environ.get("MISTLE_LLM_MODEL", "mistral/mistral-small")
|
||||
},
|
||||
"description": "Alias of 'intelligent'. Uses an LLM to craft a polite reply to private tells.",
|
||||
},
|
||||
|
|
@ -79,38 +74,6 @@ TOOL_DESCRIPTIONS = {
|
|||
from telnetclient import TelnetClient
|
||||
|
||||
|
||||
_UMLAUT_TRANSLATION = str.maketrans(
|
||||
{
|
||||
"ä": "ae",
|
||||
"ö": "oe",
|
||||
"ü": "ue",
|
||||
"Ä": "Ae",
|
||||
"Ö": "Oe",
|
||||
"Ü": "Ue",
|
||||
"ß": "ss",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def sanitize_for_mud(text: str) -> str:
|
||||
"""Return ASCII-only text suitable for Silberland's input parser."""
|
||||
if not text:
|
||||
return ""
|
||||
|
||||
replaced = text.translate(_UMLAUT_TRANSLATION)
|
||||
normalized = unicodedata.normalize("NFKD", replaced)
|
||||
cleaned: list[str] = []
|
||||
for ch in normalized:
|
||||
if unicodedata.combining(ch):
|
||||
continue
|
||||
code = ord(ch)
|
||||
if 32 <= code <= 126:
|
||||
cleaned.append(ch)
|
||||
else:
|
||||
cleaned.append("?")
|
||||
return "".join(cleaned)
|
||||
|
||||
|
||||
class SessionState:
|
||||
"""Share Telnet session state safely across threads."""
|
||||
|
||||
|
|
@ -150,9 +113,8 @@ class SessionState:
|
|||
self._listeners_lock = Lock()
|
||||
|
||||
def send(self, client: TelnetClient, message: str) -> None:
|
||||
sanitized = sanitize_for_mud(message)
|
||||
with self._send_lock:
|
||||
client.send(sanitized)
|
||||
client.send(message)
|
||||
|
||||
def tool_send(
|
||||
self,
|
||||
|
|
@ -163,14 +125,12 @@ class SessionState:
|
|||
stop_event: Event,
|
||||
) -> bool:
|
||||
"""Send on behalf of the tool while respecting a minimum cadence."""
|
||||
sanitized = sanitize_for_mud(message)
|
||||
|
||||
while not stop_event.is_set():
|
||||
with self._send_lock:
|
||||
now = time.time()
|
||||
elapsed = now - self._last_tool_send
|
||||
if elapsed >= min_interval:
|
||||
client.send(sanitized)
|
||||
client.send(message)
|
||||
self._last_tool_send = now
|
||||
return True
|
||||
wait_time = min_interval - elapsed
|
||||
|
|
@ -380,10 +340,10 @@ def login(
|
|||
state.update_output(banner)
|
||||
|
||||
if user:
|
||||
client.send(sanitize_for_mud(user))
|
||||
client.send(user)
|
||||
time.sleep(0.2)
|
||||
if password:
|
||||
client.send(sanitize_for_mud(password))
|
||||
client.send(password)
|
||||
|
||||
response = client.receive(timeout=response_timeout)
|
||||
if response:
|
||||
|
|
@ -454,7 +414,7 @@ def graceful_shutdown(
|
|||
if state:
|
||||
state.send(client, exit_command)
|
||||
else:
|
||||
client.send(sanitize_for_mud(exit_command))
|
||||
client.send(exit_command)
|
||||
farewell = client.receive(timeout=2.0)
|
||||
if farewell:
|
||||
print(farewell, end="" if farewell.endswith("\n") else "\n")
|
||||
|
|
|
|||
|
|
@ -22,9 +22,6 @@ class IntelligentCommunicationTool(Tool):
|
|||
system_prompt: str = (
|
||||
"Du bist Mistle, ein hilfsbereiter MUD-Bot. "
|
||||
"Antworte freundlich und knapp in deutscher Sprache."
|
||||
"Sprich informell und freundlich."
|
||||
"Antworte immer auf Deutsch."
|
||||
"Verwende emoticons, wenn es angebracht ist: :) ;) 8) :( ;( :P X) XD :D"
|
||||
)
|
||||
temperature: float = 0.7
|
||||
max_output_tokens: int = 120
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue