|
| 1 | +import { Agent, run, tool, ToolOutputFileContent } from '@openai/agents'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import path from 'node:path'; |
| 4 | +import { z } from 'zod'; |
| 5 | + |
| 6 | +const fetchSystemCard = tool({ |
| 7 | + name: 'fetch_system_card', |
| 8 | + description: 'Fetch the system card for the given topic.', |
| 9 | + parameters: z.object({ topic: z.string() }), |
| 10 | + execute: async ({ topic }): Promise<ToolOutputFileContent> => { |
| 11 | + console.log('[tool] Fetching system card for topic:', topic); |
| 12 | + const pdfPath = path.join( |
| 13 | + __dirname, |
| 14 | + 'media', |
| 15 | + 'partial_o3-and-o4-mini-system-card.pdf', |
| 16 | + ); |
| 17 | + return { |
| 18 | + type: 'file', |
| 19 | + file: { |
| 20 | + data: fs.readFileSync(pdfPath), |
| 21 | + mediaType: 'application/pdf', |
| 22 | + filename: 'partial_o3-and-o4-mini-system-card.pdf', |
| 23 | + }, |
| 24 | + }; |
| 25 | + }, |
| 26 | +}); |
| 27 | + |
| 28 | +const agent = new Agent({ |
| 29 | + name: 'System Card Agent', |
| 30 | + instructions: |
| 31 | + "You are a helpful assistant who can fetch system cards. When you cannot find the answer in the data from tools, you must not guess anything. Just say you don't know.", |
| 32 | + tools: [fetchSystemCard], |
| 33 | +}); |
| 34 | + |
| 35 | +async function main() { |
| 36 | + const result = await run( |
| 37 | + agent, |
| 38 | + 'Call fetch_system_card and let me know what version of Preparedness Framework was used?', |
| 39 | + ); |
| 40 | + |
| 41 | + console.log(result.finalOutput); |
| 42 | + // The version of the Preparedness Framework used is Version 2. |
| 43 | +} |
| 44 | + |
| 45 | +if (require.main === module) { |
| 46 | + main().catch(console.error); |
| 47 | +} |
0 commit comments