( model: string, limit: number = 100, userId: string | undefined = undefined, dataset: string = DATASET, )
| 308 | } |
| 309 | |
| 310 | export async function getTracesWithoutRelabels( |
| 311 | model: string, |
| 312 | limit: number = 100, |
| 313 | userId: string | undefined = undefined, |
| 314 | dataset: string = DATASET, |
| 315 | ) { |
| 316 | const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) |
| 317 | .toISOString() |
| 318 | .split('T')[0] |
| 319 | |
| 320 | const query = ` |
| 321 | SELECT t.* |
| 322 | FROM \`${dataset}.${TRACES_TABLE}\` t |
| 323 | LEFT JOIN ( |
| 324 | SELECT r.agent_step_id, r.user_id, JSON_EXTRACT_SCALAR(r.payload, '$.user_input_id') as user_input_id |
| 325 | FROM \`${dataset}.${RELABELS_TABLE}\` r |
| 326 | WHERE r.model = @model |
| 327 | ${userId ? `AND r.user_id = @userId` : ''} |
| 328 | ) r |
| 329 | ON t.agent_step_id = r.agent_step_id |
| 330 | AND t.user_id = r.user_id |
| 331 | AND JSON_EXTRACT_SCALAR(t.payload, '$.user_input_id') = r.user_input_id |
| 332 | WHERE t.type = 'get-relevant-files' |
| 333 | AND t.created_at >= @thirtyDaysAgo |
| 334 | AND r.agent_step_id IS NULL |
| 335 | ${userId ? `AND t.user_id = @userId` : ''} |
| 336 | ORDER BY t.created_at DESC |
| 337 | LIMIT @limit |
| 338 | ` |
| 339 | |
| 340 | const [rows] = await getClient().query({ |
| 341 | query, |
| 342 | params: { |
| 343 | model, |
| 344 | thirtyDaysAgo, |
| 345 | limit, |
| 346 | ...(userId ? { userId } : {}), |
| 347 | }, |
| 348 | }) |
| 349 | // Parse the payload as JSON if it's a string |
| 350 | return rows.map((row) => ({ |
| 351 | ...row, |
| 352 | payload: |
| 353 | typeof row.payload === 'string' ? JSON.parse(row.payload) : row.payload, |
| 354 | })) as GetRelevantFilesTrace[] |
| 355 | } |
| 356 | |
| 357 | export async function getTracesWithRelabels( |
| 358 | model: string, |
no test coverage detected