|
1 | 1 | import inspect |
2 | 2 | import json |
3 | | -from copy import deepcopy |
4 | 3 | from collections import deque |
5 | | -from typing import TYPE_CHECKING |
| 4 | +from copy import deepcopy |
6 | 5 | from sys import getsizeof |
| 6 | +from typing import TYPE_CHECKING |
7 | 7 |
|
8 | 8 | if TYPE_CHECKING: |
9 | 9 | from typing import Any, Callable, Dict, List, Optional, Tuple |
@@ -107,8 +107,9 @@ def get_start_span_function() -> "Callable[..., Any]": |
107 | 107 | return sentry_sdk.start_span if transaction_exists else sentry_sdk.start_transaction |
108 | 108 |
|
109 | 109 |
|
110 | | -def _truncate_single_message_content_if_present(message: "Tuple[Dict[str, Any], int]", max_chars: int) -> "Dict[str, Any]": |
111 | | - # type: (Dict[str, Any], int) -> Dict[str, Any] |
| 110 | +def _truncate_single_message_content_if_present( |
| 111 | + message: "Dict[str, Any]", max_chars: int |
| 112 | +) -> "Dict[str, Any]": |
112 | 113 | """ |
113 | 114 | Truncate a message's content to at most `max_chars` characters and append an |
114 | 115 | ellipsis if truncation occurs. |
@@ -144,7 +145,7 @@ def truncate_messages_by_size( |
144 | 145 | messages: "List[Dict[str, Any]]", |
145 | 146 | max_bytes: int = MAX_GEN_AI_MESSAGE_BYTES, |
146 | 147 | max_single_message_chars: int = MAX_SINGLE_MESSAGE_CONTENT_CHARS, |
147 | | -): |
| 148 | +) -> "Tuple[List[Dict[str, Any]], int]": |
148 | 149 | """ |
149 | 150 | Returns a truncated messages list, consisting of |
150 | 151 | - the last message, with its content truncated to `max_single_message_chars` characters, |
|
0 commit comments