Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix deployment chat interface #44

Merged
merged 23 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7b67d43
fix(docs): imports and call (#7636)
crishoj Feb 1, 2025
a003594
docs: chat model order experiment
efriis Feb 3, 2025
966821a
docs: chat model order experiment (#7641)
efriis Feb 3, 2025
d9713ca
adding interrupt banner
tanushree-sharma Feb 3, 2025
146b4dc
linting
tanushree-sharma Feb 3, 2025
3decf32
banner-size-fix
tanushree-sharma Feb 4, 2025
bb85d11
linting
tanushree-sharma Feb 4, 2025
39bf7ac
padding-fix
tanushree-sharma Feb 4, 2025
4587906
adding interrupt banner (#7642)
tanushree-sharma Feb 4, 2025
e917f3f
Remove optional checker
FilipZmijewski Feb 4, 2025
116982f
feat(anthropic): Adds Anthropic citations support (#7651)
jacoblee93 Feb 5, 2025
1f11644
release(anthropic): 0.3.13 (#7652)
jacoblee93 Feb 5, 2025
1efb550
fix(core): Fix coercion of serialized tool and function messages (#7653)
jacoblee93 Feb 5, 2025
c9eee79
release(core): 0.3.38 (#7654)
jacoblee93 Feb 5, 2025
573ac55
weaviate[minor]: Add Document className as metadata (#7486)
rolando-cruz Feb 5, 2025
2ff134e
release(weaviate): 0.1.1 (#7655)
jacoblee93 Feb 5, 2025
99829ef
feat[community]: Add chat deployment to IBM chat class (#7633)
FilipZmijewski Feb 5, 2025
ded94d5
fix(community): Relax Replicate peer dep (#7656)
jacoblee93 Feb 5, 2025
0eedecf
feat(community): Add OpenAI Whisper options (#7650)
fneiraj Feb 6, 2025
7459710
release(community): 0.3.29 (#7659)
jacoblee93 Feb 6, 2025
ebbb5f9
Merge branch 'main' of https://github.com/langchain-ai/langchainjs in…
FilipZmijewski Feb 7, 2025
5969f1e
Fix interface
FilipZmijewski Feb 7, 2025
fc9984d
Fix packages
FilipZmijewski Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/core_docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
219 changes: 206 additions & 13 deletions docs/core_docs/docs/integrations/chat/anthropic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"id": "bba739ed",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -783,7 +783,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "6e47de9b",
"metadata": {},
"outputs": [
Expand All @@ -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",
Expand All @@ -820,7 +819,8 @@
"${CACHED_TEXT}`;\n",
"\n",
"const messages = [\n",
" new SystemMessage({\n",
" {\n",
" role: \"system\",\n",
" content: [\n",
" {\n",
" type: \"text\",\n",
Expand All @@ -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",
Expand All @@ -852,7 +853,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"id": "5d264f8b",
"metadata": {},
"outputs": [
Expand All @@ -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"
]
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Up @@ -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";
Expand Down
5 changes: 5 additions & 0 deletions docs/core_docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions docs/core_docs/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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",
];

Expand Down
6 changes: 5 additions & 1 deletion examples/src/document_loaders/openai_whisper_audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
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": {
Expand Down
Loading
Loading