Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

langchain-python

БесплатноБез исполняемых скриптовНе проверен

Instructions for using LangChain with Python Triggers on: **/*.py

diegosouzapwот diegosouzapw★ 68 звёзд на GitHub

Об этом скилле

LangChain Python Instructions

These instructions guide GitHub Copilot in generating code and documentation for LangChain applications in Python. Focus on LangChain-specific patterns, APIs, and best practices.

Runnable Interface (LangChain-specific)

LangChain's Runnable interface is the foundation for composing and executing chains, chat models, output parsers, retrievers, and LangGraph graphs. It provides a unified API for invoking, batching, streaming, inspecting, and composing components.

Key LangChain-specific features:

  • All major LangChain components (chat models, output parsers, retrievers, graphs) implement the Runnable interface.
  • Supports synchronous (invoke, batch, stream) and asynchronous (ainvoke, abatch, astream) execution.
  • Batching (batch, batch_as_completed) is optimized for parallel API calls; set max_concurrency in RunnableConfig to control parallelism.
  • Streaming APIs (stream, astream, astream_events) yield outputs as they are produced, critical for responsive LLM apps.
  • Input/output types are component-specific (e.g., chat models accept messages, retrievers accept strings, output parsers accept model outputs).
  • Inspect schemas with get_input_schema, get_output_schema, and their JSONSchema variants for validation and OpenAPI generation.
  • Use with_types to override inferred input/output types for complex LCEL chains.
  • Compose Runnables declaratively with LCEL: chain = prompt | chat_model | output_parser.
  • Propagate RunnableConfig (tags, metadata, callbacks, concurrency) automatically in Python 3.11+; manually in async code for Python 3.9/3.10.
  • Create custom runnables with RunnableLambda (simple transforms) or RunnableGenerator (streaming transforms); avoid subclassing directly.
  • Configure runtime attributes and alternatives with configurable_fields and configurable_alternatives for dynamic chains and LangServe deployments.

LangChain best practices:

  • Use batching for parallel API calls to LLMs or retrievers; set max_concurrency to avoid rate limits.

  • Prefer streaming APIs for chat UIs and long outputs.

  • Always validate input/output schemas for custom chains and deployed endpoints.

  • Use tags and metadata in RunnableConfig for tracing in LangSmith and debugging complex chains.

  • For custom logic, wrap functions with RunnableLambda or RunnableGenerator instead of subclassing.

  • For advanced configuration, expose fields and alternatives via configurable_fields and configurable_alternatives.

  • Use LangChain's chat model integrations for conversational AI:

  • Import from langchain.chat_models or langchain_openai (e.g., ChatOpenAI).

  • Compose messages using SystemMessage, HumanMessage, AIMessage.

  • For tool calling, use bind_tools(tools) method.

  • For structured outputs, use with_structured_output(schema).

Example:

from langchain_openai import ChatOpenAI
from langchain.schema import HumanMessage, SystemMessage

chat = ChatOpenAI(model="gpt-4", temperature=0)
messages = [
    SystemMessage(content="You are a helpful assistant."),
    HumanMessage(content="What is LangChain?")
]
response = chat.invoke(messages)
print(response.content)
  • Compose messages as a list of SystemMessage, HumanMessage, and optionally AIMessage objects.
  • For RAG, combine chat models with retrievers/vectorstores for context injection.
  • Use streaming=True for real-time token streaming (if supported).
  • Use tools argument for function/tool calling (OpenAI, Anthropic, etc.).
  • Use response_format="json" for structured outputs (OpenAI models).

Best practices:

  • Always validate model outputs before using them in downstream tasks.

  • Prefer explicit message types for clarity and reliability.

  • For Copilot, provide clear, actionable prompts and document expected outputs.

  • LLM client factory: centralize provider configs (API keys), timeouts, retries, and telemetry. Provide a single place to switch providers or client settings.

  • Prompt templates: store templates under prompts/ and load via a safe helper. Keep templates small and testable.

  • Chains vs Agents: prefer Chains for deterministic pipelines (RAG, summarization). Use Agents when you require planning or dynamic tool selection.

  • Tools: implement typed adapter interfaces for tools; validate inputs and outputs strictly.

  • Memory: default to stateless design. When memory is needed, store minimal context and document retention/erasure policies.

  • Retrievers: build retrieval + rerank pipelines. Keep vectorstore schema stable (id, text, metadata).

Patterns

  • Callbacks & tracing: use LangChain callbacks and integrate with LangSmith or your tracing system to capture request/response lifecycle.
  • Separation of concerns: keep prompt construction, LLM wiring, and business logic separate to simplify testing and reduce accidental prompt changes.

Embeddings & vectorstores

  • Use consistent chunking and metadata fields (source, page, ch
Полный SKILL.md на GitHub

Установить langchain-python в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

metadata.json

FAQ

Что делает скилл langchain-python?

Instructions for using LangChain with Python Triggers on: **/*.py

Как установить скилл langchain-python?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл langchain-python запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить langchain-python с