diff --git a/examples/basic/local-file.ts b/examples/basic/local-file.ts new file mode 100644 index 00000000..5b4ebfc6 --- /dev/null +++ b/examples/basic/local-file.ts @@ -0,0 +1,47 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { Agent, run } from '@openai/agents'; + +const filePath = path.join( + __dirname, + 'media/partial_o3-and-o4-mini-system-card.pdf', +); + +function fileToBase64(filePath: string): string { + const fileBuffer = fs.readFileSync(filePath); + return fileBuffer.toString('base64'); +} + +async function main() { + const agent = new Agent({ + name: 'Assistant', + instructions: 'You are a helpful assistant.', + }); + + const b64File = fileToBase64(filePath); + const result = await run(agent, [ + { + role: 'user', + content: [ + { + type: 'input_file', + file: `data:application/pdf;base64,${b64File}`, + providerData: { + filename: 'partial_o3-and-o4-mini-system-card.pdf', + }, + }, + ], + }, + { + role: 'user', + content: 'What is the first sentence of the introduction?', + }, + ]); + + console.log(result.finalOutput); + // OpenAI o3 and OpenAI o4-mini combine state-of-the-art reasoning with full tool capabilities — web browsing, Python, image and file analysis, image generation, canvas, automations, file search, and memory. +} + +if (require.main === module) { + main().catch(console.error); +} diff --git a/examples/basic/media/partial_o3-and-o4-mini-system-card.pdf b/examples/basic/media/partial_o3-and-o4-mini-system-card.pdf new file mode 100644 index 00000000..e4e0feaa Binary files /dev/null and b/examples/basic/media/partial_o3-and-o4-mini-system-card.pdf differ diff --git a/examples/basic/package.json b/examples/basic/package.json index a6806bf8..896163fe 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -21,6 +21,7 @@ "start:json-schema-output-type": "tsx json-schema-output-type.ts", "start:tool-use-behavior": "tsx tool-use-behavior.ts", "start:tools": "tsx tools.ts", - "start:reasoning": "tsx reasoning.ts" + "start:reasoning": "tsx reasoning.ts", + "start:local-file": "tsx local-file.ts" } }