Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: langchain-ai/langchainjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0e48a753fb360347055fe2967e170251ea3e7f71
Choose a base ref
...
head repository: langchain-ai/langchainjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0eedecfa6f90705010624a1deda28a105bd4825a
Choose a head ref
  • 19 commits
  • 31 files changed
  • 8 contributors

Commits on Jan 30, 2025

  1. release(community): 0.3.28 (#7629)

    jacoblee93 authored Jan 30, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    05eedae View commit details

Commits on Feb 1, 2025

  1. fix(docs): imports and call (#7636)

    Co-authored-by: Jacob Lee <jacoblee93@gmail.com>
    crishoj and jacoblee93 authored Feb 1, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7b67d43 View commit details

Commits on Feb 3, 2025

  1. docs: chat model order experiment

    efriis committed Feb 3, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a003594 View commit details
  2. docs: chat model order experiment (#7641)

    efriis authored Feb 3, 2025
    Copy the full SHA
    966821a View commit details
  3. adding interrupt banner

    tanushree-sharma committed Feb 3, 2025
    Copy the full SHA
    d9713ca View commit details
  4. linting

    tanushree-sharma committed Feb 3, 2025
    Copy the full SHA
    146b4dc View commit details

Commits on Feb 4, 2025

  1. banner-size-fix

    tanushree-sharma committed Feb 4, 2025
    Copy the full SHA
    3decf32 View commit details
  2. linting

    tanushree-sharma committed Feb 4, 2025
    Copy the full SHA
    bb85d11 View commit details
  3. padding-fix

    tanushree-sharma committed Feb 4, 2025
    Copy the full SHA
    39bf7ac View commit details
  4. adding interrupt banner (#7642)

    tanushree-sharma authored Feb 4, 2025
    Copy the full SHA
    4587906 View commit details

Commits on Feb 5, 2025

  1. feat(anthropic): Adds Anthropic citations support (#7651)

    jacoblee93 authored Feb 5, 2025
    Copy the full SHA
    116982f View commit details
  2. release(anthropic): 0.3.13 (#7652)

    jacoblee93 authored Feb 5, 2025
    Copy the full SHA
    1f11644 View commit details
  3. fix(core): Fix coercion of serialized tool and function messages (#7653)

    jacoblee93 authored Feb 5, 2025
    Copy the full SHA
    1efb550 View commit details
  4. release(core): 0.3.38 (#7654)

    jacoblee93 authored Feb 5, 2025
    Copy the full SHA
    c9eee79 View commit details
  5. weaviate[minor]: Add Document className as metadata (#7486)

    rolando-cruz authored Feb 5, 2025
    Copy the full SHA
    573ac55 View commit details
  6. release(weaviate): 0.1.1 (#7655)

    jacoblee93 authored Feb 5, 2025
    Copy the full SHA
    2ff134e View commit details
  7. feat[community]: Add chat deployment to IBM chat class (#7633)

    FilipZmijewski authored Feb 5, 2025
    Copy the full SHA
    99829ef View commit details
  8. fix(community): Relax Replicate peer dep (#7656)

    jacoblee93 authored Feb 5, 2025
    Copy the full SHA
    ded94d5 View commit details

Commits on Feb 6, 2025

  1. feat(community): Add OpenAI Whisper options (#7650)

    Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
    fneiraj and jacoblee93 authored Feb 6, 2025
    Copy the full SHA
    0eedecf View commit details
Showing with 833 additions and 257 deletions.
  1. +2 βˆ’0 docs/core_docs/README.md
  2. +206 βˆ’13 docs/core_docs/docs/integrations/chat/anthropic.ipynb
  3. +1 βˆ’1 docs/core_docs/docs/integrations/llms/replicate.mdx
  4. +5 βˆ’0 docs/core_docs/docusaurus.config.js
  5. +8 βˆ’0 docs/core_docs/src/css/custom.css
  6. +1 βˆ’1 docs/core_docs/src/theme/ChatModelTabs.js
  7. +5 βˆ’1 examples/src/document_loaders/openai_whisper_audio.ts
  8. +1 βˆ’1 langchain-core/package.json
  9. +37 βˆ’0 langchain-core/src/messages/tests/base_message.test.ts
  10. +10 βˆ’0 langchain-core/src/messages/utils.ts
  11. +11 βˆ’5 libs/langchain-anthropic/README.md
  12. +2 βˆ’2 libs/langchain-anthropic/package.json
  13. +46 βˆ’30 libs/langchain-anthropic/src/chat_models.ts
  14. +61 βˆ’0 libs/langchain-anthropic/src/tests/chat_models.int.test.ts
  15. +2 βˆ’2 libs/langchain-anthropic/src/types.ts
  16. +4 βˆ’2 libs/langchain-anthropic/src/utils/message_inputs.ts
  17. +32 βˆ’23 libs/langchain-anthropic/src/utils/message_outputs.ts
  18. +4 βˆ’4 libs/langchain-community/package.json
  19. +126 βˆ’64 libs/langchain-community/src/chat_models/ibm.ts
  20. +33 βˆ’2 libs/langchain-community/src/chat_models/tests/ibm.int.test.ts
  21. +9 βˆ’0 libs/langchain-community/src/chat_models/tests/ibm.standard.int.test.ts
  22. +51 βˆ’6 libs/langchain-community/src/chat_models/tests/ibm.test.ts
  23. +5 βˆ’0 libs/langchain-community/src/document_loaders/fs/openai_whisper_audio.ts
  24. +75 βˆ’45 libs/langchain-community/src/llms/ibm.ts
  25. +32 βˆ’30 libs/langchain-community/src/llms/tests/ibm.int.test.ts
  26. +13 βˆ’2 libs/langchain-community/src/llms/tests/ibm.test.ts
  27. +19 βˆ’3 libs/langchain-community/src/types/ibm.ts
  28. +9 βˆ’1 libs/langchain-community/src/utils/ibm.ts
  29. +1 βˆ’1 libs/langchain-weaviate/package.json
  30. +4 βˆ’1 libs/langchain-weaviate/src/vectorstores.ts
  31. +18 βˆ’17 yarn.lock
2 changes: 2 additions & 0 deletions docs/core_docs/README.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ This website is built using [Docusaurus 2](https://docusaurus.io/), a modern sta

### Installation

First, make sure you have [dependencies installed](https://github.com/langchain-ai/langchainjs/blob/main/CONTRIBUTING.md#install-dependencies).

```
$ yarn
```
219 changes: 206 additions & 13 deletions docs/core_docs/docs/integrations/chat/anthropic.ipynb
Original file line number Diff line number Diff line change
@@ -509,7 +509,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"id": "bba739ed",
"metadata": {},
"outputs": [],
@@ -783,7 +783,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "6e47de9b",
"metadata": {},
"outputs": [
@@ -793,16 +793,15 @@
"text": [
"USAGE: {\n",
" input_tokens: 19,\n",
" cache_creation_input_tokens: 2925,\n",
" cache_creation_input_tokens: 2921,\n",
" cache_read_input_tokens: 0,\n",
" output_tokens: 327\n",
" output_tokens: 355\n",
"}\n"
]
}
],
"source": [
"import { ChatAnthropic } from \"@langchain/anthropic\";\n",
"import { HumanMessage, SystemMessage } from \"@langchain/core/messages\";\n",
"\n",
"const modelWithCaching = new ChatAnthropic({\n",
" model: \"claude-3-haiku-20240307\",\n",
@@ -820,7 +819,8 @@
"${CACHED_TEXT}`;\n",
"\n",
"const messages = [\n",
" new SystemMessage({\n",
" {\n",
" role: \"system\",\n",
" content: [\n",
" {\n",
" type: \"text\",\n",
@@ -829,10 +829,11 @@
" cache_control: { type: \"ephemeral\" },\n",
" },\n",
" ],\n",
" }),\n",
" new HumanMessage({\n",
" },\n",
" {\n",
" role: \"user\",\n",
" content: \"What types of messages are supported in LangChain?\",\n",
" }),\n",
" },\n",
"];\n",
"\n",
"const res = await modelWithCaching.invoke(messages);\n",
@@ -852,7 +853,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"id": "5d264f8b",
"metadata": {},
"outputs": [
@@ -863,8 +864,8 @@
"USAGE: {\n",
" input_tokens: 19,\n",
" cache_creation_input_tokens: 0,\n",
" cache_read_input_tokens: 2925,\n",
" output_tokens: 250\n",
" cache_read_input_tokens: 2921,\n",
" output_tokens: 357\n",
"}\n"
]
}
@@ -961,6 +962,198 @@
"await modelWithCustomClient.invoke([{ role: \"user\", content: \"Hello!\" }]);"
]
},
{
"cell_type": "markdown",
"id": "68a85a61",
"metadata": {},
"source": [
"## Citations\n",
"\n",
"Anthropic supports a [citations](https://docs.anthropic.com/en/docs/build-with-claude/citations) feature that lets Claude attach context to its answers based on source documents supplied by the user. When [document content blocks](https://docs.anthropic.com/en/docs/build-with-claude/citations#document-types) with `\"citations\": {\"enabled\": True}` are included in a query, Claude may generate citations in its response.\n",
"\n",
"### Simple example\n",
"\n",
"In this example we pass a [plain text document](https://docs.anthropic.com/en/docs/build-with-claude/citations#plain-text-documents). In the background, Claude [automatically chunks](https://docs.anthropic.com/en/docs/build-with-claude/citations#plain-text-documents) the input text into sentences, which are used when generating citations."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d3f1c754",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\n",
" {\n",
" \"type\": \"text\",\n",
" \"text\": \"Based on the document, I can tell you that:\\n\\n- \"\n",
" },\n",
" {\n",
" \"type\": \"text\",\n",
" \"text\": \"The grass is green\",\n",
" \"citations\": [\n",
" {\n",
" \"type\": \"char_location\",\n",
" \"cited_text\": \"The grass is green. \",\n",
" \"document_index\": 0,\n",
" \"document_title\": \"My Document\",\n",
" \"start_char_index\": 0,\n",
" \"end_char_index\": 20\n",
" }\n",
" ]\n",
" },\n",
" {\n",
" \"type\": \"text\",\n",
" \"text\": \"\\n- \"\n",
" },\n",
" {\n",
" \"type\": \"text\",\n",
" \"text\": \"The sky is blue\",\n",
" \"citations\": [\n",
" {\n",
" \"type\": \"char_location\",\n",
" \"cited_text\": \"The sky is blue.\",\n",
" \"document_index\": 0,\n",
" \"document_title\": \"My Document\",\n",
" \"start_char_index\": 20,\n",
" \"end_char_index\": 36\n",
" }\n",
" ]\n",
" }\n",
"]\n"
]
}
],
"source": [
"import { ChatAnthropic } from \"@langchain/anthropic\";\n",
"\n",
"const citationsModel = new ChatAnthropic({\n",
" model: \"claude-3-5-haiku-latest\",\n",
"});\n",
"\n",
"const messagesWithCitations = [\n",
" {\n",
" role: \"user\",\n",
" content: [\n",
" {\n",
" type: \"document\",\n",
" source: {\n",
" type: \"text\",\n",
" media_type: \"text/plain\",\n",
" data: \"The grass is green. The sky is blue.\",\n",
" },\n",
" title: \"My Document\",\n",
" context: \"This is a trustworthy document.\",\n",
" citations: {\n",
" enabled: true,\n",
" },\n",
" },\n",
" {\n",
" type: \"text\",\n",
" text: \"What color is the grass and sky?\",\n",
" },\n",
" ],\n",
" }\n",
"];\n",
"\n",
"const responseWithCitations = await citationsModel.invoke(messagesWithCitations);\n",
"\n",
"console.log(JSON.stringify(responseWithCitations.content, null, 2));"
]
},
{
"cell_type": "markdown",
"id": "14269f15",
"metadata": {},
"source": [
"### Using with text splitters\n",
"\n",
"Anthropic also lets you specify your own splits using [custom document](https://docs.anthropic.com/en/docs/build-with-claude/citations#custom-content-documents) types. LangChain [text splitters](/docs/concepts/text_splitters/) can be used to generate meaningful splits for this purpose. See the below example, where we split the LangChain.js README (a markdown document) and pass it to Claude as context:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e9f3213",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\n",
" {\n",
" \"type\": \"text\",\n",
" \"text\": \"Based on the documentation, I can provide you with a link to LangChain's tutorials:\\n\\n\"\n",
" },\n",
" {\n",
" \"type\": \"text\",\n",
" \"text\": \"The tutorials can be found at: https://js.langchain.com/docs/tutorials/\",\n",
" \"citations\": [\n",
" {\n",
" \"type\": \"content_block_location\",\n",
" \"cited_text\": \"[Tutorial](https://js.langchain.com/docs/tutorials/)walkthroughs\",\n",
" \"document_index\": 0,\n",
" \"document_title\": null,\n",
" \"start_block_index\": 191,\n",
" \"end_block_index\": 194\n",
" }\n",
" ]\n",
" }\n",
"]\n"
]
}
],
"source": [
"import { ChatAnthropic } from \"@langchain/anthropic\";\n",
"import { MarkdownTextSplitter } from \"langchain/text_splitter\";\n",
"\n",
"function formatToAnthropicDocuments(documents: string[]) {\n",
" return {\n",
" type: \"document\",\n",
" source: {\n",
" type: \"content\",\n",
" content: documents.map((document) => ({ type: \"text\", text: document })),\n",
" },\n",
" citations: { enabled: true },\n",
" };\n",
"}\n",
"\n",
"// Pull readme\n",
"const readmeResponse = await fetch(\n",
" \"https://raw.githubusercontent.com/langchain-ai/langchainjs/master/README.md\"\n",
");\n",
"\n",
"const readme = await readmeResponse.text();\n",
"\n",
"// Split into chunks\n",
"const splitter = new MarkdownTextSplitter({\n",
" chunkOverlap: 0,\n",
" chunkSize: 50,\n",
"});\n",
"const documents = await splitter.splitText(readme);\n",
"\n",
"// Construct message\n",
"const messageWithSplitDocuments = {\n",
" role: \"user\",\n",
" content: [\n",
" formatToAnthropicDocuments(documents),\n",
" { type: \"text\", text: \"Give me a link to LangChain's tutorials. Cite your sources\" },\n",
" ],\n",
"};\n",
"\n",
"// Query LLM\n",
"const citationsModelWithSplits = new ChatAnthropic({\n",
" model: \"claude-3-5-sonnet-latest\",\n",
"});\n",
"const resWithSplits = await citationsModelWithSplits.invoke([messageWithSplitDocuments]);\n",
"\n",
"console.log(JSON.stringify(resWithSplits.content, null, 2));"
]
},
{
"cell_type": "markdown",
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3",
@@ -992,4 +1185,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
2 changes: 1 addition & 1 deletion docs/core_docs/docs/integrations/llms/replicate.mdx
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import IntegrationInstallTooltip from "@mdx_components/integration_install_toolt
<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install replicate @langchain/community @langchain/core
npm install replicate@1 @langchain/community @langchain/core
```

import ReplicateLlama2 from "@examples/models/llm/replicate_llama2.ts";
5 changes: 5 additions & 0 deletions docs/core_docs/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -135,6 +135,11 @@ const config = {
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
announcementBar: {
content:
'<strong class="announcement-bar-text">Join us at <a href="https://interrupt.langchain.com/" target="_blank" rel="noopener noreferrer"> Interrupt: The Agent AI Conference by LangChain</a> on May 13 & 14 in San Francisco!</strong>',
backgroundColor: "#d0c9fe",
},
prism: {
theme: {
...baseLightCodeBlockTheme,
8 changes: 8 additions & 0 deletions docs/core_docs/src/css/custom.css
Original file line number Diff line number Diff line change
@@ -311,3 +311,11 @@ nav, h1, h2, h3, h4 {
[data-theme='dark'] .announcementBar_node_modules-\@docusaurus-theme-classic-lib-theme-AnnouncementBar-styles-module button {
color: #fff;
}

.announcement-bar-text {
font-size: 16px;
}

div[class^='announcementBar_'] {
padding: 20px 0;
}
2 changes: 1 addition & 1 deletion docs/core_docs/src/theme/ChatModelTabs.js
Original file line number Diff line number Diff line change
@@ -70,11 +70,11 @@ export default function ChatModelTabs(props) {
const groqParams = props.groqParams ?? DEFAULTS.groqParams;
const vertexParams = props.vertexParams ?? DEFAULTS.vertexParams;
const providers = props.providers ?? [
"groq",
"openai",
"anthropic",
"fireworks",
"mistral",
"groq",
"vertex",
];

6 changes: 5 additions & 1 deletion examples/src/document_loaders/openai_whisper_audio.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,11 @@ import { OpenAIWhisperAudio } from "@langchain/community/document_loaders/fs/ope

const filePath = "./src/document_loaders/example_data/test.mp3";

const loader = new OpenAIWhisperAudio(filePath);
const loader = new OpenAIWhisperAudio(filePath, {
transcriptionCreateParams: {
language: "en",
},
});

const docs = await loader.load();

2 changes: 1 addition & 1 deletion langchain-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langchain/core",
"version": "0.3.37",
"version": "0.3.38",
"description": "Core LangChain.js abstractions and schemas",
"type": "module",
"engines": {
Loading