-
Notifications
You must be signed in to change notification settings - Fork 6
251 expand preference model #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
d3eda8e
eda7763
5b646dd
1e98d4b
99a8af6
7dd2da5
4e68b74
86c90cb
8106834
1d5a2de
8061d18
4098409
c8a809e
8fd213d
1bf1af8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| """Define the prompt for stopping the conversation.""" | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from usersimcrs.core.information_need import InformationNeed | ||
| from usersimcrs.simulator.llm.prompt.prompt import Prompt | ||
| from usersimcrs.user_modeling.preference_model import PreferenceModel | ||
| from usersimcrs.user_modeling.persona import Persona | ||
|
|
||
| DEFAULT_STOP_DEFINITION = ( | ||
|
|
@@ -21,7 +24,8 @@ def __init__( | |
| information_need: InformationNeed, | ||
| item_type: str, | ||
| prompt_definition: str = DEFAULT_STOP_DEFINITION, | ||
| persona: Persona = None, | ||
| persona: Optional[Persona] = None, | ||
| preference_model: Optional[PreferenceModel] = None, | ||
| ) -> None: | ||
| """Initializes the prompt. | ||
|
|
||
|
|
@@ -31,9 +35,14 @@ def __init__( | |
| prompt_definition: The definition of the task to be performed. | ||
| Defaults to DEFAULT_STOP_DEFINITION. | ||
| persona: The persona of the user. Defaults to None. | ||
| preference_model: Preference model. Defaults to None. | ||
| """ | ||
| super().__init__( | ||
| information_need, item_type, prompt_definition, persona | ||
| information_need, | ||
| item_type, | ||
| prompt_definition, | ||
| persona, | ||
| preference_model, | ||
| ) | ||
|
|
||
| @property | ||
|
|
@@ -42,6 +51,7 @@ def prompt_text(self) -> str: | |
| return ( | ||
| self._initial_prompt | ||
| + "\n" | ||
| + self._preference_context | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Why note have a "\n" after like for the other elements of the prompt? |
||
| + self._prompt_context | ||
| + "\n" | ||
| + "CONTINUE: " | ||
|
|
@@ -66,7 +76,10 @@ def build_new_prompt(self) -> str: | |
| for key, value in self.persona.characteristics.items() | ||
| ] | ||
| ) | ||
| initial_prompt += f"PERSONA: {stringified_characteristics}\n" | ||
| persona_text = ( | ||
| self.persona.persona_description or stringified_characteristics | ||
| ) | ||
| initial_prompt += f"PERSONA: {persona_text}\n" | ||
|
|
||
| initial_prompt += "\nHISTORY:\n" | ||
| return initial_prompt | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,10 +9,13 @@ | |
| for Task-Oriented Dialog Systems", arXiv 2306.00774. | ||
| """ | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from dialoguekit.core.utterance import Utterance | ||
| from dialoguekit.participant.participant import DialogueParticipant | ||
| from usersimcrs.core.information_need import InformationNeed | ||
| from usersimcrs.simulator.llm.prompt.prompt import Prompt | ||
| from usersimcrs.user_modeling.preference_model import PreferenceModel | ||
| from usersimcrs.user_modeling.persona import Persona | ||
|
|
||
| DEFAULT_TASK_DEFINITION = ( | ||
|
|
@@ -34,7 +37,8 @@ def __init__( | |
| information_need: InformationNeed, | ||
| item_type: str, | ||
| prompt_definition: str = DEFAULT_TASK_DEFINITION, | ||
| persona: Persona = None, | ||
| persona: Optional[Persona] = None, | ||
| preference_model: Optional[PreferenceModel] = None, | ||
| ) -> None: | ||
| """Initializes the prompt. | ||
|
|
||
|
|
@@ -44,9 +48,14 @@ def __init__( | |
| prompt_definition: The definition of the task to be performed. | ||
| Defaults to DEFAULT_TASK_DEFINITION. | ||
| persona: The persona of the user. Defaults to None. | ||
| preference_model: Preference model. Defaults to None. | ||
| """ | ||
| super().__init__( | ||
| information_need, item_type, prompt_definition, persona | ||
| information_need, | ||
| item_type, | ||
| prompt_definition, | ||
| persona, | ||
| preference_model, | ||
| ) | ||
|
|
||
| def build_new_prompt(self) -> str: | ||
|
|
@@ -67,7 +76,10 @@ def build_new_prompt(self) -> str: | |
| for key, value in self.persona.characteristics.items() | ||
| ] | ||
| ) | ||
| initial_prompt += f"PERSONA: {stringified_characteristics}\n" | ||
| persona_text = ( | ||
| self.persona.persona_description or stringified_characteristics | ||
| ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: you could avoid the creation of |
||
| initial_prompt += f"PERSONA: {persona_text}\n" | ||
| else: | ||
| initial_prompt += ( | ||
| "Be precise with the REQUIREMENTS, clear and concise.\n" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,33 @@ | ||
| from __future__ import annotations | ||
|
|
||
| """Persona, which is a profile of the user to represent different backgrounds | ||
| (e.g., age, gender, education), personality types, and behavioral tendencies | ||
| (e.g., patience, conscientiousness, or curiosity).""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Any, Dict | ||
| from typing import Any, Dict, Optional | ||
|
|
||
|
|
||
| @dataclass | ||
| class Persona: | ||
| """Represents personal user characteristics as key-value pairs.""" | ||
|
|
||
| characteristics: Dict[str, Any] | ||
| persona_description: Optional[str] = None | ||
|
|
||
| @classmethod | ||
| def from_config(cls, persona_config: Dict[str, Any]) -> Persona: | ||
| """Creates a persona from a configuration dictionary. | ||
|
|
||
| The configuration must provide characteristics under | ||
| ``characteristics`` and may include an optional ``persona_description``. | ||
|
|
||
| Args: | ||
| persona_config: Persona configuration. | ||
|
|
||
| Returns: | ||
| Persona instance. | ||
| """ | ||
| return cls( | ||
| persona_config.get("characteristics", {}), | ||
| persona_config.get("persona_description"), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant, you can simple use
self.preference_model.