langchain-js
БесплатноБез исполняемых скриптовНе проверенBuilds LLM-powered applications with LangChain.js for chat, agents, and RAG. Use when creating AI applications with chains, memory, tools, and…
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
LangChain.js
Framework for building LLM-powered applications. Provides abstractions for chat models, chains, agents, RAG, and memory with support for multiple providers.
Quick Start
npm install langchain @langchain/openai @langchain/core
Basic Chat
import { ChatOpenAI } from '@langchain/openai';
const model = new ChatOpenAI({
modelName: 'gpt-4o',
temperature: 0.7,
});
const response = await model.invoke('What is the capital of France?');
console.log(response.content);
Chat Models
OpenAI
import { ChatOpenAI } from '@langchain/openai';
const model = new ChatOpenAI({
modelName: 'gpt-4o',
temperature: 0,
maxTokens: 1000,
});
const response = await model.invoke([
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' },
]);
Anthropic
npm install @langchain/anthropic
import { ChatAnthropic } from '@langchain/anthropic';
const model = new ChatAnthropic({
modelName: 'claude-sonnet-4-20250514',
temperature: 0,
});
const response = await model.invoke('Explain quantum computing');
Google (Gemini)
npm install @langchain/google-genai
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
const model = new ChatGoogleGenerativeAI({
modelName: 'gemini-pro',
temperature: 0,
});
Streaming
import { ChatOpenAI } from '@langchain/openai';
const model = new ChatOpenAI({
modelName: 'gpt-4o',
streaming: true,
});
const stream = await model.stream('Tell me a story');
for await (const chunk of stream) {
process.stdout.write(chunk.content as string);
}
Prompt Templates
import { ChatPromptTemplate } from '@langchain/core/prompts';
const prompt = ChatPromptTemplate.fromMessages([
['system', 'You are a {role} assistant.'],
['user', '{input}'],
]);
const formattedPrompt = await prompt.format({
role: 'helpful',
input: 'What is TypeScript?',
});
With Model Chain
import { ChatOpenAI } from '@langchain/openai';
import { ChatPromptTemplate } from '@langchain/core/prompts';
const model = new ChatOpenAI();
const prompt = ChatPromptTemplate.fromMessages([
['system', 'Translate the following to {language}'],
['user', '{text}'],
]);
const chain = prompt.pipe(model);
const response = await chain.invoke({
language: 'French',
text: 'Hello, how are you?',
});
Output Parsers
import { ChatOpenAI } from '@langchain/openai';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import { StringOutputParser, JsonOutputParser } from '@langchain/core/output_parsers';
// String output
const stringChain = prompt.pipe(model).pipe(new StringOutputParser());
const text = await stringChain.invoke({ input: 'Hello' });
// JSON output
const jsonChain = prompt.pipe(model).pipe(new JsonOutputParser());
const data = await jsonChain.invoke({ input: 'List 3 colors as JSON' });
Structured Output
import { z } from 'zod';
import { ChatOpenAI } from '@langchain/openai';
const model = new ChatOpenAI({ modelName: 'gpt-4o' });
const schema = z.object({
name: z.string().describe('The person name'),
age: z.number().describe('The person age'),
occupation: z.string().describe('The person occupation'),
});
const structuredModel = model.withStructuredOutput(schema);
const result = await structuredModel.invoke(
'Extract info: John is 30 years old and works as a developer.'
);
// { name: 'John', age: 30, occupation: 'developer' }
Memory (Conversation History)
import { ChatOpenAI } from '@langchain/openai';
import { ChatPromptTemplate, MessagesPlaceholder } from '@langchain/core/prompts';
import { RunnableWithMessageHistory } from '@langchain/core/runnables';
import { ChatMessageHistory } from 'langchain/memory';
const model = new ChatOpenAI();
const prompt = ChatPromptTemplate.fromMessages([
['system', 'You are a helpful assistant.'],
new MessagesPlaceholder('history'),
['user', '{input}'],
]);
const chain = prompt.pipe(model);
// In-memory store
const messageHistories: Record<string, ChatMessageHistory> = {};
const chainWithHistory = new RunnableWithMessageHistory({
runnable: chain,
getMessageHistory: async (sessionId) => {
if (!messageHistories[sessionId]) {
messageHistories[sessionId] = new ChatMessageHistory();
}
return messageHistories[sessionId];
},
inputMessagesKey: 'input',
historyMessagesKey: 'history',
});
// Use with session
const response = await chainWithHistory.invoke(
{ input: 'My name is Alice' },
{ configurable: { sessionId: 'user-123' } }
);
const response2 = await chainWithHistory.invoke(
{ input: 'What is my name?' },
{ configurable: { sessionId: 'user-123' } }
);
// Response includes "Alice"
RAG (Retrieval-Augmented Generation)
npm install @langchain/openai langchain
Document Loading
``
Установить langchain-js в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл langchain-js?
Builds LLM-powered applications with LangChain.js for chat, agents, and RAG. Use when creating AI applications with chains, memory, tools, and retrieval-augmented generation in JavaScript.
Как установить скилл langchain-js?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл langchain-js запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic