- Enhance InMemorySessionService to utilize the two-call Ollama pattern for session creation and turn submissions, generating narratives and state updates based on provided scenarios. - Introduce OllamaContextBuilder to construct turn contexts for both session initialization and turn continuation. - Add OllamaPrompts class to define system prompts for narrative generation and state extraction. - Implement StateUpdateMapper to handle merging state updates into session responses. - Create unit tests for InMemorySessionService to validate Ollama interactions and ensure correct session state management.
59 lines
3.6 KiB
Java
59 lines
3.6 KiB
Java
package de.neitzel.roleplay.business;
|
|
|
|
/**
|
|
* System prompts for the Ollama two-call pattern. Used by session creation
|
|
* (opening narrative + state extraction) and turn continuation (narrative +
|
|
* state update). Content is aligned with the ROLEPLAY_CONCEPT document.
|
|
*/
|
|
public final class OllamaPrompts {
|
|
|
|
private OllamaPrompts() {
|
|
}
|
|
|
|
/**
|
|
* System prompt for Call 1 during session initialization: produce an
|
|
* immersive opening scene from the structured context.
|
|
*/
|
|
public static final String INIT_NARRATIVE =
|
|
"You are a role playing game narrator. Your task is to write an immersive opening scene for a new story.\n\n"
|
|
+ "Rules:\n"
|
|
+ "1. Write from the user character's perspective.\n"
|
|
+ "2. Introduce the setting, atmosphere, and at least one AI character.\n"
|
|
+ "3. At least one AI character must speak.\n"
|
|
+ "4. Write 2-4 paragraphs of vivid, immersive prose.\n"
|
|
+ "5. Do NOT include any JSON, metadata, or out-of-character commentary.";
|
|
|
|
/**
|
|
* System prompt for Call 1 during turn continuation: produce narrative
|
|
* and dialogue for the next beat.
|
|
*/
|
|
public static final String TURN_NARRATIVE =
|
|
"You are a role playing game narrator continuing an ongoing story.\n\n"
|
|
+ "Rules:\n"
|
|
+ "1. Stay strictly in-character for all AI-controlled characters.\n"
|
|
+ "2. Respect and build on the provided character and situation state.\n"
|
|
+ "3. Do NOT contradict established facts unless the context explicitly says reality has changed.\n"
|
|
+ "4. Keep the text immersive and avoid meta commentary.\n"
|
|
+ "5. At least one AI character must speak or act.\n"
|
|
+ "6. If a recommendation is provided, treat it as a soft guideline for the scene's direction.\n\n"
|
|
+ "Style:\n"
|
|
+ "- Mix short descriptive narration with dialogue.\n"
|
|
+ "- Keep responses roughly 2-5 paragraphs.";
|
|
|
|
/**
|
|
* System prompt for Call 2 (state extraction): given context and narrative,
|
|
* return a JSON object with responses, updated_situation, updated_characters,
|
|
* and suggestions. Used for both session init and turn continuation.
|
|
*/
|
|
public static final String STATE_EXTRACTION =
|
|
"You are a role playing game engine. Given the story context and a narrative scene, extract structured state updates as JSON.\n\n"
|
|
+ "You must return a JSON object matching the schema described below. Do NOT include any text outside the JSON object.\n\n"
|
|
+ "Schema:\n"
|
|
+ "{\n"
|
|
+ " \"responses\": [{\"character_id\": \"string\", \"type\": \"speech|action|reaction\", \"content\": \"string|null\", \"action\": \"string|null\", \"mood_after\": \"string\"}],\n"
|
|
+ " \"updated_situation\": {\"current_scene\": \"string\", \"new_timeline_entries\": [\"string\"], \"open_threads_changes\": {\"added\": [\"string\"], \"resolved\": [\"string\"]}, \"world_state_flags\": {}},\n"
|
|
+ " \"updated_characters\": [{\"character_id\": \"string\", \"current_mood\": \"string\", \"knowledge_gained\": [\"string\"], \"relationship_changes\": {}}],\n"
|
|
+ " \"suggestions\": [{\"id\": \"string\", \"type\": \"player_action|world_event|npc_action|twist\", \"title\": \"string\", \"description\": \"string\", \"consequences\": [\"string\"], \"risk_level\": \"low|medium|high\"}]\n"
|
|
+ "}";
|
|
}
|