forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: chat deployment implementation (#39)
* Rename auth method in docs * fix(core): Fix trim messages mutation bug (langchain-ai#7547) * release(core): 0.3.31 (langchain-ai#7548) * fix(community): Updated Embeddings URL (langchain-ai#7545) * fix(community): make sure guardrailConfig can be added even with anthropic models (langchain-ai#7542) * docs: Fix PGVectorStore import in install dependencies (TypeScript) example (langchain-ai#7533) * fix(community): Airtable url (langchain-ai#7532) * docs: Fix typo in OpenAIModerationChain example (langchain-ai#7528) * docs: Resolves langchain-ai#7483, resolves langchain-ai#7274 (langchain-ai#7505) Co-authored-by: jacoblee93 <jacoblee93@gmail.com> * docs: Rename auth method in IBM docs (langchain-ai#7524) * docs: correct misspelling (langchain-ai#7522) Co-authored-by: jacoblee93 <jacoblee93@gmail.com> * release(community): 0.3.25 (langchain-ai#7549) * feat(azure-cosmosdb): add session context for a user mongodb (langchain-ai#7436) Co-authored-by: jacoblee93 <jacoblee93@gmail.com> * release(azure-cosmosdb): 0.2.7 (langchain-ai#7550) * fix(ci): Fix build (langchain-ai#7551) * feat(anthropic): Add Anthropic PDF support (document type) in invoke (langchain-ai#7496) Co-authored-by: jacoblee93 <jacoblee93@gmail.com> * release(anthropic): 0.3.12 (langchain-ai#7552) * chore(core,langchain,community): Relax langsmith deps (langchain-ai#7556) * release(community): 0.3.26 (langchain-ai#7557) * release(core): 0.3.32 (langchain-ai#7558) * Release 0.3.12 (langchain-ai#7559) * Add deployment chat to chat class * Upadate Watsonx sdk * Rework interfaces in llms as well * Bump watsonx-ai sdk version * Remove unused code * Add fake auth --------- Co-authored-by: Jacob Lee <jacoblee93@gmail.com> Co-authored-by: Jacky Chen <jackychen4@gmail.com> Co-authored-by: Mohamed Belhadj <medbelh@gmail.com> Co-authored-by: Brian Ploetz <bploetz@gmail.com> Co-authored-by: Eduard-Constantin Ibinceanu <ibinceanu.eduard@yahoo.com> Co-authored-by: Jonathan V <jonathanvelkeneers@hotmail.com> Co-authored-by: ucev <zhangshuaiyf@icloud.com> Co-authored-by: crisjy <cjy1994116@163.com> Co-authored-by: Adham Badr <adhambadr2@gmail.com>
- Loading branch information
1 parent
464e56b
commit 82a239e
Showing
33 changed files
with
657 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ChatAnthropic } from "@langchain/anthropic"; | ||
|
||
import * as fs from "fs"; | ||
|
||
export const run = async () => { | ||
const llm = new ChatAnthropic({ | ||
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 | ||
}); | ||
|
||
// 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); | ||
const arrayBuffer = await response.arrayBuffer(); | ||
const base64File = Buffer.from(arrayBuffer).toString("base64"); | ||
return base64File; | ||
}; | ||
|
||
const base64 = await getRemoteFile( | ||
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" | ||
); | ||
|
||
const prompt = "Summarise the contents of this PDF"; | ||
|
||
const response = await llm.invoke([ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: prompt, | ||
}, | ||
{ | ||
type: "document", | ||
source: { | ||
media_type: "application/pdf", | ||
type: "base64", | ||
data: base64, | ||
}, | ||
}, | ||
], | ||
}, | ||
]); | ||
console.log(response.content); | ||
return response.content; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.