Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
📄 feat: Context Field for Anthropic Documents (PDF) (#10148)
Danny Avilaf59daaeecc62
diff --git a/packages/api/src/files/encode/document.ts b/packages/api/src/files/encode/document.tsindex bc1396958c..338a4ddea6 100644--- a/packages/api/src/files/encode/document.ts+++ b/packages/api/src/files/encode/document.ts@@ -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',diff --git a/packages/api/src/types/files.ts b/packages/api/src/types/files.tsindex dc37410050..5b25f0b3e9 100644--- a/packages/api/src/types/files.ts+++ b/packages/api/src/types/files.ts@@ -46,29 +46,51 @@ export interface VideoResult {}>;}+/** Anthropic document block format */+export interface AnthropicDocumentBlock {+ type: 'document';+ source: {+ type: string;+ media_type: string;+ data: string;+ };+ context?: string;+ title?: string;+ cache_control?: { type: string };+ citations?: { enabled: boolean };+}++/** Google document block format */+export interface GoogleDocumentBlock {+ type: 'document';+ mimeType: string;+ data: string;+}++/** OpenAI file block format */+export interface OpenAIFileBlock {+ type: 'file';+ file: {+ filename: string;+ file_data: string;+ };+}++/** OpenAI Responses API file format */+export interface OpenAIInputFileBlock {+ type: 'input_file';+ filename: string;+ file_data: string;+}++export type DocumentBlock =+ | AnthropicDocumentBlock+ | GoogleDocumentBlock+ | OpenAIFileBlock+ | OpenAIInputFileBlock;+export interface DocumentResult {- documents: Array<{- type: 'document' | 'file' | 'input_file';- /** Anthropic File Format, `document` */- source?: {- type: string;- media_type: string;- data: string;- };- cache_control?: { type: string };- citations?: { enabled: boolean };- /** Google File Format, `document` */- mimeType?: string;- data?: string;- /** OpenAI File Format, `file` */- file?: {- filename?: string;- file_data?: string;- };- /** OpenAI Responses API File Format, `input_file` */- filename?: string;- file_data?: string;- }>;+ documents: DocumentBlock[];files: Array<{file_id?: string;temp_file_id?: string;