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
23 changes: 23 additions & 0 deletions packages/api/src/files/encode/document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,29 @@ describe('encodeAndFormatDocuments - fileConfig integration', () => {
expect(result.files).toHaveLength(1);
});

it('should skip file blocks for DeepSeek models routed through the OpenAI provider', async () => {
const req = createMockRequest(15) as ServerRequest;
const mimeType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
const file = createMockDocFile(1, mimeType, 'brief.docx');

const mockContent = Buffer.from('docx-binary-content').toString('base64');
mockedGetFileStream.mockResolvedValue({
file,
content: mockContent,
metadata: file,
});

const result = await encodeAndFormatDocuments(
req,
[file],
{ provider: Providers.OPENAI, model: 'deepseek-v4-pro' },
mockStrategyFunctions,
);

expect(result.documents).toHaveLength(0);
expect(result.files).toHaveLength(0);
});

it('should skip non-Bedrock-document types for Bedrock provider', async () => {
const req = createMockRequest() as ServerRequest;
const file = createMockDocFile(1, 'application/zip', 'archive.zip');
Expand Down
27 changes: 27 additions & 0 deletions packages/api/src/files/encode/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ const ANTHROPIC_CITATION_TYPES = new Set([
'text/html',
'text/markdown',
]);
const DEEPSEEK_TARGET_PATTERN = /^deepseek(?:[-_.]|$)/i;

function targetsDeepSeek(...values: Array<string | undefined>): boolean {
for (const value of values) {
if (!value) {
continue;
}

const normalized = value.replace(/^~/, '');
const segments = normalized.split(/[/:]/);
if (segments.some((segment) => DEEPSEEK_TARGET_PATTERN.test(segment))) {
return true;
}
}

return false;
}

/**
* Formats a base64-encoded document into the appropriate provider-specific block.
Expand All @@ -33,6 +50,8 @@ function formatDocumentBlock(
content: string,
filename: string | undefined,
useResponsesApi: boolean | undefined,
endpoint: string | undefined,
model: string | undefined,
): DocumentBlock | null {
if (provider === Providers.ANTHROPIC) {
const document: AnthropicDocumentBlock = {
Expand Down Expand Up @@ -63,6 +82,10 @@ function formatDocumentBlock(
};
}

if (provider === Providers.DEEPSEEK || targetsDeepSeek(endpoint, model)) {
return null;
}

const resolvedFilename = filename ?? 'document';

if (useResponsesApi) {
Expand Down Expand Up @@ -214,6 +237,8 @@ export async function encodeAndFormatDocuments(
content,
file.filename,
useResponsesApi,
endpoint,
model,
);
if (block) {
result.documents.push(block);
Expand All @@ -233,6 +258,8 @@ export async function encodeAndFormatDocuments(
content,
file.filename,
useResponsesApi,
endpoint,
model,
);
if (block) {
result.documents.push(block);
Expand Down
Loading