📄 feat: Context Field for Anthropic Documents (PDF) (#10148)

* fix: Remove ephemeral cache control from document encoding function

* refactor: Improve document encoding types and add file context for anthropic messages api

- Added AnthropicDocumentBlock interface to define the structure for documents from the Anthropic provider.
- Updated encodeAndFormatDocuments function to utilize the new type and include optional context for filenames.
- Refactored DocumentResult to use a union type for various document formats, improving type safety and clarity.
This commit is contained in:
Danny Avila 2025-10-16 23:24:14 +03:00 committed by GitHub
parent bc77bbd1ba
commit f59daaeecc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 26 deletions

View file

@ -2,7 +2,7 @@ import { Providers } from '@librechat/agents';
import { isOpenAILikeProvider, isDocumentSupportedProvider } from 'librechat-data-provider';
import type { IMongoFile } from '@librechat/data-schemas';
import type { Request } from 'express';
import type { StrategyFunctions, DocumentResult } from '~/types/files';
import type { StrategyFunctions, DocumentResult, AnthropicDocumentBlock } from '~/types/files';
import { validatePdf } from '~/files/validation';
import { getFileStream } from './utils';
@ -69,16 +69,21 @@ export async function encodeAndFormatDocuments(
}
if (provider === Providers.ANTHROPIC) {
result.documents.push({
const document: AnthropicDocumentBlock = {
type: 'document',
source: {
type: 'base64',
media_type: 'application/pdf',
data: content,
},
cache_control: { type: 'ephemeral' },
citations: { enabled: true },
});
};
if (file.filename) {
document.context = `File: "${file.filename}"`;
}
result.documents.push(document);
} else if (useResponsesApi) {
result.documents.push({
type: 'input_file',