Appearance
Function: askFile()
ts
function askFile(
ctx: Context,
file: MwFile,
options: AskFileOptions): Promise<
| {
object: unknown;
text?: undefined;
}
| {
object?: undefined;
text: string;
}>;Defined in: src/ai/askFile.tsx:38
Process a file with OCR (for PDFs and images) or direct text extraction, then send it to an AI model with a prompt.
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context | Assistant context that holds secrets and configuration. |
file | MwFile | The file to process. PDF and image files go through OCR first. |
options | AskFileOptions | Prompt text, optional OCR settings, and AI provider config. |
Returns
Promise< | { object: unknown; text?: undefined; } | { object?: undefined; text: string; }>
The AI response containing generated text.
Example
ts
const response = await askFile(ctx, recipePhoto, {
prompt: 'List every ingredient you can see in this photo.',
provider: SkillSecretType.OpenAi,
config: { openAiApiKey: 'your-api-key' },
model: 'gpt-4o-mini',
ocrOptions: {
endpoint: 'https://my-ocr.cognitiveservices.azure.com/',
key: 'ocr-key-123',
},
});
console.log(response.text);
// "flour, sugar, butter, vanilla extract, 3 eggs..."