@@ -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' ,
@@ -710,21 +710,37 @@ def edit(self, instance: Dict, with_valid=True):
710710 raise AppApiException (500 , "模型不存在" )
711711 if not model .is_permission (application .user_id ):
712712 raise AppApiException (500 , f"沒有权限使用该模型:{ model .name } " )
713+ if instance .get ('stt_model_id' ) is None or len (instance .get ('stt_model_id' )) == 0 :
714+ application .stt_model_id = None
715+ else :
716+ model = QuerySet (Model ).filter (
717+ id = instance .get ('stt_model_id' )).first ()
718+ if model is None :
719+ raise AppApiException (500 , "模型不存在" )
720+ if not model .is_permission (application .user_id ):
721+ raise AppApiException (500 , f"沒有权限使用该模型:{ model .name } " )
722+ if instance .get ('tts_model_id' ) is None or len (instance .get ('tts_model_id' )) == 0 :
723+ application .tts_model_id = None
724+ else :
725+ model = QuerySet (Model ).filter (
726+ id = instance .get ('tts_model_id' )).first ()
727+ if model is None :
728+ raise AppApiException (500 , "模型不存在" )
729+ if not model .is_permission (application .user_id ):
730+ raise AppApiException (500 , f"沒有权限使用该模型:{ model .name } " )
713731 if 'work_flow' in instance :
714732 # 当前用户可修改关联的知识库列表
715733 application_dataset_id_list = [str (dataset_dict .get ('id' )) for dataset_dict in
716734 self .list_dataset (with_valid = False )]
717735 self .update_reverse_search_node (instance .get ('work_flow' ), application_dataset_id_list )
718736
719737 update_keys = ['name' , 'desc' , 'model_id' , 'multiple_rounds_dialogue' , 'prologue' , 'status' ,
720- 'dataset_setting' , 'model_setting' , 'problem_optimization' ,
738+ 'dataset_setting' , 'model_setting' , 'problem_optimization' , 'dialogue_number' ,
739+ 'stt_model_id' , 'tts_model_id' , 'tts_model_enable' , 'stt_model_enable' ,
721740 'api_key_is_active' , 'icon' , 'work_flow' , 'model_params_setting' ]
722741 for update_key in update_keys :
723742 if update_key in instance and instance .get (update_key ) is not None :
724- if update_key == 'multiple_rounds_dialogue' :
725- application .__setattr__ ('dialogue_number' , 0 if not instance .get (update_key ) else 3 )
726- else :
727- application .__setattr__ (update_key , instance .get (update_key ))
743+ application .__setattr__ (update_key , instance .get (update_key ))
728744 application .save ()
729745
730746 if 'dataset_id_list' in instance :
@@ -823,6 +839,16 @@ def save_other_config(self, data):
823839
824840 application .save ()
825841
842+ def speech_to_text (self , filelist ):
843+ # todo 找到模型 mp3转text
844+ print (self .application_id )
845+ print (filelist )
846+
847+ def text_to_speech (self , text ):
848+ # todo 找到模型 text转bytes
849+ print (self .application_id )
850+ print (text )
851+
826852 class ApplicationKeySerializerModel (serializers .ModelSerializer ):
827853 class Meta :
828854 model = ApplicationApiKey
0 commit comments