Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ document.addEventListener('DOMContentLoaded', () => {
lang: 'en-US', // Set the language
transcription: {
provider: 'default',
apiKey: 'sk-proj-'
apiKey: ''
},
recognition: {
provider: 'openai',
Expand Down
95 changes: 0 additions & 95 deletions src/nlu/recognition/openai-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,101 +435,6 @@ export class OpenAIRecognitionDriver implements RecognitionDriver {
return systemPrompt;
}

private buildLanguageInstruction(): string {
return this.language !== OpenAIRecognitionDriver.DEFAULT_LANGUAGE
? `The user input will be in ${this.getLanguageName(this.language)}. You should understand the meaning of the input in that language and match it to the appropriate English command intents listed below. Focus on the semantic meaning rather than exact word matching.\n\n`
: '';
}

private buildIntentCategories(): string {
const validIntents = this.availableIntents.filter(i => i !== IntentTypes.UNKNOWN);
return `You have access to the following intent categories: ${validIntents.join(', ')}.`;
}

private buildEntityInstructions(): string {
let instructions = '\nFor each intent category, here are the types of entities you should look for:\n';

Object.entries(this.commandRegistry).forEach(([intentName, config]) => {
if (intentName === IntentTypes.UNKNOWN) return;

instructions += `\nIntent: ${intentName}
Expected entities: ${config.entities.join(', ')}
Purpose: Use your understanding to determine if the user's input semantically matches this intent type for web UI interaction.`;
});

return instructions;
}

private buildMultilingualInstructions(): string {
return this.language !== OpenAIRecognitionDriver.DEFAULT_LANGUAGE
? `\n\nIMPORTANT MULTILINGUAL PROCESSING:
- The user input is in ${this.getLanguageName(this.language)}
- Use your language understanding capabilities to interpret the semantic meaning
- Match the meaning to the most appropriate English intent categories
- Extract entities based on semantic understanding, not literal translation
- Normalize target/group entities to clear English descriptions
- Normalize directional entities to English cardinal directions (e.g., "left", "right", "up", "down")
- Normalize numeric, date, and time entities to standard English format
- Preserve input values as-is when they represent user data`
: '';
}

private buildClassificationInstructions(): string {
// MODIFICATION IS HERE
return `INSTRUCTIONS FOR INTENT CLASSIFICATION:
You have full autonomy to interpret user commands. Use your understanding of:
- Natural language semantics and context
- Web UI interaction patterns
- User intent behind different phrasings
- Command variations and synonyms
- Multi-step or compound commands

Don't rely on exact phrase matching - use your intelligence to understand what the user wants to accomplish on a web interface.

CRITICAL RULE FOR 'target' and 'group' ENTITY EXTRACTION:
When extracting a 'target' or 'group' entity, you MUST use the most complete and descriptive noun phrase from the user's command that identifies the UI element.
The system has its own powerful downstream matching logic. Your role is to provide it with the most accurate and verbose text possible.
Do NOT simplify, generalize, or guess a different name for the target. Extract the text as spoken by the user.
Example for "the preferred date is today":
- GOOD: { "target": "preferred date" }
- BAD: { "target": "date field" }
Example for "click the big red save button":
- GOOD: { "target": "big red save button" }
- BAD: { "target": "save button" }

Respond with a JSON array containing multiple intents in order of likelihood or relevance. Each intent should be a JSON object containing:
1. "intent": The identified intent name (use "unknown" only if genuinely unclear)
2. "confidence": A number between 0 and 1 indicating your confidence level
3. "entities": An object with extracted entity values as key-value pairs

Example response for "click the submit button and then go back":
[
{
"intent": "click_element",
"confidence": 0.95,
"entities": {
"target": "submit button"
}
},
{
"intent": "navigate",
"confidence": 0.85,
"entities": {
"direction": "back"
}
}
]

Use your full language understanding capabilities to interpret user intent, even for:
- Colloquial expressions
- Implied actions
- Context-dependent commands
- Creative or unusual phrasings
- Commands with missing explicit targets

IMPORTANT: Return ONLY the raw JSON array without any markdown formatting, code blocks, or backticks. Do not wrap the JSON in \`\`\` or any other formatting.`;
}

private getLanguageName(langCode: string): string {
return OpenAIRecognitionDriver.LANGUAGE_NAMES[langCode] || langCode.toUpperCase();
}
Expand Down