|
1 | 1 | import asyncio |
2 | | -import time |
3 | | -import traceback |
4 | 2 | from contextlib import asynccontextmanager |
5 | 3 | from datetime import datetime |
| 4 | +import time |
| 5 | +import traceback |
6 | 6 | from typing import ( |
7 | 7 | Any, |
8 | 8 | AsyncGenerator, |
|
14 | 14 | overload, |
15 | 15 | ) |
16 | 16 |
|
17 | | -import pydantic |
18 | 17 | from openai.types.chat.chat_completion import Choice |
| 18 | +import pydantic |
19 | 19 |
|
20 | 20 | from .types import Messages, MessagesAndChoices, Tools |
21 | 21 |
|
@@ -92,9 +92,13 @@ def for_logging(self) -> dict[str, Any]: |
92 | 92 | for message_or_choice in self.messages_and_choices: |
93 | 93 | trainable = isinstance(message_or_choice, Choice) |
94 | 94 | 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] |
96 | 98 | ) |
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] |
98 | 102 | return loggable_dict |
99 | 103 |
|
100 | 104 |
|
@@ -173,9 +177,9 @@ def __init__( |
173 | 177 | + exceptions |
174 | 178 | ) |
175 | 179 | ], |
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 | + ), |
179 | 183 | metrics=metrics if metrics is not None else getattr(self, "metrics", {}), |
180 | 184 | logs=logs if logs is not None else getattr(self, "logs", []), |
181 | 185 | ) |
|
0 commit comments