File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change 7
7
from onyx .configs .app_configs import BRAINTRUST_API_KEY
8
8
from onyx .configs .app_configs import BRAINTRUST_PROJECT
9
9
10
+ MASKING_LENGTH = 20000
10
11
11
- def _truncate_str (s : str , head : int = 800 , tail : int = 200 ) -> str :
12
- if len (s ) <= head + tail :
13
- return s
14
- return f"{ s [:head ]} …{ s [- tail :]} [TRUNCATED { len (s )} chars to 10,000]"
12
+
13
+ def _truncate_str (s : str ) -> str :
14
+ tail = MASKING_LENGTH // 5
15
+ head = MASKING_LENGTH - tail
16
+ return f"{ s [:head ]} …{ s [- tail :]} [TRUNCATED { len (s )} chars to { MASKING_LENGTH } ]"
17
+
18
+
19
+ def _should_mask (data : Any ) -> bool :
20
+ return len (str (data )) > MASKING_LENGTH
15
21
16
22
17
23
def _mask (data : Any ) -> Any :
18
- data_str = str ( data )
19
- if len ( data_str ) > 10_000 :
20
- return _truncate_str ( data_str )
21
- return data
24
+ """Mask data if it exceeds the maximum length threshold."""
25
+ if not _should_mask ( data ) :
26
+ return data
27
+ return _truncate_str ( str ( data ))
22
28
23
29
24
30
def setup_braintrust () -> None :
You can’t perform that action at this time.
0 commit comments