Skip to content

Commit

Permalink
Making an example for it
Browse files Browse the repository at this point in the history
  • Loading branch information
adhambadr committed Jan 10, 2025
1 parent f1db62a commit f9bcb57
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions examples/src/prompts/pdf_document.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { HumanMessage } from "@langchain/core/message";
import { base } from "@faker-js/faker";
import { ChatAnthropic } from "@langchain/anthropic";

export const run = async () => {
const llm = new ChatAnthropic({
model: "claude-3-5-sonnet-20240620", // Only claude-3-5-sonnet-20240620 or later supports documents
model: "claude-3-5-sonnet-20240620", // Only claude-3-5-sonnet-20240620 , claude-3-5-sonnet-20241022 as of Jan 2025 support PDF documents as in base64
});

const prompt = "Summarise the contents of this PDF";

// PDF needs to be in Base64.
const getLocalFile = async (path: string) => {
const localFile = await fs.readFileSync(path);
const base64File = localFile.toString("base64");
return base64File;
};

// Or remotely
const getRemoteFile = async (url: string) => {
const response = await fetch(url);
Expand All @@ -26,8 +25,11 @@ export const run = async () => {
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
);

const response = await llm.invoke(
new HumanMessage({
const prompt = "Summarise the contents of this PDF";

const response = await llm.invoke([
{
role: "user",
content: [
{
type: "text",
Expand All @@ -38,8 +40,8 @@ export const run = async () => {
source: base64,
},
],
})
);
},
]);
console.log(response.content);
//console.log(response.content);
return response.content;
Expand Down

0 comments on commit f9bcb57

Please sign in to comment.