Skip to content

Commit

Permalink
fix: Add test for pdf uploads anthropic (langchain-ai#7613)
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Jan 28, 2025
1 parent bdab4a3 commit 29486ed
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions libs/langchain-anthropic/src/tests/chat_models.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { expect, test } from "@jest/globals";
import * as fs from "fs/promises";
import {
AIMessageChunk,
HumanMessage,
Expand Down Expand Up @@ -834,3 +835,36 @@ test("human message caching", async () => {
0
);
});

test("Can accept PDF documents", async () => {
const model = new ChatAnthropic({
model: "claude-3-5-sonnet-latest",
});

const pdfPath =
"../langchain-community/src/document_loaders/tests/example_data/Jacob_Lee_Resume_2023.pdf";
const pdfBase64 = await fs.readFile(pdfPath, "base64");

const response = await model.invoke([
["system", "Use the provided documents to answer the question"],
[
"user",
[
{
type: "document",
source: {
type: "base64",
media_type: "application/pdf",
data: pdfBase64,
},
},
{
type: "text",
text: "Summarize the contents of this PDF",
},
],
],
]);

expect(response.content.length).toBeGreaterThan(10);
});

0 comments on commit 29486ed

Please sign in to comment.