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
6 changes: 6 additions & 0 deletions .changeset/young-birds-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@openai/agents-openai': patch
'@openai/agents-core': patch
---

Fix #216 Publicly accessible PDF file URL is not yet supported in the input_file content data
1 change: 1 addition & 0 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"start:previous-response-id": "tsx previous-response-id.ts",
"start:prompt": "tsx prompt-id.ts",
"start:remote-image": "tsx remote-image.ts",
"start:remote-pdf": "tsx remote-pdf.ts",
"start:stream-items": "tsx stream-items.ts",
"start:stream-text": "tsx stream-text.ts",
"start:json-schema-output-type": "tsx json-schema-output-type.ts",
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/remote-image.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Agent, run } from '@openai/agents';

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

async function main() {
Expand All @@ -15,7 +15,7 @@ async function main() {
content: [
{
type: 'input_image',
image: URL,
image: url,
providerData: {
detail: 'auto',
},
Expand Down
27 changes: 27 additions & 0 deletions examples/basic/remote-pdf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Agent, run } from '@openai/agents';

const url = 'https://www.berkshirehathaway.com/letters/2024ltr.pdf';

async function main() {
const agent = new Agent({
name: 'Assistant',
instructions: 'You are a helpful assistant.',
});

const result = await run(agent, [
{
role: 'user',
content: [{ type: 'input_file', file: url }],
},
{
role: 'user',
content: 'Can you summarize the letter?',
},
]);

console.log(result.finalOutput);
}

if (require.main === module) {
main().catch(console.error);
}
10 changes: 9 additions & 1 deletion packages/agents-core/src/types/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@ export const InputFile = SharedBase.extend({
*/
file: z
.string()
.describe(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

developers can pass 1) as string or 2) { url: '....' }

'Either base64 encoded file data or a publicly accessible file URL',
)
.or(
z.object({
id: z.string(),
id: z.string().describe('OpenAI file ID'),
}),
)
.or(
z.object({
url: z.string().describe('Publicly accessible PDF file URL'),
}),
)
.describe('Contents of the file or an object with a file ID.'),
Expand Down
14 changes: 12 additions & 2 deletions packages/agents-openai/src/openaiResponsesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,19 @@ function getInputMessageContent(
type: 'input_file',
};
if (typeof entry.file === 'string') {
fileEntry.file_data = entry.file;
} else {
if (entry.file.startsWith('data:')) {
fileEntry.file_data = entry.file;
} else if (entry.file.startsWith('https://')) {
fileEntry.file_url = entry.file;
} else {
throw new UserError(
`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.`,
);
}
} else if ('id' in entry.file) {
fileEntry.file_id = entry.file.id;
} else if ('url' in entry.file) {
fileEntry.file_url = entry.file.url;
}
return {
...fileEntry,
Expand Down