0Pricing
LangChain / RAG / Vector DBs · 课时

设置您的 LangChain 环境

配置开发环境并安装必要的库,开始使用 LangChain 构建应用并与 LLM 集成

设置您的 LangChain 环境 是 CoddyKit 上的免费 LangChain / RAG / Vector DBs 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 LangChain / RAG / Vector DBs 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 LangChain / RAG / Vector DBs 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Welcome to LangChain Setup

Welcome to the exciting world of LangChain! This powerful framework helps you build applications powered by large language models (LLMs).

In this lesson, we'll get your development environment ready. Think of it as preparing your workbench before starting a new project.

Why Virtual Environments?

Before installing anything, it's a best practice to use a virtual environment. This keeps your project's dependencies separate from other Python projects on your computer.

  • Avoids conflicts between different project versions.
  • Makes your project easily shareable and reproducible.
  • Keeps your global Python installation clean.

Create a Virtual Environment

You can create a virtual environment using Python's built-in venv module. Choose a descriptive name, like langchain_env.

Run this command in your terminal:

python -m venv langchain_env

Activate Your Environment

After creating it, you need to activate your virtual environment. This tells your system to use the Python and packages from this specific environment.

The command depends on your operating system:

  • macOS/Linux: source langchain_env/bin/activate
  • Windows: .\langchain_env\Scripts\activate

Install LangChain Core

Now that your environment is active, let's install the core LangChain library. This package provides the fundamental building blocks for working with LLMs.

Use pip, the Python package installer, to get LangChain:

pip install langchain

Install an LLM Provider

LangChain acts as an interface to various LLM providers (like OpenAI, Google, Anthropic). You'll need to install the specific library for the provider you want to use.

For this course, we'll often use OpenAI as an example. Install its Python client:

pip install openai

Handle API Keys Securely

To interact with LLM providers, you'll need an API key. Never hardcode API keys directly in your code!

The safest way is to set them as environment variables. For OpenAI, you'd typically set OPENAI_API_KEY:

  • macOS/Linux: export OPENAI_API_KEY="your_key_here"
  • Windows (PowerShell): $env:OPENAI_API_KEY="your_key_here"

Replace your_key_here with your actual key.

Verify Your Setup

Let's run a quick Python script to ensure LangChain is installed and importable. This doesn't call an LLM yet, just checks the setup.

Try running this example:

from langchain_core.prompts import ChatPromptTemplate

print("LangChain Core imported successfully!")
print("Your environment is ready!")

What's Next in LangChain?

Great job! Your LangChain environment is now set up. You've installed the necessary libraries and verified the core components.

In the next lesson, we'll dive deeper into how to actually use LangChain to interact with LLMs, focusing on prompts and basic chains.

Environment Setup Quiz

Which of the following are good practices when setting up a new LangChain project environment?

Recap: Your LangChain Start

You've successfully set up your first LangChain development environment!

  • We learned the importance of virtual environments.
  • You created and activated a dedicated environment.
  • You installed the LangChain library and an LLM provider.
  • You understood how to handle API keys securely.
  • You verified your setup with a simple Python script.

You're now ready to start building amazing LLM applications!

常见问题解答

「设置您的 LangChain 环境」课时是免费的吗?

是的 — 「设置您的 LangChain 环境」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 LangChain / RAG / Vector DBs 课程的其余内容,请升级到 CoddyKit PRO。 LangChain / RAG / Vector DBs 课程共包含 4 节课。

「设置您的 LangChain 环境」这节课中我会学到什么?

配置开发环境并安装必要的库,开始使用 LangChain 构建应用并与 LLM 集成 你通过在浏览器中直接运行的动手代码来练习 LangChain / RAG / Vector DBs,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 LangChain / RAG / Vector DBs 需要有经验吗?

无需任何先前经验。CoddyKit 上的 LangChain / RAG / Vector DBs 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「设置您的 LangChain 环境」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 LangChain / RAG / Vector DBs 课中编写并运行代码吗?

能。每节 LangChain / RAG / Vector DBs 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 设置您的 LangChain 环境
  2. 提示、LLM 与基础链
  3. 输出解析器与回调
  4. LangChain 中的记忆与对话上下文
← 返回 LangChain / RAG / Vector DBs