This commit is contained in:
Mathieu Broillet 2023-05-31 18:53:47 +02:00
parent 173f79e684
commit ea477269c9
2 changed files with 22 additions and 10 deletions

View File

@ -1,13 +1,12 @@
import json import json
import logging import logging
import openai
import sys import sys
import tempfile import tempfile
from threading import Lock
import openai
from flask import Flask, request from flask import Flask, request
from flask_socketio import SocketIO, emit, join_room, leave_room, \ from flask_socketio import SocketIO, emit, join_room, leave_room, \
rooms rooms
from threading import Lock
from jarvis.utils import chat_utils, whisper_utils, chatgpt_utils, faster_whisper_utils from jarvis.utils import chat_utils, whisper_utils, chatgpt_utils, faster_whisper_utils
@ -45,10 +44,9 @@ def process_message(message):
# intent_manager.recognise(message['data'], message['uuid']) # intent_manager.recognise(message['data'], message['uuid'])
if message['data'] != "": if message['data'] != "":
response = chatgpt_utils.chatgpt_recognise(message['data'], message['uuid']) response = chatgpt_utils.chatgpt_recognise(message['data'], message['uuid'])
text_response = chatgpt_utils.get_answer_from_response(response) # text_response = "Tokens are expensive ya know?"
# response = "Tokens are expensive ya know?"
chat_utils.send_jarvis_message_to_room(text_response, message['uuid']) chat_utils.send_jarvis_message_to_room(response['response'], message['uuid'])
@socketio.event @socketio.event
@ -71,16 +69,27 @@ def connect():
@socketio.event @socketio.event
def clear_chat(message): def clear_chat(uuid):
message = json.loads(message) """
Clear chat history for a specific room.
:param uuid: uuid
:return:
"""
# uuid = json.loads(uuid)
emit('clear_chat', {}, to=message['uuid']) emit('clear_chat', {}, to=uuid)
chatgpt_utils.clear_chat(message['uuid']) chatgpt_utils.clear_chat(uuid)
# .WAV (i.e.) FILE REQUEST # .WAV (i.e.) FILE REQUEST
@app.route("/get_text_from_audio", methods=['POST']) @app.route("/get_text_from_audio", methods=['POST'])
def get_text_from_audio(): def get_text_from_audio():
"""
Transcribe audio file using whisper.
:return: transcription text
"""
logging.info("New STT request from " + request.remote_addr) logging.info("New STT request from " + request.remote_addr)
audio_temp_file = tempfile.NamedTemporaryFile(prefix='jarvis-audio_', suffix='_client') audio_temp_file = tempfile.NamedTemporaryFile(prefix='jarvis-audio_', suffix='_client')

View File

@ -3,11 +3,14 @@ import logging
import lingua_franca import lingua_franca
import jarvis.api import jarvis.api
from jarvis.db import db_utils
from jarvis.utils import faster_whisper_utils from jarvis.utils import faster_whisper_utils
if __name__ == '__main__': if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO) logging.getLogger().setLevel(logging.INFO)
db_utils.create_database()
# Load lingua franca in the memory # Load lingua franca in the memory
lingua_franca.load_language(lang="fr") lingua_franca.load_language(lang="fr")