@@ -14,7 +14,7 @@ import type {
1414 PromptGeneratorOptions ,
1515 WorkspaceFile ,
1616} from "@genaiscript/core" ;
17- import { resolveChatGenerationContext } from "./runtime.js" ;
17+ import { resolveChatGenerationContext , resolveRuntime } from "./runtime.js" ;
1818
1919/**
2020 * Converts a PDF file to markdown format with intelligent formatting preservation.
@@ -32,7 +32,8 @@ export async function markdownifyPdf(
3232 ctx ?: ChatGenerationContext ;
3333 } ,
3434) {
35- const ctx = resolveChatGenerationContext ( options ) ;
35+ const generator = resolveChatGenerationContext ( options ) ;
36+ const { parsers } = resolveRuntime ( ) ;
3637 const {
3738 label = `markdownify PDF` ,
3839 model = "ocr" ,
@@ -42,7 +43,7 @@ export async function markdownifyPdf(
4243 } = options || { } ;
4344
4445 // extract text and render pages as images
45- const { pages, images = [ ] } = await globalPromptContext . parsers . PDF ( file , {
46+ const { pages, images = [ ] } = await parsers . PDF ( file , {
4647 ...rest ,
4748 renderAsImage : true ,
4849 } ) ;
@@ -51,7 +52,7 @@ export async function markdownifyPdf(
5152 const page = pages [ i ] ;
5253 const image = images [ i ] ;
5354 // mix of text and vision
54- const res = await ctx . runPrompt (
55+ const res = await generator . runPrompt (
5556 async ( _ ) => {
5657 const previousPages = markdowns . slice ( - 2 ) . join ( "\n\n" ) ;
5758 if ( previousPages . length ) _ . def ( "PREVIOUS_PAGES" , previousPages ) ;
@@ -76,7 +77,7 @@ export async function markdownifyPdf(
7677 - Do not repeat the <PREVIOUS_PAGES> content.
7778 - Do not include any additional explanations or comments in the markdown formatted extracted text.
7879 ` ;
79- if ( image ) globalPromptContext . $ `- For images, generate a short alt-text description.` ;
80+ if ( image ) _ . $ `- For images, generate a short alt-text description.` ;
8081 if ( typeof instructions === "string" ) _ . $ `${ instructions } ` ;
8182 else if ( typeof instructions === "function" ) await instructions ( _ ) ;
8283 } ,
0 commit comments