Skip to content

Commit 656c0e4

Browse files
committed
refactor: reorganize imports and improve code readability in trajectories.py
- Adjusted import order and spacing for consistency. - Enhanced readability of the loggable_dict construction in the Trajectory class. - Streamlined metadata handling in the TrajectoryGroup class.
1 parent fb94450 commit 656c0e4

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/art/trajectories.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import asyncio
2-
import time
3-
import traceback
42
from contextlib import asynccontextmanager
53
from datetime import datetime
4+
import time
5+
import traceback
66
from typing import (
77
Any,
88
AsyncGenerator,
@@ -14,8 +14,8 @@
1414
overload,
1515
)
1616

17-
import pydantic
1817
from openai.types.chat.chat_completion import Choice
18+
import pydantic
1919

2020
from .types import Messages, MessagesAndChoices, Tools
2121

@@ -92,9 +92,13 @@ 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() if trainable else message_or_choice # ty:ignore[possibly-missing-attribute]
95+
message_or_choice.message.to_dict()
96+
if trainable
97+
else message_or_choice # ty:ignore[possibly-missing-attribute]
9698
)
97-
loggable_dict["messages"].append({**message, "trainable": trainable}) # ty:ignore[invalid-argument-type, possibly-missing-attribute]
99+
loggable_dict["messages"].append(
100+
{**message, "trainable": trainable}
101+
) # ty:ignore[invalid-argument-type, possibly-missing-attribute]
98102
return loggable_dict
99103

100104

@@ -173,9 +177,9 @@ def __init__(
173177
+ exceptions
174178
)
175179
],
176-
metadata=metadata
177-
if metadata is not None
178-
else getattr(self, "metadata", {}),
180+
metadata=(
181+
metadata if metadata is not None else getattr(self, "metadata", {})
182+
),
179183
metrics=metrics if metrics is not None else getattr(self, "metrics", {}),
180184
logs=logs if logs is not None else getattr(self, "logs", []),
181185
)

0 commit comments

Comments
 (0)