| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function extractLanguageInstructions( |
| episodeData: Record<string, unknown>[], |
| sampleIndices: number[] = [0], |
| ): string | undefined { |
| if (episodeData.length === 0) return undefined; |
|
|
| const languageInstructions: string[] = []; |
|
|
| |
| for (const idx of sampleIndices) { |
| if (idx >= episodeData.length) continue; |
|
|
| const row = episodeData[idx]; |
|
|
| |
| if ( |
| "language_instruction" in row && |
| typeof row.language_instruction === "string" && |
| row.language_instruction |
| ) { |
| languageInstructions.push(row.language_instruction); |
|
|
| |
| let instructionNum = 2; |
| let key = `language_instruction_${instructionNum}`; |
| while (key in row && typeof row[key] === "string") { |
| languageInstructions.push(row[key] as string); |
| instructionNum++; |
| key = `language_instruction_${instructionNum}`; |
| } |
|
|
| |
| if (languageInstructions.length > 0) break; |
| } |
| } |
|
|
| return languageInstructions.length > 0 |
| ? languageInstructions.join("\n") |
| : undefined; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function extractTaskFromMetadata( |
| taskIndex: unknown, |
| tasksData: Record<string, unknown>[], |
| ): string | undefined { |
| |
| const taskIndexNum = |
| typeof taskIndex === "bigint" |
| ? Number(taskIndex) |
| : typeof taskIndex === "number" |
| ? taskIndex |
| : undefined; |
|
|
| if (taskIndexNum === undefined || taskIndexNum < 0) { |
| return undefined; |
| } |
|
|
| if (taskIndexNum >= tasksData.length) { |
| return undefined; |
| } |
|
|
| const taskData = tasksData[taskIndexNum]; |
|
|
| |
| if ( |
| taskData && |
| "__index_level_0__" in taskData && |
| typeof taskData.__index_level_0__ === "string" |
| ) { |
| return taskData.__index_level_0__; |
| } else if ( |
| taskData && |
| "task" in taskData && |
| typeof taskData.task === "string" |
| ) { |
| return taskData.task; |
| } |
|
|
| return undefined; |
| } |
|
|