Skip to content

Commit 40dc0be

Browse files
feat(tools): Publicly accessible PDF file URL is not yet supported in the input_file content data. Fixes 216 (#225)
* Fix #216 Publicly accessible PDF file URL is not yet supported in the input_file content data * changeset * URL to url Fixes #216 --------- Co-authored-by: Dominik Kundel <[email protected]>
1 parent 98b8fcf commit 40dc0be

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

.changeset/young-birds-hammer.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@openai/agents-openai': patch
3+
'@openai/agents-core': patch
4+
---
5+
6+
Fix #216 Publicly accessible PDF file URL is not yet supported in the input_file content data

examples/basic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"start:previous-response-id": "tsx previous-response-id.ts",
1818
"start:prompt": "tsx prompt-id.ts",
1919
"start:remote-image": "tsx remote-image.ts",
20+
"start:remote-pdf": "tsx remote-pdf.ts",
2021
"start:stream-items": "tsx stream-items.ts",
2122
"start:stream-text": "tsx stream-text.ts",
2223
"start:json-schema-output-type": "tsx json-schema-output-type.ts",

examples/basic/remote-image.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Agent, run } from '@openai/agents';
22

3-
const URL =
3+
const url =
44
'https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg';
55

66
async function main() {
@@ -15,7 +15,7 @@ async function main() {
1515
content: [
1616
{
1717
type: 'input_image',
18-
image: URL,
18+
image: url,
1919
providerData: {
2020
detail: 'auto',
2121
},

examples/basic/remote-pdf.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Agent, run } from '@openai/agents';
2+
3+
const url = 'https://www.berkshirehathaway.com/letters/2024ltr.pdf';
4+
5+
async function main() {
6+
const agent = new Agent({
7+
name: 'Assistant',
8+
instructions: 'You are a helpful assistant.',
9+
});
10+
11+
const result = await run(agent, [
12+
{
13+
role: 'user',
14+
content: [{ type: 'input_file', file: url }],
15+
},
16+
{
17+
role: 'user',
18+
content: 'Can you summarize the letter?',
19+
},
20+
]);
21+
22+
console.log(result.finalOutput);
23+
}
24+
25+
if (require.main === module) {
26+
main().catch(console.error);
27+
}

packages/agents-core/src/types/protocol.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,17 @@ export const InputFile = SharedBase.extend({
9191
*/
9292
file: z
9393
.string()
94+
.describe(
95+
'Either base64 encoded file data or a publicly accessible file URL',
96+
)
9497
.or(
9598
z.object({
96-
id: z.string(),
99+
id: z.string().describe('OpenAI file ID'),
100+
}),
101+
)
102+
.or(
103+
z.object({
104+
url: z.string().describe('Publicly accessible PDF file URL'),
97105
}),
98106
)
99107
.describe('Contents of the file or an object with a file ID.'),

packages/agents-openai/src/openaiResponsesModel.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,19 @@ function getInputMessageContent(
266266
type: 'input_file',
267267
};
268268
if (typeof entry.file === 'string') {
269-
fileEntry.file_data = entry.file;
270-
} else {
269+
if (entry.file.startsWith('data:')) {
270+
fileEntry.file_data = entry.file;
271+
} else if (entry.file.startsWith('https://')) {
272+
fileEntry.file_url = entry.file;
273+
} else {
274+
throw new UserError(
275+
`Unsupported string data for file input. If you're trying to pass an uploaded file's ID, use an object with the ID property instead.`,
276+
);
277+
}
278+
} else if ('id' in entry.file) {
271279
fileEntry.file_id = entry.file.id;
280+
} else if ('url' in entry.file) {
281+
fileEntry.file_url = entry.file.url;
272282
}
273283
return {
274284
...fileEntry,

0 commit comments

Comments
 (0)