多轮问询
This commit is contained in:
parent
2411eba2f0
commit
487d12b45f
16
api/mian.py
16
api/mian.py
|
|
@ -12,7 +12,7 @@ from pydantic import ValidationError
|
||||||
from intentRecognition import IntentRecognition
|
from intentRecognition import IntentRecognition
|
||||||
from slotRecognition import SlotRecognition
|
from slotRecognition import SlotRecognition
|
||||||
from fuzzywuzzy import process
|
from fuzzywuzzy import process
|
||||||
from utils import CheckResult, StandardType
|
from utils import CheckResult, StandardType, load_standard_name
|
||||||
from constants import PROJECT_NAME, PROJECT_DEPARTMENT
|
from constants import PROJECT_NAME, PROJECT_DEPARTMENT
|
||||||
|
|
||||||
# 常量
|
# 常量
|
||||||
|
|
@ -47,9 +47,9 @@ slot_recognizer = SlotRecognition(MODEL_UIE_PATH, label_map)
|
||||||
# 设置Flask应用
|
# 设置Flask应用
|
||||||
|
|
||||||
#标准工程名
|
#标准工程名
|
||||||
standard_project_name_list = utils.load_standard_name('./standard_data/standard_project.txt')
|
standard_project_name_list = load_standard_name('./standard_data/standard_project.txt')
|
||||||
#标准项目名
|
#标准项目名
|
||||||
standard_program_name_list = utils.load_standard_name('./standard_data/standard_program.txt')
|
standard_program_name_list = load_standard_name('./standard_data/standard_program.txt')
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -209,7 +209,9 @@ def agent():
|
||||||
})
|
})
|
||||||
|
|
||||||
#工程名和项目名标准化
|
#工程名和项目名标准化
|
||||||
|
print(f"start to check_project_standard_slot")
|
||||||
result, information = check_project_standard_slot(predicted_id, entities)
|
result, information = check_project_standard_slot(predicted_id, entities)
|
||||||
|
print(f"end check_project_standard_slot,{result},{information}")
|
||||||
if result == CheckResult.NEEDS_MORE_ROUNDS:
|
if result == CheckResult.NEEDS_MORE_ROUNDS:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"code": 10001, "msg": "成功",
|
"code": 10001, "msg": "成功",
|
||||||
|
|
@ -286,11 +288,12 @@ def check_lost(int_res, slot):
|
||||||
def check_project_standard_slot(int_res, slot) -> tuple:
|
def check_project_standard_slot(int_res, slot) -> tuple:
|
||||||
intention_list = {3, 4, 5, 6, 7, 8}
|
intention_list = {3, 4, 5, 6, 7, 8}
|
||||||
if int_res not in intention_list:
|
if int_res not in intention_list:
|
||||||
return CheckResult.NO_MATCH,""
|
return CheckResult.NO_MATCH, ""
|
||||||
|
|
||||||
for key, value in slot.items():
|
for key, value in slot.items():
|
||||||
if key == PROJECT_NAME:
|
if key == PROJECT_NAME:
|
||||||
match_project, match_possibility = fuzzy_match(value, standard_project_name_list)
|
match_project, match_possibility = fuzzy_match(value, standard_project_name_list)
|
||||||
|
print(f"fuzzy_match project result:{match_project}, {match_possibility}")
|
||||||
if match_possibility >= 0.9:
|
if match_possibility >= 0.9:
|
||||||
slot[key] = match_project
|
slot[key] = match_project
|
||||||
else:
|
else:
|
||||||
|
|
@ -298,17 +301,18 @@ def check_project_standard_slot(int_res, slot) -> tuple:
|
||||||
|
|
||||||
if key == PROJECT_DEPARTMENT:
|
if key == PROJECT_DEPARTMENT:
|
||||||
match_program, match_possibility = fuzzy_match(value, standard_program_name_list)
|
match_program, match_possibility = fuzzy_match(value, standard_program_name_list)
|
||||||
|
print(f"fuzzy_match program result:{match_program}, {match_possibility}")
|
||||||
if match_possibility >= 0.9:
|
if match_possibility >= 0.9:
|
||||||
slot[key] = match_program
|
slot[key] = match_program
|
||||||
else:
|
else:
|
||||||
return CheckResult.NEEDS_MORE_ROUNDS, f"抱歉,您说的项目名是{match_program}吗"
|
return CheckResult.NEEDS_MORE_ROUNDS, f"抱歉,您说的项目名是{match_program}吗"
|
||||||
|
|
||||||
return CheckResult.NO_MATCH,""
|
return CheckResult.NO_MATCH, ""
|
||||||
|
|
||||||
|
|
||||||
def fuzzy_match(user_input, standard_name):
|
def fuzzy_match(user_input, standard_name):
|
||||||
result = process.extract(user_input, standard_name)
|
result = process.extract(user_input, standard_name)
|
||||||
return result[0], result[1]/100
|
return result[0][0], result[0][1]/100
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=18074, debug=True)
|
app.run(host='0.0.0.0', port=18074, debug=True)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue