Download src/workflow/problem-framing/format-repair.ts from Bin29/ManimCat: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/Bin29/ManimCat/resolve/main/src/workflow/problem-framing/format-repair.ts
- Command line
-
hf download hf://spaces/Bin29/ManimCat/src/workflow/problem-framing/format-repair.ts
-
curl -L -o format-repair.ts https://huggingface.co/spaces/Bin29/ManimCat/resolve/main/src/workflow/problem-framing/format-repair.ts
1.26 kB
| import { | |
| parseProblemFramingResponse, | |
| ProblemFramingFormatError, | |
| type ProblemFramingPlan, | |
| } from './parser' | |
| import type { PromptLocale } from '../../types' | |
| interface ProblemFramingFormatRepairOptions { | |
| content: string | |
| locale: PromptLocale | |
| requireDesignFields?: boolean | |
| maxRepairAttempts: number | |
| repair: (input: { | |
| content: string | |
| error: string | |
| attempt: number | |
| }) => Promise<string> | |
| } | |
| export async function parseProblemFramingWithRepair( | |
| options: ProblemFramingFormatRepairOptions, | |
| ): Promise<ProblemFramingPlan> { | |
| let content = options.content | |
| let lastError: ProblemFramingFormatError | undefined | |
| for (let attempt = 0; attempt <= options.maxRepairAttempts; attempt += 1) { | |
| try { | |
| return parseProblemFramingResponse(content, options.locale, options.requireDesignFields) | |
| } catch (error) { | |
| if (!(error instanceof ProblemFramingFormatError)) { | |
| throw error | |
| } | |
| lastError = error | |
| if (attempt >= options.maxRepairAttempts) { | |
| break | |
| } | |
| content = await options.repair({ | |
| content, | |
| error: error.message, | |
| attempt: attempt + 1, | |
| }) | |
| } | |
| } | |
| throw lastError || new ProblemFramingFormatError('Unable to parse problem framing response') | |
| } | |