Skip to content

Commit

Permalink
chore: review-induced renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik committed Jan 20, 2025
1 parent efaaf8f commit 57eb4eb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions aidial_adapter_bedrock/llm/chat_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class CueMapping(TypedDict):

class BasicChatEmulator(ChatEmulator):
prelude_template: Optional[str]
add_cue: Callable[[Message, int], bool]
add_invitation_cue: bool
fallback_to_completion: bool
should_prefix_with_cue: Callable[[Message, int], bool]
should_add_invitation_cue: bool
should_fallback_to_completion: bool
cues: CueMapping
separator: str

Expand All @@ -55,7 +55,7 @@ def _get_cue(self, message: Message) -> Optional[str]:
def _format_message(self, message: Message, idx: int) -> str:
cue = self._get_cue(message)

if cue is None or not self.add_cue(message, idx):
if cue is None or not self.should_prefix_with_cue(message, idx):
cue_prefix = ""
else:
cue_prefix = cue + " "
Expand All @@ -69,7 +69,7 @@ def get_ai_cue(self) -> Optional[str]:

def display(self, messages: List[Message]) -> Tuple[str, List[str]]:
if (
self.fallback_to_completion
self.should_fallback_to_completion
and len(messages) == 1
and messages[0].role == Role.USER
):
Expand All @@ -83,7 +83,7 @@ def display(self, messages: List[Message]) -> Tuple[str, List[str]]:
for message in messages:
ret.append(self._format_message(message, len(ret)))

if self.add_invitation_cue:
if self.should_add_invitation_cue:
ret.append(
self._format_message(
Message(role=Role.ASSISTANT, content=""), len(ret)
Expand All @@ -106,9 +106,9 @@ def display(self, messages: List[Message]) -> Tuple[str, List[str]]:
Reply to the last message from the user taking into account the preceding dialog history.
====================
""".strip(),
add_cue=lambda *_: True,
add_invitation_cue=True,
fallback_to_completion=True,
should_prefix_with_cue=lambda *_: True,
should_add_invitation_cue=True,
should_fallback_to_completion=True,
cues=CueMapping(
system="Human:",
human="Human:",
Expand Down
6 changes: 3 additions & 3 deletions aidial_adapter_bedrock/llm/model/claude/v1_v2/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def add_cue(message: Message, idx: int) -> bool:

return BasicChatEmulator(
prelude_template=None,
add_cue=add_cue,
add_invitation_cue=True,
fallback_to_completion=False,
should_prefix_with_cue=add_cue,
should_add_invitation_cue=True,
should_fallback_to_completion=False,
cues=CueMapping(
system=anthropic.HUMAN_PROMPT.strip(),
human=anthropic.HUMAN_PROMPT.strip(),
Expand Down
6 changes: 3 additions & 3 deletions aidial_adapter_bedrock/llm/model/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ async def response_to_stream(

cohere_emulator = BasicChatEmulator(
prelude_template=None,
add_cue=lambda _, idx: idx > 0,
add_invitation_cue=False,
fallback_to_completion=False,
should_prefix_with_cue=lambda _, idx: idx > 0,
should_add_invitation_cue=False,
should_fallback_to_completion=False,
cues=CueMapping(
system="User:",
human="User:",
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/chat_emulation/test_default_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

noop_emulator = BasicChatEmulator(
prelude_template=None,
add_cue=lambda *_: False,
add_invitation_cue=False,
fallback_to_completion=False,
should_prefix_with_cue=lambda *_: False,
should_add_invitation_cue=False,
should_fallback_to_completion=False,
cues=CueMapping(system=None, human=None, ai=None),
separator="",
)
Expand Down

0 comments on commit 57eb4eb

Please sign in to comment.