多轮问询

This commit is contained in:
weiweiw 2025-02-27 20:22:00 +08:00
parent 2411eba2f0
commit 487d12b45f
1 changed files with 10 additions and 6 deletions

View File

@ -12,7 +12,7 @@ from pydantic import ValidationError
from intentRecognition import IntentRecognition
from slotRecognition import SlotRecognition
from fuzzywuzzy import process
from utils import CheckResult, StandardType
from utils import CheckResult, StandardType, load_standard_name
from constants import PROJECT_NAME, PROJECT_DEPARTMENT
# 常量
@ -47,9 +47,9 @@ slot_recognizer = SlotRecognition(MODEL_UIE_PATH, label_map)
# 设置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__)
@ -209,7 +209,9 @@ def agent():
})
#工程名和项目名标准化
print(f"start to check_project_standard_slot")
result, information = check_project_standard_slot(predicted_id, entities)
print(f"end check_project_standard_slot,{result},{information}")
if result == CheckResult.NEEDS_MORE_ROUNDS:
return jsonify({
"code": 10001, "msg": "成功",
@ -291,6 +293,7 @@ def check_project_standard_slot(int_res, slot) -> tuple:
for key, value in slot.items():
if key == PROJECT_NAME:
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:
slot[key] = match_project
else:
@ -298,6 +301,7 @@ def check_project_standard_slot(int_res, slot) -> tuple:
if key == PROJECT_DEPARTMENT:
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:
slot[key] = match_program
else:
@ -308,7 +312,7 @@ def check_project_standard_slot(int_res, slot) -> tuple:
def fuzzy_match(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__':
app.run(host='0.0.0.0', port=18074, debug=True)