Skip to content

Commit 568dedc

Browse files
committed
refactor: improve readability in trajectories.py and server.py
- Simplified the construction of loggable_dict in the Trajectory class for better clarity. - Enhanced assertion error message formatting in OpenAICompatibleTinkerServer for consistency.
1 parent 4683fd0 commit 568dedc

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

src/art/tinker/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ async def chat_completions(
133133
choices: list[Choice] = []
134134
for i, sequence in enumerate(sample_response.sequences):
135135
assert sequence.logprobs is not None, "Logprobs are required"
136-
assert len(sequence.tokens) == len(
137-
sequence.logprobs
138-
), "Tokens and logprobs must have the same length"
136+
assert len(sequence.tokens) == len(sequence.logprobs), (
137+
"Tokens and logprobs must have the same length"
138+
)
139139
rendered_response_tokens = renderer.tokenizer.encode(
140140
renderer.tokenizer.decode(sequence.tokens)
141141
)

src/art/trajectories.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,9 @@ def for_logging(self) -> dict[str, Any]:
9292
for message_or_choice in self.messages_and_choices:
9393
trainable = isinstance(message_or_choice, Choice)
9494
message = (
95-
message_or_choice.message.to_dict()
96-
if trainable
97-
else message_or_choice # ty:ignore[possibly-missing-attribute]
95+
message_or_choice.message.to_dict() if trainable else message_or_choice # ty:ignore[possibly-missing-attribute]
9896
)
99-
loggable_dict["messages"].append(
100-
{**message, "trainable": trainable}
101-
) # ty:ignore[invalid-argument-type, possibly-missing-attribute]
97+
loggable_dict["messages"].append({**message, "trainable": trainable}) # ty:ignore[invalid-argument-type, possibly-missing-attribute]
10298
return loggable_dict
10399

104100

0 commit comments

Comments
 (0)