mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 18:00:15 +01:00
📄 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:
parent
bc77bbd1ba
commit
f59daaeecc
2 changed files with 53 additions and 26 deletions
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue