Skip to content

Commit

Permalink
better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoudz committed Mar 26, 2024
1 parent 7414e1a commit 9da665f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/core/vuic.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ class Vuic extends EventEmitter {
})
.then((response) => response.json())
.then((data) => this._handleProcessedVoiceCommandResponse(data))
.catch((error) => console.error('Error:', error));
.catch((error) => console.error('API Error:', error));
};

_handleProcessedVoiceCommandResponse = (response) => {
console.log('--[VUIC]-- _handleProcessedVoiceCommandResponse');
console.log('@ RAW RESPONSE:', response);
console.log('--[VUIC]-- RAW RESPONSE:', response);

if (!response || !response.executableFunctions) {
console.error('Invalid response format:', response);
Expand Down Expand Up @@ -189,49 +189,54 @@ class Vuic extends EventEmitter {
console.log('--[VUIC]-- _executeFunctions');

if (!message || !message.tool_calls) {
console.error('Invalid message format:', message);
console.error('E1: Invalid API response:', message);
return;
}

message.tool_calls.forEach((toolCall) => {

if (!toolCall.function || !toolCall.function.name) {
console.error('Invalid tool call format:', toolCall);
console.error('E2: Invalid API response:', toolCall);
return;
}

const functionName = toolCall.function.name;
const functionToCall = this.functionReferences[functionName];

if (!functionToCall) {
console.error('No function found for name:', functionName);
return;
console.error(`Function '${functionName}' not found. Ensure you've registered the function in 'registerFunctions'. See docs https://docs.sista.ai`);
return;
}

let functionArgs = {};
try {
functionArgs = JSON.parse(toolCall.function.arguments);
} catch (error) {
console.error('Failed to parse function arguments:', error);
console.error('E3: Invalid API response:', error);
return;
}

const functionArgsArray = Object.values(functionArgs);
try {
functionToCall(...functionArgsArray);
} catch (error) {
console.error(`Error executing function ${functionName}:`, error);
console.error(`Error calling function ${functionName}:`, error);
}
});
};

_executeTextReply = (content) => {
console.log('YOW:', content);
console.log('--[VUIC]-- _executeTextReply');
console.log('AI Reply:', content);
};

playSound(soundFile, volume = 0.20) {
console.log('--[VUIC]-- playSound');

let audio = new Audio(soundFile);
audio.volume = volume;
audio.play();

return audio;
}

Expand Down

0 comments on commit 9da665f

Please sign in to comment.