fixed indexing on feedback
This commit is contained in:
@@ -356,10 +356,19 @@ class PromptService:
|
||||
raise ValueError(f"Rating for '{word}' must be between 0 and 6, got {rating}")
|
||||
|
||||
if i < len(feedback_historic):
|
||||
# Update the weight for the queued word
|
||||
feedback_key = f"feedback{i:02d}"
|
||||
# Get the existing item and its key
|
||||
existing_item = feedback_historic[i]
|
||||
# Find the feedback key (not "weight")
|
||||
existing_keys = [k for k in existing_item.keys() if k != "weight"]
|
||||
if existing_keys:
|
||||
existing_key = existing_keys[0]
|
||||
else:
|
||||
# Fallback to generating a key
|
||||
existing_key = f"feedback{i:02d}"
|
||||
|
||||
# Update the item with existing key, same word, new weight
|
||||
feedback_historic[i] = {
|
||||
feedback_key: word,
|
||||
existing_key: word,
|
||||
"weight": rating
|
||||
}
|
||||
else:
|
||||
@@ -404,6 +413,8 @@ class PromptService:
|
||||
# Create new feedback items with default weight of 3
|
||||
new_feedback_items = []
|
||||
for i, word in enumerate(new_words):
|
||||
# Generate unique key based on position in buffer
|
||||
# New items will be at positions 0-5, so use those indices
|
||||
feedback_key = f"feedback{i:02d}"
|
||||
new_feedback_items.append({
|
||||
feedback_key: word,
|
||||
@@ -416,6 +427,26 @@ class PromptService:
|
||||
if len(updated_feedback_historic) > settings.FEEDBACK_HISTORY_SIZE:
|
||||
updated_feedback_historic = updated_feedback_historic[:settings.FEEDBACK_HISTORY_SIZE]
|
||||
|
||||
# Re-key all items to ensure unique keys
|
||||
for i, item in enumerate(updated_feedback_historic):
|
||||
# Get the word and weight from the current item
|
||||
# Each item has structure: {"feedbackXX": "word", "weight": N}
|
||||
old_key = list(item.keys())[0]
|
||||
if old_key == "weight":
|
||||
# Handle edge case where weight might be first key
|
||||
continue
|
||||
word = item[old_key]
|
||||
weight = item.get("weight", 3)
|
||||
|
||||
# Create new key based on position
|
||||
new_key = f"feedback{i:02d}"
|
||||
|
||||
# Replace the item with new structure
|
||||
updated_feedback_historic[i] = {
|
||||
new_key: word,
|
||||
"weight": weight
|
||||
}
|
||||
|
||||
# Update cache and save
|
||||
self._feedback_historic_cache = updated_feedback_historic
|
||||
await self.data_service.save_feedback_historic(updated_feedback_historic)
|
||||
|
||||
Reference in New Issue
Block a user