@@ -49,23 +49,6 @@ def read_df(filename: Path, **pandas_kwargs) -> pd.DataFrame:
4949 return pd .read_parquet (filename , ** pandas_kwargs )
5050
5151
52- def truncate (s : str , max_len : int | None = None ) -> str :
53- if not isinstance (s , str ):
54- return ""
55- if max_len is not None :
56- return s [:max_len ]
57- return s
58-
59-
60- def safe_text (value : object , truncate_chars : int | None ) -> str :
61- if value is None :
62- return ""
63- is_missing = pd .isna (value )
64- if isinstance (is_missing , bool ) and is_missing :
65- return ""
66- return truncate (str (value ), max_len = truncate_chars )
67-
68-
6952def compute_pref_summary (prefs : pd .Series ) -> dict [str , float | int ]:
7053 """Compute win/loss/tie stats for preference series (0=A, 0.5=tie, 1=B)."""
7154 prefs = pd .Series (prefs , dtype = "float64" )
@@ -99,6 +82,20 @@ def truncate(s: str, max_len: int | None = None) -> str:
9982 return s
10083
10184
85+ def safe_text (value : object , truncate_chars : int | None ) -> str :
86+ """Coerce *value* to a string and optionally truncate.
87+
88+ Returns the empty string for ``None`` and NaN-like values so callers
89+ don't have to guard against missing data.
90+ """
91+ if value is None :
92+ return ""
93+ is_missing = pd .isna (value )
94+ if isinstance (is_missing , bool ) and is_missing :
95+ return ""
96+ return truncate (str (value ), max_len = truncate_chars )
97+
98+
10299def do_inference (chat_model , inputs , use_tqdm : bool = False ):
103100 # Retries on rate-limit/server errors with exponential backoff.
104101 # Async path retries individual calls; batch path splits into 4^attempt chunks on failure.
0 commit comments