git clone https://github.com/your-username/name-of-forked-repo.git# For instance, for LangChain:git clone https://github.com/parrot123/langchain.git
# Inside your repo, initialize environment and install dependenciesuv venv && source .venv/bin/activateuv sync --all-groups# or, to install a specific group only:uv sync --group test
位置:tests/integration_tests/集成测试覆盖需要调用外部 API 的逻辑,通常是与其他服务的集成。集成测试需要访问外部服务或提供商 API,这可能产生费用,因此默认不会运行。并非每次代码变更都需要集成测试,但请记住,评审过程中可能会单独要求或运行集成测试。要求:
使用外部服务测试真实集成
使用环境变量存储 API key
在凭据不可用时优雅跳过
运行集成测试:
make integration_tests# Or directly:uv run --group test --group test_integration pytest --retries 3 --retry-delay 1 tests/integration_tests# To run a specific test:TEST_FILE=tests/integration_tests/test_openai.py make integration_tests
def process_documents( docs: list[Document], processor: DocumentProcessor, *, batch_size: int = 100) -> ProcessingResult: """Process documents in batches. Args: docs: List of documents to process. processor: Document processing instance. batch_size: Number of documents per batch. Returns: Processing results with success/failure counts. """
class ChatAnthropic(BaseChatModel): """Interface to Claude chat models. See the [usage guide](https://docs.langchain.com/oss/python/integrations/chat/anthropic) for tutorials, feature walkthroughs, and examples. Args: model: Model identifier (e.g., `'claude-sonnet-4-6'`). temperature: Sampling temperature between `0` and `1`. max_tokens: Maximum number of tokens to generate. api_key: Anthropic API key. If not provided, reads from the `ANTHROPIC_API_KEY` environment variable. timeout: Request timeout in seconds. max_retries: Maximum number of retries for failed requests. Returns: A chat model instance that can be invoked with messages. Raises: ValueError: If the model identifier is not recognized. AuthenticationError: If the API key is invalid. Example: ```python from langchain_anthropic import ChatAnthropic model = ChatAnthropic(model="claude-sonnet-4-6") response = model.invoke("Hello!") ``` """
不应放入 docstring 的内容
避免重复应放在文档中的内容:
参数类型:这些已经在函数签名中,并会自动生成到 API reference。
功能教程:不要包含较长 walkthrough。请改为链接到本站:
"""...See the [extended thinking guide](https://docs.langchain.com/oss/integrations/chat/anthropic#extended-thinking)for configuration options."""
多个示例变体:包含一个最小示例,然后链接到完整指南:
"""Example: \`\`\`python message = HumanMessage(content=[ {"type": "image", "url": "https://example.com/image.jpg"} ]) \`\`\`See the [multimodal guide](https://docs.langchain.com/oss/integrations/chat/anthropic#multimodal)for all supported input formats."""
概念说明:保留事实性的参数描述。链接到文档以提供更深入上下文。
MkDocs 专用语法:避免在 docstring 中使用 ???+、accordion 或 tabs。它们不会在 IDE 中渲染。