ishaq101 commited on
Commit
56dd37e
·
1 Parent(s): 2216e64

[NOTICKET] handle create_weight if total weight not between 0 and 1

Browse files
Files changed (1) hide show
  1. services/agentic/weight.py +8 -4
services/agentic/weight.py CHANGED
@@ -63,10 +63,14 @@ class AgenticWeightService:
63
  else:
64
  # normalized weight
65
  # total_weight = sum([getattr(new_weight, field_name) for field_name in weighted_field_name])
66
- for field_name in weighted_field_name:
67
- curr_w = getattr(new_weight, field_name)
68
- normalized_w = curr_w / total_weight
69
- setattr(new_weight, field_name, normalized_w)
 
 
 
 
70
 
71
  # create weight
72
  created_weight = await create_weight(self.db, new_weight)
 
63
  else:
64
  # normalized weight
65
  # total_weight = sum([getattr(new_weight, field_name) for field_name in weighted_field_name])
66
+ # for field_name in weighted_field_name:
67
+ # curr_w = getattr(new_weight, field_name)
68
+ # normalized_w = curr_w / total_weight
69
+ # setattr(new_weight, field_name, normalized_w)
70
+ raise HTTPException(
71
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
72
+ detail=f"Create weight error: the weight value must be between 0 and 1, and the total weight must be less than or equal to 1. The total weight you provided is {total_weight}"
73
+ )
74
 
75
  # create weight
76
  created_weight = await create_weight(self.db, new_weight)