Files
QueryRewrite/rag2_0/dify/WorkorderToDify.py
T

45 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import sys
sys.path.append(os.getcwd())
import rag2_0.dify.dify_client.dify_api as DifyApi
import pandas as pd
pd_data = pd.read_excel("data/excel/工单汇总(给AI_2.xlsx")
dify_api = DifyApi.DifyApi()
peiwang_dataset_id = dify_api.get_or_create_dataset_by_name("配网工单数据")
zhuwang_dataset_id = dify_api.get_or_create_dataset_by_name("主网工单数据")
jianga_dataset_id = dify_api.get_or_create_dataset_by_name("技改工单数据")
chuneng_dataset_id = dify_api.get_or_create_dataset_by_name("储能工单数据")
soft_segments_list={}
for index, row in pd_data.iterrows():
query = row["客户问题"]
answer = row["解决方案"]
skill_group = row["技能组"]
content = f"问题:{query}\n回答:{answer}"
if skill_group not in soft_segments_list:
soft_segments_list[skill_group]=[]
soft_segments_list[skill_group].append({
"content": str(content),
"answer": "",
"keywords": []
})
for skill_group, segments_list in soft_segments_list.items():
if skill_group == "配网":
dataset_id = peiwang_dataset_id
elif skill_group == "主网":
dataset_id = zhuwang_dataset_id
elif skill_group == "技改":
dataset_id = jianga_dataset_id
elif skill_group == "储能":
dataset_id = chuneng_dataset_id
document_id = dify_api.get_document_id(dataset_id=dataset_id, document_name=f"{skill_group}工单数据")
if not document_id:
document_id = dify_api.upload_text_to_document(text_name=f"{skill_group}工单数据", text="", dataset_id=dataset_id)
dify_api.add_document_segments(dataset_id=dataset_id, document_id=document_id, segments_list=segments_list)