diff options
| author | sharkiecodes <lanyi_stroud@brown.edu> | 2025-06-01 20:24:04 -0400 |
|---|---|---|
| committer | sharkiecodes <lanyi_stroud@brown.edu> | 2025-06-01 20:24:04 -0400 |
| commit | 7626527799c0606fa9c4fd4d26a19189dc7e7a0e (patch) | |
| tree | 858dca125a097e0b43b1685c0d96e8a2ddf1cb1b /src/client/views/nodes/scrapbook/AIPresetGenerator.ts | |
| parent | c1f4a60b0016242a9097357074730f0cc9c151ba (diff) | |
reactive backgrounds, tagging of pdfs, group-select and suggested templates, text box content influences backgrounds
Diffstat (limited to 'src/client/views/nodes/scrapbook/AIPresetGenerator.ts')
| -rw-r--r-- | src/client/views/nodes/scrapbook/AIPresetGenerator.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/client/views/nodes/scrapbook/AIPresetGenerator.ts b/src/client/views/nodes/scrapbook/AIPresetGenerator.ts new file mode 100644 index 000000000..1f159222b --- /dev/null +++ b/src/client/views/nodes/scrapbook/AIPresetGenerator.ts @@ -0,0 +1,31 @@ +import { ScrapbookItemConfig } from './ScrapbookPreset'; +import { GPTCallType, gptAPICall } from '../../../apis/gpt/GPT'; + +// Represents the descriptor for each document +export interface DocumentDescriptor { + type: string; + tags: string[]; +} + +// Main function to request AI-generated presets +export async function requestAiGeneratedPreset(descriptors: DocumentDescriptor[]): Promise<ScrapbookItemConfig[]> { + const prompt = createPrompt(descriptors); + let aiResponse = await gptAPICall(prompt, GPTCallType.GENERATESCRAPBOOK); + // Strip out ```json and ``` if the model wrapped its answer in fences + aiResponse = aiResponse + .trim() + .replace(/^```(?:json)?\s*/, "") // remove leading ``` or ```json + .replace(/\s*```$/, ""); // remove trailing ``` + const parsedPreset = JSON.parse(aiResponse) as ScrapbookItemConfig[]; + return parsedPreset; +} + +// Helper to generate prompt text for AI +function createPrompt(descriptors: DocumentDescriptor[]): string { + let prompt = ""; + descriptors.forEach((desc, index) => { + prompt += `${index + 1}. Type: ${desc.type}, Tags: ${desc.tags.join(', ')}\n`; + }); + + return prompt; +} |
