f9b9785857
When a player creates a game without pasting their own adventure, the DM previously improvised turn-by-turn with no overall arc, ending, or calibrated difficulty. Now the setup-chat interview generates a full outline (hook, three-to-four-part structure, milestone leveling, explicit ending condition, GM guidance) as a follow-up LLM call once genre/length/experience are known, and feeds it through the existing adventure_text -> RAG ingestion -> "follow strictly" pipeline exactly like a pasted adventure. Falls back silently to today's improvised behavior if generation fails. Verified end-to-end in the browser: setup interview -> outline generated and previewed -> game created -> RAG chunks ingested -> has_adventure true -> cascade-cleaned on delete. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
34 lines
973 B
Python
34 lines
973 B
Python
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
from openai import AsyncOpenAI
|
|
|
|
from app.config import settings
|
|
|
|
PROMPTS_DIR = Path(__file__).parent / "prompts"
|
|
|
|
|
|
@lru_cache
|
|
def get_dm_system_prompt() -> str:
|
|
return (PROMPTS_DIR / "dm_system_prompt.txt").read_text(encoding="utf-8")
|
|
|
|
|
|
@lru_cache
|
|
def get_game_setup_prompt() -> str:
|
|
return (PROMPTS_DIR / "game_setup_prompt.txt").read_text(encoding="utf-8")
|
|
|
|
|
|
@lru_cache
|
|
def get_adventure_outline_prompt() -> str:
|
|
return (PROMPTS_DIR / "adventure_outline_prompt.txt").read_text(encoding="utf-8")
|
|
|
|
|
|
@lru_cache
|
|
def get_llm_client() -> AsyncOpenAI:
|
|
if settings.llm_provider == "lmstudio":
|
|
# LM Studio's local server accepts any non-empty string when no key is configured.
|
|
return AsyncOpenAI(
|
|
api_key=settings.lmstudio_api_key or "lm-studio", base_url=settings.lmstudio_base_url
|
|
)
|
|
return AsyncOpenAI(api_key=settings.xai_api_key, base_url=settings.xai_base_url)
|