251 expand preference model#252
Conversation
| def get_preference_summary(self, max_preferences: int = 10) -> str: | ||
| """Returns a compact preference summary for prompts.""" | ||
| return "" | ||
|
|
||
| def update_from_dialogue(self, dialogue) -> None: | ||
| """Updates preferences from dialogue if supported by the model.""" |
There was a problem hiding this comment.
Shouldn't these be abstract?
Also, update_from_dialogue is currently empty.
There was a problem hiding this comment.
Nit: docstrings do not follow guidelines.
| r"\bwithout\b.*\b{value}\b", | ||
| r"\b{value}\s+(?:heavy|packed)\b", | ||
| ) | ||
| POSITIVE_PATTERNS = ( |
There was a problem hiding this comment.
It's the easiest solution so far
I think we could use llm to extract prefs in the future
| continue | ||
| self._item_preferences.set_preference(KEY_ITEM_ID, item_id, rating) | ||
|
|
||
| def _collect_slot_value_ratings(self) -> Dict[str, Dict[str, List[float]]]: |
There was a problem hiding this comment.
This is later used to compute the user’s long term preference score for each slot value pair
|
|
||
| self._update_session_preference(slot, value, score) | ||
|
|
||
| def _update_existing_preference( |
There was a problem hiding this comment.
it looks up the current score for slot=value
checks whether the new signal is positive or negative
moves the score by one UPDATE_STEP in that direction
increments the count for that preference
| preference_store.set_preference(slot, value, new_score) | ||
| preference_counts[key] = max(1, old_count) + 1 | ||
|
|
||
| def _update_session_preference( |
There was a problem hiding this comment.
if the session preference already exists, it updates it using the normal step-based rule
if it is new, it creates it in the session layer with an initial score of 2 * UPDATE_STEP
| + session_count | ||
| ) | ||
|
|
||
| def _extract_matched_values(self, text_lower: str) -> List[Tuple[str, str]]: |
There was a problem hiding this comment.
it looks for known preference values already stored in the model
then it looks for possible values from the item catalog
|
|
||
| self._apply_text_update(text) | ||
|
|
||
| def _rank_preferences(self) -> List[Tuple[str, str, float]]: |
There was a problem hiding this comment.
it combines long-term and session preferences
if the same slot=value exists in both, the session version overrides the long-term one
| ), | ||
| ) | ||
|
|
||
| def get_preference_summary(self, max_preferences: int = 20) -> str: |
|
|
||
| @abstractmethod | ||
| def get_preference_summary(self, max_preferences: int = 10) -> str: | ||
| """Returns a compact preference summary for prompts.""" |
There was a problem hiding this comment.
Nit: Docstring does not follow guidelines (e.g., missing args and raises sections).
| def get_preference_summary(self, max_preferences: int = 10) -> str: | ||
| """Returns a compact preference summary for prompts.""" | ||
| return "" | ||
|
|
||
| def update_from_dialogue(self, dialogue) -> None: | ||
| """Updates preferences from dialogue if supported by the model.""" |
There was a problem hiding this comment.
Nit: docstrings do not follow guidelines.
| item_collection=item_collection, | ||
| preference_model=preference_model, | ||
| ) | ||
| self._preference_model = self.preference_model |
There was a problem hiding this comment.
This is redundant, you can simple use self.preference_model.
| @property | ||
| def _preference_context(self) -> str: | ||
| """Returns current preference context for the prompt.""" | ||
| if not self.preference_model: | ||
| return "" | ||
|
|
||
| preference_summary = self.preference_model.get_preference_summary() | ||
| if not preference_summary: | ||
| return "" | ||
|
|
||
| return ( | ||
| "USER PREFERENCES: " | ||
| f"{preference_summary}\n" | ||
| "Treat these preferences as soft background tastes, not as new " | ||
| "requirements. Use them to shape what the user accepts, " | ||
| "rejects, asks to avoid, or follows up on. Do not force every " | ||
| "liked preference into the opening request.\n" | ||
| ) |
There was a problem hiding this comment.
I wonder if it would be better to leave specific prompt class define the way the preferences are described in the prompt. For example, currently the stop prompt and utterance generation prompt use you while this prompt uses the user (possible misalignment and confusion for the model).
| return ( | ||
| self._initial_prompt | ||
| + "\n" | ||
| + self._preference_context |
There was a problem hiding this comment.
Nit: Why note have a "\n" after like for the other elements of the prompt?
| persona_text = ( | ||
| self.persona.persona_description or stringified_characteristics | ||
| ) |
There was a problem hiding this comment.
Nit: you could avoid the creation of stringified_characteristics if the persona_description exist (similar comment for stop_prompt.py)
| def get_preference_summary(self, max_preferences: int = 10) -> str: | ||
| """Returns an empty summary until PKG prompt support is added.""" | ||
| return "" | ||
|
|
||
| def update_from_dialogue(self, dialogue) -> None: | ||
| """PKG-backed dialogue updates are not implemented yet.""" | ||
| return None |
There was a problem hiding this comment.
Nit: docstrings do not follow guidelines.
| def get_preference_summary(self, max_preferences: int = 10) -> str: | ||
| """Returns an empty summary for non-structured preferences.""" | ||
| return "" | ||
|
|
||
| def update_from_dialogue(self, dialogue) -> None: | ||
| """Simple preferences do not update from dialogue.""" | ||
| return None |
There was a problem hiding this comment.
Nit: docstrings do not follow guidelines.
No description provided.