You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The socket server is not stable and the client.on('conversation.updated', fn) callback function sometimes didn't response with the item of 'assistant' role.
#93
exportconstinstructions=({ label, text })=>{constlanguage=label.split(' ').slice(1).join(' ');return`Instructions:- You are an artificial intelligence agent responsible for translating languages from audio to text- Please just repeat and translate what has been said and translate it- The conversations you hear will be in English and ${language}- When translating, make sure to translate the entire sentence, not just parts of it- If you cannot translate a word, leave it blank- So that all users can understand, respond in both English and ${language}- output everything said since the last translationPersonality:- NoneFormat:\`\`\`{ "source": "translated text", "dest": ${text}}\`\`\``;};
and the client.on('conversation.updated', fn) part:
client.on('conversation.updated',async({ item, delta }: any)=>{constitems=client.conversation.getItems();if(delta?.audio){wavStreamPlayer.add16BitPCM(delta.audio,item.id);}if(item.status==='completed'&&item.formatted.audio?.length){constwavFile=awaitWavRecorder.decode(item.formatted.audio,24000,24000);item.formatted.file=wavFile;}setItems(items);console.log(item);// the socket server sometimes didn't return item of 'assistant' roleif(item.role==='assistant'&&item.formatted.text){try{// check if ID is already in translationsif(item.id!==lastId){// parse the text into JSON-compatible formatconsttext=newString(item.formatted.text).replaceAll('```json','').replaceAll('```','')// replace all newlines with spaces.replaceAll('\n',' ');console.log({ text });consttranslationData=JSON.parse(text);lastId=item.id;if(translationData.source&&translationData.dest){setTranslations((prev)=>[...prev,translationData]);}}}catch(error){console.error('Failed to parse translation data:',error);}}});
The text was updated successfully, but these errors were encountered:
My instructions config file:
and the
client.on('conversation.updated', fn)
part:The text was updated successfully, but these errors were encountered: