MCPcopy Create free account
hub / github.com/AndrewWTY/UNIT / transform_data

Function transform_data

src/make_data_ref.py:235–292  ·  view source on GitHub ↗
(rows, all_info_seeking=False, no_surgery=False)

Source from the content-addressed store, hash-verified

233
234# ---------- Final multi-turn structure ----------------------------------- #
235def transform_data(rows, all_info_seeking=False, no_surgery=False):
236 out = []
237
238 SYS_MESSAGE_INFO = (
239 "You are a helpful assistant. "
240 "You should answer the user's query first. "
241 "Then write a <reflection> section listing the factual claims you are uncertain about."
242 )
243 SYS_MESSAGE_OTHER = (
244 "You are a helpful assistant. "
245 "Answer the user's query directly and accurately."
246 )
247
248 def is_info(d):
249 if all_info_seeking:
250 return d.get("primary_tag", "").lower() == "information seeking"
251 return d.get("primary_tag", "").lower() == "information seeking" and d.get(
252 "other_tags"
253 ) is None
254
255 for d in rows:
256 # choose system + assistant content
257 if no_surgery:
258 sys_msg = SYS_MESSAGE_OTHER
259 assistant_content = d["response"]
260 else:
261 if is_info(d):
262 sys_msg = SYS_MESSAGE_INFO
263 assistant_content = d.get("surgery_response", d["response"])
264 else:
265 sys_msg = SYS_MESSAGE_OTHER
266 assistant_content = d["response"]
267
268 transformed = {
269 "prompt": d.get("instruction", ""),
270 "chosen": [
271 {"role": "system", "content": sys_msg},
272 {"role": "user", "content": d.get("instruction", "")},
273 {"role": "assistant", "content": assistant_content},
274 ],
275 "rejected": [
276 {"role": "system", "content": sys_msg},
277 {"role": "user", "content": d.get("instruction", "")},
278 {"role": "assistant", "content": d["response"]},
279 ],
280 "messages": [
281 {"role": "system", "content": sys_msg},
282 {"role": "user", "content": d.get("instruction", "")},
283 {"role": "assistant", "content": assistant_content},
284 ],
285 # carry-through extras
286 "response": d["response"],
287 "info-seeking": d.get("info-seeking", False),
288 "certain_claims": d.get("certain_claims", []),
289 "uncertain_claims": d.get("uncertain_claims", []),
290 }
291 out.append(transformed)
292 return out

Callers 1

mainFunction · 0.85

Calls 1

is_infoFunction · 0.70

Tested by

no test coverage detected