Spaces:
Paused
Paused
Move question example to types/example.ts
Browse files- src/lib/csvUtils.ts +9 -24
- src/types/example.ts +9 -0
src/lib/csvUtils.ts
CHANGED
|
@@ -1,28 +1,13 @@
|
|
| 1 |
import fs from 'fs';
|
| 2 |
import path from 'path';
|
|
|
|
| 3 |
|
| 4 |
-
export
|
| 5 |
-
年度: string;
|
| 6 |
-
題號: string;
|
| 7 |
-
子題型: string;
|
| 8 |
-
題幹: string;
|
| 9 |
-
選項: string;
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
export interface ParagraphDetailsExample {
|
| 13 |
-
年度: string;
|
| 14 |
-
題號: string;
|
| 15 |
-
子題型: string;
|
| 16 |
-
題幹: string;
|
| 17 |
-
選項: string;
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
export async function loadParagraphSummaryExamples(): Promise<ParagraphSummaryExample[]> {
|
| 21 |
try {
|
| 22 |
const csvPath = path.join(process.cwd(), 'public', 'data', 'paragraph_summary.csv');
|
| 23 |
const csvContent = fs.readFileSync(csvPath, 'utf-8');
|
| 24 |
|
| 25 |
-
const examples:
|
| 26 |
const lines = csvContent.split('\n');
|
| 27 |
let i = 1; // Skip header
|
| 28 |
|
|
@@ -55,12 +40,12 @@ export async function loadParagraphSummaryExamples(): Promise<ParagraphSummaryEx
|
|
| 55 |
}
|
| 56 |
}
|
| 57 |
|
| 58 |
-
export async function loadParagraphDetailsExamples(): Promise<
|
| 59 |
try {
|
| 60 |
const csvPath = path.join(process.cwd(), 'public', 'data', 'paragraph_details.csv');
|
| 61 |
const csvContent = fs.readFileSync(csvPath, 'utf-8');
|
| 62 |
|
| 63 |
-
const examples:
|
| 64 |
const lines = csvContent.split('\n');
|
| 65 |
let i = 1; // Skip header
|
| 66 |
|
|
@@ -126,7 +111,7 @@ function parseCSVEntry(lines: string[], startIndex: number): { values: string[],
|
|
| 126 |
};
|
| 127 |
}
|
| 128 |
|
| 129 |
-
export function getUniqueSubTypes(examples:
|
| 130 |
const subTypes = new Set<string>();
|
| 131 |
examples.forEach(example => {
|
| 132 |
if (example.子題型) {
|
|
@@ -136,11 +121,11 @@ export function getUniqueSubTypes(examples: ParagraphSummaryExample[]): string[]
|
|
| 136 |
return Array.from(subTypes);
|
| 137 |
}
|
| 138 |
|
| 139 |
-
export function getExamplesBySubType(examples:
|
| 140 |
return examples.filter(example => example.子題型 === subType);
|
| 141 |
}
|
| 142 |
|
| 143 |
-
export function getParagraphDetailsUniqueSubTypes(examples:
|
| 144 |
const subTypes = new Set<string>();
|
| 145 |
examples.forEach(example => {
|
| 146 |
if (example.子題型) {
|
|
@@ -150,7 +135,7 @@ export function getParagraphDetailsUniqueSubTypes(examples: ParagraphDetailsExam
|
|
| 150 |
return Array.from(subTypes);
|
| 151 |
}
|
| 152 |
|
| 153 |
-
export function getParagraphDetailsExamplesBySubType(examples:
|
| 154 |
return examples.filter(example => example.子題型 === subType);
|
| 155 |
}
|
| 156 |
|
|
|
|
| 1 |
import fs from 'fs';
|
| 2 |
import path from 'path';
|
| 3 |
+
import type { PromptExample } from '@/types/example';
|
| 4 |
|
| 5 |
+
export async function loadParagraphSummaryExamples(): Promise<PromptExample[]> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
try {
|
| 7 |
const csvPath = path.join(process.cwd(), 'public', 'data', 'paragraph_summary.csv');
|
| 8 |
const csvContent = fs.readFileSync(csvPath, 'utf-8');
|
| 9 |
|
| 10 |
+
const examples: PromptExample[] = [];
|
| 11 |
const lines = csvContent.split('\n');
|
| 12 |
let i = 1; // Skip header
|
| 13 |
|
|
|
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
+
export async function loadParagraphDetailsExamples(): Promise<PromptExample[]> {
|
| 44 |
try {
|
| 45 |
const csvPath = path.join(process.cwd(), 'public', 'data', 'paragraph_details.csv');
|
| 46 |
const csvContent = fs.readFileSync(csvPath, 'utf-8');
|
| 47 |
|
| 48 |
+
const examples: PromptExample[] = [];
|
| 49 |
const lines = csvContent.split('\n');
|
| 50 |
let i = 1; // Skip header
|
| 51 |
|
|
|
|
| 111 |
};
|
| 112 |
}
|
| 113 |
|
| 114 |
+
export function getUniqueSubTypes(examples: PromptExample[]): string[] {
|
| 115 |
const subTypes = new Set<string>();
|
| 116 |
examples.forEach(example => {
|
| 117 |
if (example.子題型) {
|
|
|
|
| 121 |
return Array.from(subTypes);
|
| 122 |
}
|
| 123 |
|
| 124 |
+
export function getExamplesBySubType(examples: PromptExample[], subType: string): PromptExample[] {
|
| 125 |
return examples.filter(example => example.子題型 === subType);
|
| 126 |
}
|
| 127 |
|
| 128 |
+
export function getParagraphDetailsUniqueSubTypes(examples: PromptExample[]): string[] {
|
| 129 |
const subTypes = new Set<string>();
|
| 130 |
examples.forEach(example => {
|
| 131 |
if (example.子題型) {
|
|
|
|
| 135 |
return Array.from(subTypes);
|
| 136 |
}
|
| 137 |
|
| 138 |
+
export function getParagraphDetailsExamplesBySubType(examples: PromptExample[], subType: string): PromptExample[] {
|
| 139 |
return examples.filter(example => example.子題型 === subType);
|
| 140 |
}
|
| 141 |
|
src/types/example.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Example question types used for in-context learning in prompts
|
| 2 |
+
export interface PromptExample {
|
| 3 |
+
年度: string;
|
| 4 |
+
題號: string;
|
| 5 |
+
子題型: string;
|
| 6 |
+
題幹: string;
|
| 7 |
+
選項: string;
|
| 8 |
+
}
|
| 9 |
+
|