From e8ecb3e0a622a6bbf1779dd186cd6d307a47578b Mon Sep 17 00:00:00 2001 From: hmasdev Date: Tue, 26 Nov 2024 22:20:39 +0900 Subject: [PATCH] Refactor Field definitions in model classes for consistency --- langchain_werewolf/models/config.py | 2 +- langchain_werewolf/models/general.py | 4 ++-- langchain_werewolf/models/state.py | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/langchain_werewolf/models/config.py b/langchain_werewolf/models/config.py index 11f2c3c..ef71634 100644 --- a/langchain_werewolf/models/config.py +++ b/langchain_werewolf/models/config.py @@ -33,7 +33,7 @@ class GeneralConfig(BaseModel, frozen=True): class PlayerConfig(BaseModel, frozen=True): - name: str = Field(..., title="The name of the player", default_factory=consecutive_string_generator(CUSTOM_PLAYER_PREFIX).__next__) # noqa + name: str = Field(title="The name of the player", default_factory=consecutive_string_generator(CUSTOM_PLAYER_PREFIX).__next__) # noqa role: ERole | None = Field(default=None, title="The role of the player") # noqa model: str = Field(default=DEFAULT_MODEL, title=f"The model to use. Default is {DEFAULT_MODEL}.") # noqa language: ELanguage | None = Field(default=None, title="The language of the player") # noqa diff --git a/langchain_werewolf/models/general.py b/langchain_werewolf/models/general.py index 6635d92..707562a 100644 --- a/langchain_werewolf/models/general.py +++ b/langchain_werewolf/models/general.py @@ -37,8 +37,8 @@ class IdentifiedModel(PartialFrozenModel, Generic[T]): # FIXME: frozen_fields should be merged with the parent class's frozen_fields # noqa frozen_fields: Annotated[set[str], constant_reducer] = {'frozen_fields', 'id'} # noqa - id: str = Field(..., title="object id", default_factory=_generate_unique_string) # noqa - value: T = Field(..., title="the value of the model") + id: str = Field(title="object id", default_factory=_generate_unique_string) # noqa + value: T = Field(title="the value of the model") def reduce_dict( diff --git a/langchain_werewolf/models/state.py b/langchain_werewolf/models/state.py index 45a8a47..d9314d1 100644 --- a/langchain_werewolf/models/state.py +++ b/langchain_werewolf/models/state.py @@ -20,11 +20,11 @@ class MsgModel(BaseModel): name: str \ = Field(..., title="the name of the player") timestamp: datetime \ - = Field(..., title="Timestamp", default_factory=datetime.now) + = Field(title="Timestamp", default_factory=datetime.now) message: str \ = Field(..., title="Message") participants: frozenset[str] \ - = Field(..., title="the names of the participants", default_factory=frozenset) # noqa + = Field(title="the names of the participants", default_factory=frozenset) # noqa template: str \ = Field( default='\n'.join([ @@ -60,7 +60,7 @@ class ChatHistoryModel(PartialFrozenModel): names: frozenset[str]\ = Field(..., title="the names of the chat participants") messages: list[IdentifiedModel[MsgModel]]\ - = Field(..., title="Chat Messages", default_factory=list) + = Field(title="Chat Messages", default_factory=list) @field_serializer('names') def serialize_names(self, value: frozenset[str]) -> list[str]: @@ -124,13 +124,13 @@ class StateModel(PartialFrozenModel): chat_state: Annotated[ dict[frozenset[str], ChatHistoryModel], _reduce_chat_state, - ] = Field(..., title="the chat state", default_factory=dict) # noqa + ] = Field(title="the chat state", default_factory=dict) # noqa # players information alive_players_names: Annotated[list[str], overwrite_reducer]\ = Field(..., title="the names of the alive players") safe_players_names: Annotated[set[str], overwrite_reducer]\ - = Field(..., title="the names of the safe players", default_factory=set) # noqa + = Field(title="the names of the safe players", default_factory=set) # noqa # game chat information current_speaker: Annotated[str | None, overwrite_reducer]\ @@ -141,13 +141,13 @@ class StateModel(PartialFrozenModel): # vote information # TODO: modify the type of daytime_votes_history and nighttime_votes_history: dict to dict[str, str] # noqa daytime_vote_result_history: Annotated[list[IdentifiedModel[str | None]], reduce_list]\ - = Field(..., title="the history of the daytime vote results", default_factory=list) # noqa + = Field(title="the history of the daytime vote results", default_factory=list) # noqa daytime_votes_history: Annotated[list[IdentifiedModel[dict]], reduce_list]\ - = Field(..., title="the votes of each daytime discussion", default_factory=list) # noqa + = Field(title="the votes of each daytime discussion", default_factory=list) # noqa nighttime_vote_result_history: Annotated[list[IdentifiedModel[str | None]], reduce_list]\ - = Field(..., title="the history of the nighttime vote results", default_factory=list) # noqa + = Field(title="the history of the nighttime vote results", default_factory=list) # noqa nighttime_votes_history: Annotated[list[IdentifiedModel[dict]], reduce_list]\ - = Field(..., title="the votes of each nighttime discussion", default_factory=list) # noqa + = Field(title="the votes of each nighttime discussion", default_factory=list) # noqa daytime_votes_current: Annotated[dict[str, str], _reduce_votes_current]\ = Field(default_factory=dict, title="the current daytime votes") nighttime_votes_current: Annotated[dict[str, str], _reduce_votes_current]\