MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / direction_add

Function direction_add

scripts/drift_engine.py:1082–1121  ·  view source on GitHub ↗

鏂板鏍稿績鏂瑰悜锛氬湪鍘熸湁鏍稿績鏂瑰悜鍩虹涓婃坊鍔犳柊鐨勭爺绌舵柟鍚?

(
    profile: Dict[str, Any],
    params: Dict[str, Any],
    selected_papers: Optional[List[Dict]] = None,
    date: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

1080
1081def direction_add(
1082 profile: Dict[str, Any],
1083 params: Dict[str, Any],
1084 selected_papers: Optional[List[Dict]] = None,
1085 date: Optional[str] = None,
1086) -> Tuple[Dict[str, Any], Dict[str, Any]]:
1087 """
1088 鏂板鏍稿績鏂瑰悜锛氬湪鍘熸湁鏍稿績鏂瑰悜鍩虹涓婃坊鍔犳柊鐨勭爺绌舵柟鍚? """
1089 updated = copy.deepcopy(profile)
1090 core_directions = updated.get("core_directions", {})
1091
1092 old_directions = list(core_directions.keys())
1093 new_directions_pool = params.get("new_directions_pool", [])
1094 add_count = params.get("add_count", 1)
1095 initial_weight = params.get("initial_weight", 0.4)
1096
1097 # 杩囨护鎺夊凡鏈夌殑鏂瑰悜
1098 available_directions = [d for d in new_directions_pool if d not in core_directions]
1099
1100 # 闅忔満閫夋嫨鏂版柟鍚?
1101 new_directions = random.sample(available_directions, min(add_count, len(available_directions)))
1102
1103 # 娣诲姞鏂版柟鍚?
1104 for direction in new_directions:
1105 core_directions[direction] = initial_weight
1106
1107 updated["core_directions"] = core_directions
1108 updated["topic_weights"] = copy.deepcopy(core_directions)
1109
1110 # 鏇存柊 drift_state
1111 updated["drift_state"] = _update_drift_state(profile, date, score_delta=0.2)
1112
1113 drift_event = {
1114 "method": "direction_add",
1115 "directions_before": old_directions,
1116 "directions_added": new_directions,
1117 "directions_after": list(core_directions.keys()),
1118 }
1119
1120 return updated, drift_event
1121
1122
1123def direction_remove(
1124 profile: Dict[str, Any],

Callers

nothing calls this directly

Calls 2

_update_drift_stateFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected