| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- # inputType.py
- # from services.templateData import templateData
- # 引入1-4套皮肤数据
- from services.style.style1to4data import sectorStyle1to4Data
- # 引入5套皮肤数据
- from services.style.style5data import sectorStyle5Data
- class inputType:
- def __init__(self):
- self.del_map = [
- "删除", "去掉", "移除", "去除", "不要", "删掉", "不需要", "没有"
- ]
- self.del_group_map = [
- "不要显示广告", "去掉所有广告", "纯净版" , "只要新闻"
- ]
- self.sectors_name = {
- # 公用通栏
- "adSector": "通栏广告",
- # 1-4套皮肤
- "headLineSector": "网站头条",
- "bannerSector": "焦点图",
- "linkSector": "外链面板",
- "manyPictureSector": "新闻图文组合1",
- "commentSector": "新闻图文组合2",
- "listSector": "新闻图文组合3",
- "onlyImgSector": "带广告新闻组合",
-
- # 第5套皮肤
- "headLineSector": "网站头条",
- "bannerSectorMerge": "焦点图",
- "linkCxfwSector": "外链面板-带查询服务",
- "NewsHyjjSector": "行业聚焦新闻通栏",
- "newsTabsSector": "热点新闻选项卡",
- "newsTextSector": "文字新闻通栏1",
- "newsTabsTextSector": "选项卡文字新闻通栏",
- "newsAllPictureSector": "图片新闻通栏1",
- "newsTabsAdSector": "选项卡资讯带两个广告",
- }
-
- self.pos_first = ["第一个", "第一", "首位", "最前面", "开头", "第一位", "顶部"]
- self.pos_second = ["第二个", "第二", "第二位"]
- self.pos_third = ["第三个", "第三", "第三位"]
- self.pos_last = ["最后一个", "最后", "末尾", "垫底", "最后一位", "底部"]
- self.pos_last_second = ["倒数第二个", "倒数第二", "倒数第二位"]
- self.pos_last_third = ["倒数第三个", "倒数第三", "倒数第三位"]
-
- def generate_inputType(self, user_text,matched_template_id):
- # 导入推理方法
- from services.ai_service import ai_service
- import re
- # 按标点符号分句处理,支持多指令
- segments = re.split(r'[,,。;;|]+', user_text)
- segments = [s.strip() for s in segments if s.strip()]
- templateData = None
- # 根据matched_template_id选择样式数据
- if int(matched_template_id) == 5:
- print("正在使用第5套皮肤的数据!")
- templateData = sectorStyle5Data
- else:
- print("正在使用前4套皮肤的数据!")
- templateData = sectorStyle1to4Data
- if not segments:
- segments = [user_text]
- for segment in segments:
- # 1. 检查用户输入中是否包含组删除词
- if any(word in segment for word in self.del_group_map):
- # 删除所有广告相关通栏
- # ad_sectors = ["通栏广告", "带广告新闻组合"]
- # 找到所有名字中含有广告的通栏
- ad_sectors = [sector for sector in templateData.sectors_config if "广告" in sector['CNname']]
-
- templateData.sectors_config = [
- sector for sector in templateData.sectors_config
- if sector not in ad_sectors
- ]
- # 添加推理过程
- ai_service.add_reasoning(f"另外,用户不想看到广告,因此我修改了通栏列表,只保留了新闻相关通栏")
- print(f"已删除所有广告通栏: {ad_sectors}")
-
- # 2. 检查用户输入中是否包含普通删除词
- elif any(word in segment for word in self.del_map):
- # 查找用户输入中提到的通栏名称
- sectors_to_delete = []
- for cnname in self.sectors_name.values():
- if cnname in segment:
- sectors_to_delete.append(cnname)
-
- # 删除匹配的通栏配置
- if sectors_to_delete:
- templateData.sectors_config = [
- sector for sector in templateData.sectors_config
- if sector['CNname'] not in sectors_to_delete
- ]
- # 添加推理过程
- ai_service.add_reasoning(f"另外,用户想要删除{sectors_to_delete}通栏,我来把它隐藏掉")
- print(f"已删除通栏: {sectors_to_delete}")
-
- # 3. 检查用户输入中是否包含位置调整
- # 遍历所有通栏名称
- for name, cnname in self.sectors_name.items():
- if cnname in segment:
- new_weight = None
- reasoning_msg = ""
-
- # 获取当前最大和最小权重
- current_weights = [s['weight'] for s in templateData.sectors_config]
- if not current_weights:
- break
- max_weight = max(current_weights)
- min_weight = min(current_weights)
-
- # 检查位置关键词
- force_pos_val = None
-
- if any(word in segment for word in self.pos_first):
- new_weight = max_weight + 2
- reasoning_msg = f"用户想要把{cnname}放在第一位,我提升了它的权重"
- elif any(word in segment for word in self.pos_second):
- new_weight = max_weight - 1
- reasoning_msg = f"用户想要把{cnname}放在第二位,我调整了它的权重"
- elif any(word in segment for word in self.pos_third):
- new_weight = max_weight - 2
- reasoning_msg = f"用户想要把{cnname}放在第三位,我调整了它的权重"
- elif any(word in segment for word in self.pos_last):
- new_weight = min_weight - 3
- force_pos_val = 1
- reasoning_msg = f"用户想要把{cnname}放在最后一位,我降低了它的权重"
- elif any(word in segment for word in self.pos_last_second):
- if min_weight < 6:
- new_weight = min_weight + 1
- else:
- new_weight = min_weight - 2
- force_pos_val = 2
- reasoning_msg = f"用户想要把{cnname}放在倒数第二位,我调整了它的权重"
- elif any(word in segment for word in self.pos_last_third):
- if min_weight < 6:
- new_weight = min_weight + 2
- else:
- new_weight = min_weight - 1
- force_pos_val = 3
- reasoning_msg = f"用户想要把{cnname}放在倒数第三位,我调整了它的权重"
-
- # 如果确定了新权重,进行修改
- if new_weight is not None:
- for sector in templateData.sectors_config:
- if sector['name'] == name:
- sector['weight'] = new_weight
- if force_pos_val is not None:
- sector['force_pos'] = force_pos_val
- # 添加推理过程
- ai_service.add_reasoning(reasoning_msg)
- print(f"已调整通栏 {cnname} 权重为: {new_weight}")
- break
-
- # 全局匹配器实例
- inputType_matcher = inputType()
|