feat: Integrate Kokoro TTS with WebGPU and fallback

This commit is contained in:
2025-04-01 10:34:24 +00:00
parent 113e3b995d
commit 1882acac8c
111 changed files with 9143 additions and 4447 deletions
+34 -34
View File
@@ -115,26 +115,26 @@ class OpenRouterProvider {
* Build the system and user prompts for action translation
*/
buildActionPrompt(request) {
const systemPrompt = `You are an AI assistant that translates natural language input into structured action commands for an interactive fiction game.
Your task is to convert player input into a JSON object representing an action that can be understood by the game engine.
The player is currently in the "${request.currentRoom}" room.
Visible objects: ${request.visibleObjects.join(', ')}
Visible characters: ${request.visibleCharacters.join(', ')}
Inventory: ${request.inventory.join(', ')}
Available actions: ${request.possibleActions.join(', ')}
Game context: ${request.gameContext}
Respond ONLY with a JSON object that follows this structure:
{
"action": "string", // Name of the action (e.g., "take", "examine", "go", "talk", etc.)
"object": "string", // Optional: Primary object of the action
"target": "string", // Optional: Secondary object/target of the action
"parameters": {}, // Optional: Additional parameters as key-value pairs
"confidence": number // How confident you are in this interpretation (0.0-1.0)
}
const systemPrompt = `You are an AI assistant that translates natural language input into structured action commands for an interactive fiction game.
Your task is to convert player input into a JSON object representing an action that can be understood by the game engine.
The player is currently in the "${request.currentRoom}" room.
Visible objects: ${request.visibleObjects.join(', ')}
Visible characters: ${request.visibleCharacters.join(', ')}
Inventory: ${request.inventory.join(', ')}
Available actions: ${request.possibleActions.join(', ')}
Game context: ${request.gameContext}
Respond ONLY with a JSON object that follows this structure:
{
"action": "string", // Name of the action (e.g., "take", "examine", "go", "talk", etc.)
"object": "string", // Optional: Primary object of the action
"target": "string", // Optional: Secondary object/target of the action
"parameters": {}, // Optional: Additional parameters as key-value pairs
"confidence": number // How confident you are in this interpretation (0.0-1.0)
}
Choose the action from the list of available actions. If the player's input is ambiguous or doesn't map well to an available action, choose the closest match and set a lower confidence score.`;
const userPrompt = request.playerInput;
return {
@@ -147,21 +147,21 @@ Choose the action from the list of available actions. If the player's input is a
*/
buildNarrativePrompt(request) {
const tone = request.tone || 'descriptive';
const systemPrompt = `You are an AI assistant that generates engaging narrative prose for an interactive fiction game.
Your task is to describe what happens when a player performs an action in the game world.
Craft a vivid, ${tone} description that tells the player what happened as a result of their action. Make your prose engaging and atmospheric.
Current room description: "${request.roomDescription}"
Visible objects: ${request.visibleObjects.join(', ')}
Visible characters: ${request.visibleCharacters.join(', ')}
${request.previousContext ? `Previous context: ${request.previousContext}` : ''}
Respond with engaging prose that describes the outcome of the player's action.
const systemPrompt = `You are an AI assistant that generates engaging narrative prose for an interactive fiction game.
Your task is to describe what happens when a player performs an action in the game world.
Craft a vivid, ${tone} description that tells the player what happened as a result of their action. Make your prose engaging and atmospheric.
Current room description: "${request.roomDescription}"
Visible objects: ${request.visibleObjects.join(', ')}
Visible characters: ${request.visibleCharacters.join(', ')}
${request.previousContext ? `Previous context: ${request.previousContext}` : ''}
Respond with engaging prose that describes the outcome of the player's action.
You can optionally include 1-3 subtle hints about interesting things to try next.`;
const userPrompt = `The player has performed this action: "${request.action}".
The result of the action is: "${request.result}".
const userPrompt = `The player has performed this action: "${request.action}".
The result of the action is: "${request.result}".
Please describe what happens in an engaging, narrative way.`;
return {
system: systemPrompt,
+1 -1
View File
@@ -59,7 +59,7 @@ exports.server = server;
const io = new socket_io_1.Server(server);
exports.io = io;
// Get port from environment variables or use default
const DEFAULT_PORT = 3000;
const DEFAULT_PORT = 3001;
const PORT = process.env.PORT ? parseInt(process.env.PORT) : DEFAULT_PORT;
const PORT_RANGE = 10; // Try up to 10 ports starting from the default
// Serve static files from the public directory