Skip to content

Conversation

@danny-avila
Copy link
Owner

Summary

I added support for including filenames as context in Anthropic document blocks and refactored the document type definitions for better type safety and maintainability.

  • Added optional context field to Anthropic document blocks to include the filename when available
  • Removed the cache_control field from the default Anthropic document structure, allowing it to be set optionally
  • Created dedicated TypeScript interfaces for each provider's document format: AnthropicDocumentBlock, GoogleDocumentBlock, OpenAIFileBlock, and OpenAIInputFileBlock
  • Introduced a union type DocumentBlock to represent all possible document formats
  • Refactored the DocumentResult interface to use the new strongly typed DocumentBlock[] instead of an inline type definition
  • Improved code maintainability by separating provider-specific document formats into distinct, well-documented interfaces

Change Type

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Testing

I tested the changes by uploading PDF documents through the Anthropic provider and verifying that the filename appears correctly in the document context field. I also confirmed that existing functionality for other providers (Google, OpenAI) remains unaffected.

Test Configuration:

  • Provider: Anthropic Claude
  • File type: PDF documents
  • Verified context field population with filename
  • Verified backward compatibility with existing document handling

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • Local unit tests pass with my changes
  • Any changes dependent on mine have been merged and published in downstream modules

…thropic 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.
@danny-avila danny-avila merged commit f59daae into dev Oct 16, 2025
1 check passed
@danny-avila danny-avila deleted the fix/anthropic-documents branch October 16, 2025 20:24
Francistab705 pushed a commit to Francistab705/LibreChat that referenced this pull request Oct 27, 2025
* 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.
JustinBeaudry pushed a commit to Actual-Reality/LibreChat that referenced this pull request Nov 12, 2025
* 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.
Guiraud pushed a commit to Guiraud/LibreChat that referenced this pull request Nov 21, 2025
* 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.
patricksn3ll pushed a commit to patricksn3ll/LibreChat that referenced this pull request Dec 11, 2025
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants