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

Function update_weight

scripts/add_must_read.py:255–296  ·  view source on GitHub ↗

Update direction weight

(profile, direction, params)

Source from the content-addressed store, hash-verified

253
254def update_weight(profile, direction, params):
255 """Update direction weight"""
256 topic = params.get('topic')
257 new_weight = params.get('weight', 0.5)
258 core_directions = profile.get('core_directions', {})
259
260 matched_topic = None
261 if topic:
262 for t in core_directions.keys():
263 if topic.lower() in t.lower() or t.lower() in topic.lower():
264 matched_topic = t
265 break
266
267 if not matched_topic:
268 topic_weights = profile.get('topic_weights', {})
269 for t in topic_weights.keys():
270 if topic.lower() in t.lower() or t.lower() in topic.lower():
271 matched_topic = t
272 core_directions = topic_weights
273 break
274
275 if not matched_topic:
276 return (False, f"[错误] 未找到方向:{topic}", None)
277
278 old_weight = core_directions.get(matched_topic, 0.5)
279 if direction == 'down':
280 new_weight = max(0.1, old_weight - 0.1)
281 elif direction == 'up':
282 new_weight = min(1.0, old_weight + 0.1)
283
284 updated = profile.copy()
285 if matched_topic in profile.get('core_directions', {}):
286 updated['core_directions'] = profile['core_directions'].copy()
287 updated['core_directions'][matched_topic] = new_weight
288 if matched_topic in profile.get('topic_weights', {}):
289 updated['topic_weights'] = profile['topic_weights'].copy()
290 updated['topic_weights'][matched_topic] = new_weight
291 updated['version'] = f"0.{int(profile.get('version', '0.1').split('.')[1]) + 1}"
292 updated['updated_at'] = datetime.now().isoformat()
293
294 msg = f"[OK] 已调整 {matched_topic} 权重:{old_weight:.2f} → {new_weight:.2f}"
295 return (True, msg, updated)
296
297
298def main():
299 user_id = "user_001"

Callers 1

mainFunction · 0.85

Calls 2

getMethod · 0.80
nowMethod · 0.80

Tested by

no test coverage detected