Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions examples/basic/local-file.ts
Original file line number Diff line number Diff line change
@@ -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);
}
Binary file not shown.
3 changes: 2 additions & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}