@@ -516,7 +516,7 @@ def list(self, with_valid=True):
516516 @staticmethod
517517 def reset_application (application : Dict ):
518518 application ['multiple_rounds_dialogue' ] = True if application .get ('dialogue_number' ) > 0 else False
519- del application [ 'dialogue_number' ]
519+
520520 if 'dataset_setting' in application :
521521 application ['dataset_setting' ] = {'search_mode' : 'embedding' , 'no_references_setting' : {
522522 'status' : 'ai_questioning' ,
@@ -711,21 +711,39 @@ def edit(self, instance: Dict, with_valid=True):
711711 raise AppApiException (500 , "模型不存在" )
712712 if not model .is_permission (application .user_id ):
713713 raise AppApiException (500 , f"沒有权限使用该模型:{ model .name } " )
714+ if instance .get ('stt_model_id' ) is None or len (instance .get ('stt_model_id' )) == 0 :
715+ application .stt_model_id = None
716+ else :
717+ model = QuerySet (Model ).filter (
718+ id = instance .get ('stt_model_id' )).first ()
719+ if model is None :
720+ raise AppApiException (500 , "模型不存在" )
721+ if not model .is_permission (application .user_id ):
722+ raise AppApiException (500 , f"沒有权限使用该模型:{ model .name } " )
723+ if instance .get ('tts_model_id' ) is None or len (instance .get ('tts_model_id' )) == 0 :
724+ application .tts_model_id = None
725+ else :
726+ model = QuerySet (Model ).filter (
727+ id = instance .get ('tts_model_id' )).first ()
728+ if model is None :
729+ raise AppApiException (500 , "模型不存在" )
730+ if not model .is_permission (application .user_id ):
731+ raise AppApiException (500 , f"沒有权限使用该模型:{ model .name } " )
714732 if 'work_flow' in instance :
715733 # 当前用户可修改关联的知识库列表
716734 application_dataset_id_list = [str (dataset_dict .get ('id' )) for dataset_dict in
717735 self .list_dataset (with_valid = False )]
718736 self .update_reverse_search_node (instance .get ('work_flow' ), application_dataset_id_list )
737+ # 找到语音配置相关
738+ self .get_work_flow_model (instance )
719739
720740 update_keys = ['name' , 'desc' , 'model_id' , 'multiple_rounds_dialogue' , 'prologue' , 'status' ,
721- 'dataset_setting' , 'model_setting' , 'problem_optimization' ,
741+ 'dataset_setting' , 'model_setting' , 'problem_optimization' , 'dialogue_number' ,
742+ 'stt_model_id' , 'tts_model_id' , 'tts_model_enable' , 'stt_model_enable' ,
722743 'api_key_is_active' , 'icon' , 'work_flow' , 'model_params_setting' ]
723744 for update_key in update_keys :
724745 if update_key in instance and instance .get (update_key ) is not None :
725- if update_key == 'multiple_rounds_dialogue' :
726- application .__setattr__ ('dialogue_number' , 0 if not instance .get (update_key ) else 3 )
727- else :
728- application .__setattr__ (update_key , instance .get (update_key ))
746+ application .__setattr__ (update_key , instance .get (update_key ))
729747 application .save ()
730748
731749 if 'dataset_id_list' in instance :
@@ -825,6 +843,27 @@ def save_other_config(self, data):
825843
826844 application .save ()
827845
846+ @staticmethod
847+ def get_work_flow_model (instance ):
848+ nodes = instance .get ('work_flow' )['nodes' ]
849+ for node in nodes :
850+ if node ['id' ] == 'base-node' :
851+ instance ['stt_model_id' ] = node ['properties' ]['node_data' ]['stt_model_id' ]
852+ instance ['tts_model_id' ] = node ['properties' ]['node_data' ]['tts_model_id' ]
853+ instance ['stt_model_enable' ] = node ['properties' ]['node_data' ]['stt_model_enable' ]
854+ instance ['tts_model_enable' ] = node ['properties' ]['node_data' ]['tts_model_enable' ]
855+ break
856+
857+ def speech_to_text (self , filelist ):
858+ # todo 找到模型 mp3转text
859+ print (self .application_id )
860+ print (filelist )
861+
862+ def text_to_speech (self , text ):
863+ # todo 找到模型 text转bytes
864+ print (self .application_id )
865+ print (text )
866+
828867 class ApplicationKeySerializerModel (serializers .ModelSerializer ):
829868 class Meta :
830869 model = ApplicationApiKey
0 commit comments