14/12/2024 - 14h

master
cherif 2024-12-14 14:06:21 +01:00
parent 3cea719d32
commit 262c86eb44
5 changed files with 2090 additions and 15 deletions

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="08/12/2024 - 12h">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="10/12/2024 - 22h">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tools_cherif/mysy_openai_file.py" beforeDir="false" afterPath="$PROJECT_DIR$/tools_cherif/mysy_openai_file.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -77,13 +77,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00368" summary="10/08/2024 - 20h32s">
<created>1723319219142</created>
<option name="number" value="00368" />
<option name="presentableId" value="LOCAL-00368" />
<option name="project" value="LOCAL" />
<updated>1723319219157</updated>
</task>
<task id="LOCAL-00369" summary="11/08/2024 - 12h32s">
<created>1723371666599</created>
<option name="number" value="00369" />
@ -420,7 +413,14 @@
<option name="project" value="LOCAL" />
<updated>1733655942463</updated>
</task>
<option name="localTasksCounter" value="417" />
<task id="LOCAL-00417" summary="10/12/2024 - 22h">
<created>1733865023238</created>
<option name="number" value="00417" />
<option name="presentableId" value="LOCAL-00417" />
<option name="project" value="LOCAL" />
<updated>1733865023239</updated>
</task>
<option name="localTasksCounter" value="418" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -462,7 +462,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="06/09/2024 - 22h" />
<MESSAGE value="08/09/2024 - 21h" />
<MESSAGE value="08/09/2024 - 21terth" />
<MESSAGE value="12/09/2024 - 13:00" />
@ -487,6 +486,7 @@
<MESSAGE value="22/11/2024 - 18h" />
<MESSAGE value="27/11/2024 : 12h30" />
<MESSAGE value="08/12/2024 - 12h" />
<option name="LAST_COMMIT_MESSAGE" value="08/12/2024 - 12h" />
<MESSAGE value="10/12/2024 - 22h" />
<option name="LAST_COMMIT_MESSAGE" value="10/12/2024 - 22h" />
</component>
</project>

View File

@ -779,3 +779,49 @@ EMAIL_MAX_PJ = 5
La clé API de OpenAI
"""
OPENAI_KEY = "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"
"""
Variable interne pour le traitement
des mysy_voice_to_text
"""
#Les collections autorisées pour les opérations voix
mysy_voice_instruction_related_collection = ['myclass', 'session_formation', 'parter_order_header', 'parter_order_line']
#Les mots de ponctuation vocale
mysy_voice_stop_word = ['stop', 'fin']
#Les champs autorisés par collection
mysy_voice_instruction_collection_field = {
"myclass": [
"Titre",
"Description",
"Programme"
],
"session_formation": [
"Titre",
"Debut",
"Fin"
]
}
#Les actions autorisées par collection
mysy_voice_instruction_collection_action = {
"myclass": [
{"créer": "create"}, {"création": "create"}, {"crée": "create"},
{"ajoute": "create"}, {"ajout": "create"}, {"nouvelle": "create"},
{"nouveau": "create"},
{"met à jour": "update"}, {"met a jour": "update"}, {"mettre à jour": "update"},
{"mettre a jour": "update"}, {"modifier": "update"}, {"modifie": "update"},
{"update":"update"} ,
],
"session_formation": [
{"créer": "create"}, {"création": "create"}, {"crée": "create"},
{"ajoute": "create"}, {"ajout": "create"}, {"nouvelle": "create"},
{"nouveau": "create"},
{"met à jour": "update"}, {"met a jour": "update"}, {"mettre à jour": "update"},
{"mettre a jour": "update"}, {"modifier": "update"}, {"modifie": "update"},
{"update":"update"} ,
]
}

File diff suppressed because it is too large Load Diff

20
main.py
View File

@ -11367,8 +11367,8 @@ def Get_Audio_File():
f.save(os.path.join(str("./temp_direct/test_audio_pr_IA.mp3")))
new_payload = {}
new_payload['voice_file'] = str(f.filename)
status, retval = mysy_openai_file.mysy_openai_voice_to_text(payload)
new_payload['voice_file'] = "temp_direct/test_audio_pr_IA.mp3"
status, retval = mysy_openai_file.mysy_openai_voice_to_text(new_payload)
status= True
@ -11376,6 +11376,22 @@ def Get_Audio_File():
return jsonify(status=status)
'''
API test gestion fichier blob audio
'''
@app.route('/myclass/api/Test_Get_Audio_File/', methods=['POST','GET'])
@crossdomain(origin='*')
def Test_Get_Audio_File():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### payload = ",payload)
status, retval = mysy_openai_file.test_mysy_openai_voice_to_text(payload)
return jsonify(status=status, message=retval)
@app.route('/myclass/api/mysy_openai_assistant/', methods=['POST','GET'])
@crossdomain(origin='*')
def mysy_openai_assistant():

View File

@ -95,6 +95,7 @@ def mysy_openai_voice_to_text(diction):
print(" ### Traitement du fichier audio : ", file_name)
"""
audio_file = open(file_name, "rb")
transcription = client.audio.transcriptions.create(
model="whisper-1",
@ -103,8 +104,12 @@ def mysy_openai_voice_to_text(diction):
)
requestion_response = transcription.text
"""
requestion_response = "OK, Missy, crée la formation avec le titre Je vais à la plage, stop. Description, comment aller à la plage, stop."
print(" ### AFFICHAGE GPT RESPONSE - mysy_openai_voice_to_text")
print(transcription.text)
print(requestion_response)
status, retval = mysy_openai_voice_to_text_traitement_1(requestion_response)
return True,requestion_response
@ -114,6 +119,292 @@ def mysy_openai_voice_to_text(diction):
return False, " Impossible de traiter : mysy_openai_voice_to_text"
def test_mysy_openai_voice_to_text(diction):
try:
working_text = ["Ok mysy, créer une formation .... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, création une formation .... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, crée une formation .... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, ajoute une formation .... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, ajout une formation .... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, nouvelle une formation .... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, met à jour formation code CCCCCC .... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, mettre à jour formation code CCCCCC.... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, update formation code CCCCCC.... stop . programme yyyyy stop objectifyyyyy stop ",
"Ok mysy, modifier formation code CCCCCC.... stop . Titre xxxxxx stop Descriptionxxxxx stop ",
"Ok mysy, modifie formation code CCCCCC.... stop . Titre xxxxxx stop Descriptionxxxxx stop "]
for text in working_text :
status, retval, message_id = mysy_openai_voice_to_text_traitement_1(text)
return True, "Ok"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de traiter : test_mysy_openai_voice_to_text"
"""
Cette fonction prend une phrase et fait un decoupage comme suit :
1 - enleve le mot "ok Missy", "ok mysy"
2 - met la pharase d'instruction dans une tableau
"""
tab_order_mysy = ['ok, missi', 'ok missi', 'ok; missi','ok, missy', 'ok mysy']
def mysy_openai_voice_to_text_traitement_1(voice_text):
try:
print(" ### Texte initial = ", str(voice_text).strip().lower())
voice_text_work = str(voice_text).strip().lower()
for val in tab_order_mysy:
voice_text_work = str(voice_text_work).strip().lower().replace(str(val), '[INSTRUCTION]')
voice_text_work = str(voice_text_work).strip().lower().replace("stop", '[stop]')
new_diction = {}
new_diction['text'] = str(voice_text_work)
new_diction['partner_owner_recid'] = "partner_owner_recid"
new_diction['related_object'] = "myclass"
new_diction['related_collection_recid'] = "dqsqddd0ed"
local_status, local_retval_message, local_retval_id = mysy_openai_insert_voice_to_collection(new_diction)
print(" || == > Texte Final = ", voice_text_work, " ## ID message = ", local_retval_id)
print("\n")
return local_status, local_retval_message, local_retval_id
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de traiter : mysy_openai_voice_to_text_traitement_1", False
"""
Cette fonction prend une phrase du type :
[instruction], modifie formation code cccccc.... [stop] . titre: xxxxxx [stop] description:xxxxx [stop] [fin]
et insert les données dans une collection (voice_instruction) comme suit :
[
{
"_id": "02sdsddfdfd52",
"related_collection": "myclass",
"related_collection_recid": "",
"instruction": "créer une formation ....[stop] Titre xxxxxx [stop] Description xxxxx[stop]",
"action": "create",
"partner_owner_recid": "ddddd",
"valide": "1",
"locked": "0",
"data": [
{
"field": "Titre",
"value": "xxxxx"
},
{
"field": "Description",
"value": "xxxx"
}
]
},
{
"_id": "34sdrrdfdfd53",
"related_collection": "myclass",
"related_collection_recid": "ikddd933ob",
"instruction": "update formation ....[stop]. programme: yyyyy[stop] objectif:yyyyy[stop]",
"action": "update",
"partner_owner_recid": "ddddd",
"valide": "1",
"locked": "0",
"data": [
{
"field": "objectif",
"value": "yyyyy"
},
]
}
]
"""
def mysy_openai_insert_voice_to_collection(diction):
try:
"""
Verification des input acceptés
"""
field_list = ['text', "partner_owner_recid", "related_object", "related_collection_recid"]
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
return False, " Les informations fournies sont incorrectes", False
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['text', "partner_owner_recid", "related_object", "related_collection_recid"]
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Les informations fournies sont incorrectes", False
voice_text_work = str(diction['text']).strip().lower().replace("[instruction] ", '')
voice_text_work = str(voice_text_work).strip().lower().replace("[instruction], ", '')
local_data = {}
local_data['text'] = str(voice_text_work)
local_data['related_collection'] = "myclass"
local_status, local_retval, local_retval_action = mysy_openai_transform_instruction_text_to_json_tab(local_data)
new_data = {}
new_data['partner_owner_recid'] = diction['partner_owner_recid']
new_data['related_object'] = diction['related_object']
new_data['related_collection_recid'] = diction['related_collection_recid']
new_data['instruction'] = str(voice_text_work)
new_data['valide'] = '1'
new_data['locked'] = '0'
new_data['date_create'] = str(datetime.now())
new_data['date_update'] = str(datetime.now())
if( local_status):
new_data['action'] = str(local_retval_action)
new_data['data'] = local_retval
else:
new_data['action'] = ""
new_data['data'] = []
inserted_id = ""
inserted_id = MYSY_GV.dbname['voice_instruction'].insert_one(new_data).inserted_id
if (not inserted_id):
mycommon.myprint(
" Impossible de créer le message vocal dans la collection ")
return False, " Impossible de créer le message vocal dans la collection (2) "
return True, "Le message a été correctement enregistré en base", str(inserted_id)
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de créer le message vocal dans la collection ", False
"""
Cette fonction prends une phrase d'instruction du type :
"créer une formation .... [stop] . titre: xxxxxx [stop] description:xxxxx [stop]"
et la transforme en un tableau de json comme suit :
[
{
"field": "Titre",
"value": "xxxxx"
},
{
"field": "Description",
"value": "xxxx"
}
]
"""
def mysy_openai_transform_instruction_text_to_json_tab(diction):
try:
"""
Verification des input acceptés
"""
field_list = ['text', "related_collection",]
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
return False, " Les informations fournies sont incorrectes", False
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['text', "related_collection",]
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Les informations fournies sont incorrectes", False
local_related_collection = str(diction['related_collection']).strip().lower()
if( local_related_collection not in MYSY_GV.mysy_voice_instruction_related_collection):
mycommon.myprint(
str(inspect.stack()[0][3]) + " La collection "+str(diction['related_collection']).strip().lower()+" n'est pas"
" autorisé pour les actions voices")
return False, "La collection "+str(diction['related_collection']).strip().lower()+" n'est pas autorisé pour les actions voices", False
"""
Recuperer la liste des mots clés de cette collection qui est stocké ici :
mysy_voice_instruction_collection_field
"""
collection_tab_champs_cle = []
if (local_related_collection in MYSY_GV.mysy_voice_instruction_collection_field.keys()):
collection_tab_champs_cle = MYSY_GV.mysy_voice_instruction_collection_field[str(local_related_collection)]
collection_tab_action_autorise = []
if (local_related_collection in MYSY_GV.mysy_voice_instruction_collection_action.keys()):
collection_tab_action_autorise = MYSY_GV.mysy_voice_instruction_collection_action[str(local_related_collection)]
#print(' ### Collection concernée = ', local_related_collection)
#print(' ### Collection champs = ', collection_tab_champs_cle)
#print(' ### Collection action autorise = ', collection_tab_action_autorise)
new_tab = str(diction['text']).strip().lower().split("[stop]")
#print(' ### new_tab = ', new_tab)
tab_text = []
# Recuperation des champs/valeur
for val in new_tab:
for champ in collection_tab_champs_cle:
champ = str(champ).strip().lower()
if (champ in val):
print(str(champ) + " = " + str(val).replace(str(champ), ""))
my_value = str(val).replace(str(champ), "")
node = {}
node['field'] = str(champ)
node['value'] = str(my_value)
tab_text.append(node)
# Recuperation de l'action
action = ""
for val in new_tab:
for champ in collection_tab_action_autorise :
for my_cle in champ.keys():
cle_action = my_cle
if( cle_action in val ):
#print(" OK POUR l'action ", cle_action, " ## la valeur = ", champ[str(cle_action)])
action = champ[str(cle_action)]
return True, tab_text, action
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de traiter : mysy_openai_assistant", False
def mysy_openai_assistant(diction):
try: