Skip to content

Commit

Permalink
Revised column names for base models to improve consistency for _loca…
Browse files Browse the repository at this point in the history
…lized string columns.
  • Loading branch information
yghokim committed Apr 25, 2024
1 parent 771dc23 commit 02bf745
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
2 changes: 2 additions & 0 deletions data/card_translation_dictionary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ o5KmEGtJjx,action,do,해요,True
gDBX_FfZB6,action,done,끝났어요,True
TEOhxZmjK6,action,draw,그려요,True
v3di8t0pWz,action,drawing,그려요,True
A69xsnZPHn,action,drawn,그린,False
ZON1ssMHKK,action,drew,그렸어요,True
qFMNNFSCX5,action,eat,먹어요,True
H67n9i7nOg,action,eating,먹어요,True
Expand Down Expand Up @@ -348,6 +349,7 @@ UeI__XeQNE,topic,run,달리기,True
v87vwbFyNz,topic,sandbox,모래사장,True
l6a_W_vdiO,topic,sandwich,샌드위치,True
2bqHLaFEOK,topic,school,학교,True
HSqQ6LpTen,topic,school lunch,학교 점심,False
AIVv8SZhiV,topic,science,과학,True
MKImtd3Ojq,topic,sculpting,조각하기,True
volZ4dnema,topic,see,보기,False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def inspect_all(self, check_mode = False):
writer.writeheader()
translations = translations_already_inspected + translations_to_inspect

translations.sort(key=lambda t: t.localized)
translations.sort(key=lambda t: t.label_localized)
translations.sort(key=lambda t: t.english)
translations.sort(key=lambda t: t.category)

Expand Down
16 changes: 8 additions & 8 deletions libs/py_core/py_core/system/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class CardCategory(StrEnum):
class CardInfo(CardIdentity):
model_config = ConfigDict(frozen=True, use_enum_values=True)

text: str = Field()
localized: str
label: str = Field()
label_localized: str
category: CardCategory

def simple_str(self) -> str:
return f"{self.localized} ({self.text}) | {self.category}"
return f"{self.label_localized} ({self.label}) | {self.category}"


class ChildCardRecommendationResult(ModelWithIdAndTimestamp):
Expand Down Expand Up @@ -115,18 +115,18 @@ class DialogueMessage(ModelWithIdAndTimestamp):
model_config = ConfigDict(frozen=True)

role: DialogueRole
content: str | list[CardInfo]
content_en: str | None = None
content_localized: str | None = None
content: str | list[CardInfo] | None = None
recommendation_id: str | None = None

@classmethod
def example_parent_message(cls, content_en: str) -> 'DialogueMessage':
return DialogueMessage(content="_", content_en=content_en, role=DialogueRole.Parent)
def example_parent_message(cls, content: str) -> 'DialogueMessage':
return DialogueMessage(content_localized="_", content=content, role=DialogueRole.Parent)

@classmethod
def example_child_message(cls, *card_labels_eng: tuple[str, CardCategory]) -> 'DialogueMessage':
return DialogueMessage(role=DialogueRole.Child,
content=[CardInfo(text=label, localized="", category=category, recommendation_id="") for
content=[CardInfo(label=label, label_localized="", category=category, recommendation_id="") for
label, category in card_labels_eng])


Expand Down
4 changes: 2 additions & 2 deletions libs/py_core/py_core/system/moderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ async def submit_parent_message(self, parent_message: str,
print("Translated parent message.")

new_message = DialogueMessage(role=DialogueRole.Parent,
content=parent_message,
content_en=message_eng,
content_localized=parent_message,
content=message_eng,
recommendation_id=current_parent_guide.id if current_parent_guide is not None else None)

await self.__storage.add_dialogue_message(new_message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __prompt_generator(input: Dialogue, params: ChildCardRecommendationParams) -
"""f"""
{"" if params.prev_recommendation is None else "- The child had previous recommendation: " + params.prev_recommendation.json(exclude={"id", "timestamp"}) + ". Try to generate phrases that are distinct to this previous recommendation."}
{"" if params.interim_cards is None else "- The child had selected the following cards: " + ', '.join([card.text for card in params.interim_cards]) + ". The generated recommendation should be relevant to these selections."}
{"" if params.interim_cards is None else "- The child had selected the following cards: " + ', '.join([card.label for card in params.interim_cards]) + ". The generated recommendation should be relevant to these selections."}
- Provide up to five options for each category.
"""
return prompt
Expand Down Expand Up @@ -88,6 +88,6 @@ async def generate(self,
recommendation.emotions]

return ChildCardRecommendationResult(id=rec_id, cards=[
CardInfo(text=word, localized=translated_keywords[i], category=category,
CardInfo(label=word, label_localized=translated_keywords[i], category=category,
recommendation_id=rec_id) for i, (word, category) in
enumerate(keyword_category_list)])
2 changes: 1 addition & 1 deletion libs/py_core/py_core/system/task/stringify.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self,

@staticmethod
def message_content_formatter_default(message: DialogueMessage, dialogue: Dialogue) -> str:
return f"{'Parent' if message.role == DialogueRole.Parent else 'Child'}: {message.content_en if isinstance(message.content, str) else ', '.join([card.text for card in message.content])}"
return f"{'Parent' if message.role == DialogueRole.Parent else 'Child'}: {message.content if isinstance(message.content, str) else ', '.join([card.label for card in message.content])}"

@staticmethod
def message_row_formatter_default(formatted: str, message: DialogueMessage, dialogue: Dialogue) -> str:
Expand Down
8 changes: 4 additions & 4 deletions libs/py_database/py_database/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class DialogueMessageContentType(StrEnum):
class DialogueMessage(SQLModel, IdTimestampMixin, SessionIdMixin, table=True):
role: DialogueRole
content_type: DialogueMessageContentType
content_str: str
content_str_en: Optional[str] = Field(default=None)
content_str_localized: Optional[str] = Field(default=None)
content_str: Optional[str] = Field(default=None)
timestamp: int = Field(default_factory=get_timestamp, index=True)
recommendation_id: Optional[str] = Field(default=None)

Expand All @@ -82,7 +82,7 @@ def to_data_model(self) -> _DialogueMessage:
role=self.role,
content=self.content_str if self.content_type == DialogueMessageContentType.text else CardInfoListTypeAdapter.validate_json(
self.content_str),
content_en=self.content_str_en,
content_localized=self.content_str_localized,
recommendation_id=self.recommendation_id
)

Expand All @@ -91,9 +91,9 @@ def from_data_model(cls, session_id: str, message: _DialogueMessage) -> 'Dialogu
return DialogueMessage(
**message.model_dump(),
session_id=session_id,
content_str_localized=message.content_localized,
content_str=message.content if isinstance(message.content, str) else CardInfoListTypeAdapter.dump_json(
message.content),
content_str_en=message.content_en,
content_type=DialogueMessageContentType.text if isinstance(message.content,
str) else DialogueMessageContentType.json
)
Expand Down

0 comments on commit 02bf745

Please sign in to comment.