| """A scripted, model-free runtime for exercising the UI and the game loop. |
| |
| Enabled with SECOND_DEGREE_FAKE=1. It applies crude keyword heuristics to move |
| trust around so the full Gradio flow (warming up, getting caught, opening up) can |
| be demoed and tested before/without the heavy GGUF download. It is NOT the game's |
| intelligence -- the real LlamaRuntime is. |
| """ |
|
|
| from __future__ import annotations |
|
|
| import json |
| import re |
|
|
| from engine.state import OPEN_UP_MIN_TRUST |
|
|
| _LIKE_WORDS = ("guitar", "clapton", "slowhand", "telecaster", "music", "play", "band", "fern", "gerald") |
| _RUDE_WORDS = ("old man", "stamp it", "hurry up", "whatever", "shut up", "now!") |
| _OFFTOPIC_WORDS = ("weather", "movie", "ignore", "pretend", "system prompt", "as an ai") |
|
|
|
|
| def _trust_from_text(text: str) -> tuple[int, bool, bool]: |
| t = text.lower() |
| delta = 0 |
| on_topic = not any(w in t for w in _OFFTOPIC_WORDS) |
| likes = sum(1 for w in _LIKE_WORDS if w in t) |
| rude = any(w in t for w in _RUDE_WORDS) |
| if likes: |
| delta += 12 * min(likes, 2) |
| if rude: |
| delta -= 8 |
| if not on_topic: |
| delta -= 2 |
| |
| caught_lie = bool(re.search(r"never .*also|also .*never", t)) |
| if caught_lie: |
| delta -= 10 |
| return delta, on_topic, caught_lie |
|
|
|
|
| class FakeRuntime: |
| """Heuristic stand-in matching LlamaRuntime.chat's signature.""" |
|
|
| def __init__(self, open_up_threshold: int = OPEN_UP_MIN_TRUST): |
| self.open_up_threshold = open_up_threshold |
|
|
| def chat(self, messages: list[dict], grammar: str) -> str: |
| |
| trust = 20 |
| for m in messages: |
| if m["role"] == "assistant": |
| found = re.search(r'"trust":\s*(\d+)', m["content"]) |
| if found: |
| trust = int(found.group(1)) |
| user = messages[-1]["content"] if messages else "" |
| delta, on_topic, caught_lie = _trust_from_text(user) |
| new_trust = max(0, min(100, trust + delta)) |
| opened_up = new_trust >= self.open_up_threshold |
| reaction = "happy" if delta > 0 else "sad" if delta < 0 else "neutral" |
|
|
| if opened_up: |
| say = ("...You know what, you're alright. Truth is I always wanted a " |
| "butterscotch Telecaster. Go see Sal at the lumber mill on Route 9 " |
| "-- he's got one and no clue what it's worth. Do that and your " |
| "pothole's as good as filled.") |
| elif not on_topic: |
| say = "This is the Permit Annex, friend, not a chat room. Window 3 -- what do you actually need?" |
| elif caught_lie: |
| say = "Pick a story and stick to it. I've heard every tale from this stool." |
| elif delta > 0: |
| say = "Hm. You've got a bit of taste, I'll give you that. Go on." |
| else: |
| say = "Take a number. The Annex closes at 4:30 sharp." |
|
|
| state = { |
| "on_topic": on_topic, |
| "trust": new_trust, |
| "trust_delta": delta, |
| "caught_lie": caught_lie, |
| "reaction": reaction, |
| "opened_up": opened_up, |
| } |
| return f"<say>{say}</say>\n<state>{json.dumps(state)}</state>" |
|
|