Skip to content
Closed
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
16 changes: 4 additions & 12 deletions packages/core/src/core/openaiContentGenerator/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,12 @@ describe('OpenAIContentConverter', () => {
const contentArray = toolMessage?.content as Array<{
type: string;
text?: string;
file?: { filename: string; file_data: string };
}>;
expect(contentArray).toHaveLength(2);
expect(contentArray[0].type).toBe('text');
expect(contentArray[0].text).toBe('PDF content');
expect(contentArray[1].type).toBe('file');
expect(contentArray[1].file?.filename).toBe('document.pdf');
expect(contentArray[1].file?.file_data).toBe(
'data:application/pdf;base64,base64pdfdata',
);
expect(contentArray[1].type).toBe('text');
expect(contentArray[1].text).toContain('PDF file: document.pdf');

// No separate user message should be created
const userMessage = messages.find((message) => message.role === 'user');
Expand Down Expand Up @@ -534,16 +530,12 @@ describe('OpenAIContentConverter', () => {
const contentArray = toolMessage?.content as Array<{
type: string;
text?: string;
file?: { filename: string; file_data: string };
}>;
expect(contentArray).toHaveLength(2);
expect(contentArray[0].type).toBe('text');
expect(contentArray[0].text).toBe('PDF content');
expect(contentArray[1].type).toBe('file');
expect(contentArray[1].file?.filename).toBe('document.pdf');
expect(contentArray[1].file?.file_data).toBe(
'https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf',
);
expect(contentArray[1].type).toBe('text');
expect(contentArray[1].text).toContain('PDF file: document.pdf');
});

it('should convert video inlineData to tool message with embedded video_url', () => {
Expand Down
27 changes: 6 additions & 21 deletions packages/core/src/core/openaiContentGenerator/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,11 @@ type OpenAIContentPartVideoUrl = {
};
};

type OpenAIContentPartFile = {
type: 'file';
file: {
filename: string;
file_data: string;
};
};

type OpenAIContentPart =
| OpenAI.Chat.ChatCompletionContentPartText
| OpenAI.Chat.ChatCompletionContentPartImage
| OpenAI.Chat.ChatCompletionContentPartInputAudio
| OpenAIContentPartVideoUrl
| OpenAIContentPartFile;
| OpenAIContentPartVideoUrl;

/**
* Converter class for transforming data between Gemini and OpenAI formats
Expand Down Expand Up @@ -600,13 +591,10 @@ export class OpenAIContentConverter {
}

if (mimeType === 'application/pdf') {
const filename = part.inlineData.displayName || 'document.pdf';
const displayName = part.inlineData.displayName || 'document.pdf';
return {
type: 'file' as const,
file: {
filename,
file_data: `data:${mimeType};base64,${part.inlineData.data}`,
},
type: 'text' as const,
text: `[PDF file: ${displayName} - PDF content cannot be directly displayed in this context. Please use a text extraction tool or ask the user to provide the content in text format.]`,
};
}

Expand Down Expand Up @@ -656,11 +644,8 @@ export class OpenAIContentConverter {

if (mimeType === 'application/pdf') {
return {
type: 'file' as const,
file: {
filename,
file_data: fileUri,
},
type: 'text' as const,
text: `[PDF file: ${filename} - PDF content cannot be directly displayed in this context. Please use a text extraction tool or ask the user to provide the content in text format.]`,
};
}

Expand Down