From e5358562f4cf96d4633630499e63b193b7b62866 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Fri, 16 Feb 2024 22:11:48 +0200 Subject: [PATCH] logs --- agent-mobile/artimobile/VoiceHandler.js | 48 +++++++++++++------------ web/server.js | 2 +- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/agent-mobile/artimobile/VoiceHandler.js b/agent-mobile/artimobile/VoiceHandler.js index 0ab7efc..18ebffb 100644 --- a/agent-mobile/artimobile/VoiceHandler.js +++ b/agent-mobile/artimobile/VoiceHandler.js @@ -54,30 +54,14 @@ class VoiceHandler extends Component { onSpeechResults(e) { this.setState({ results: e.value, - recognized: recognized + " " + e.value, - status: this.state.status+ "\nonSpeechResults():" + e.value + // recognized: recognized + " " + e.value, + // status: this.state.status+ "\nonSpeechResults():" + e.value }); - this.logRemote("onSpeechResults():" + e.value); + this.logRemote("onSpeechResults():" + e.value.join(' ')); } - async logRemote(message){ - try{ - fetch(process.env.LOG_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({"message":message}), - }); - } - catch(e){ - console.log("error logging:" + e); - } - console.log( message ); - } - async _startRecognizing(e) { this.setState({ recognized: '', @@ -99,18 +83,20 @@ class VoiceHandler extends Component { async _stopRecognizing() { try { await Voice.stop(); + const input = this.state.results.join(' ') this.setState({ isRecording: false, isProcessing:true, - recognized: this.state.results.join(' ') + recognized: input }); // Assuming you have the audio data, send it to your backend // this._sendTranscribedTextToLLM("who is the president of thr USA"); - this._sendTranscribedTextToLLM(this.state.results.join(' ')); + this._sendTranscribedTextToLLM(input); } catch (e) { console.error(e); } } + async _sendTranscribedTextToLLM(transcribedText) { const model = "openhermes:latest"; @@ -145,7 +131,7 @@ class VoiceHandler extends Component { // Update your app state or UI based on LLM response this.setState(prevState => ({ status: "LLM responded", - results: [...prevState.results, responseJson.message.content], // Append the response to the existing results + response: [...prevState.response, responseJson.message.content], // Append the response to the existing results })); } } else { @@ -188,6 +174,22 @@ class VoiceHandler extends Component { console.error('Failed to send audio:', error); }); } + + async logRemote(message){ + try{ + fetch(process.env.LOG_ENDPOINT, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({"message":message}), + }); + } + catch(e){ + console.log("error logging:" + e); + } + console.log( message ); + } render() { return ( @@ -206,6 +208,8 @@ class VoiceHandler extends Component { {r} ))} + + AI: ); } diff --git a/web/server.js b/web/server.js index 7a85922..0be2a4e 100644 --- a/web/server.js +++ b/web/server.js @@ -120,7 +120,7 @@ app.get('/', (req, res) => { //accept LOG messages on /log app.post('/log', (req, res) => { - console.log("log>" + req.body.message); + console.log("log["+new Date().toISOString() + '] ' + req.body.message); res.send('OK', 200, { 'Content-Type': 'text/plain' }); });