(LangGraph教程)6. Deployment部署——Lesson 1(2):创建部署(未索引)

https://academy.langchain.com/courses/intro-to-langgraph

https://github.com/shangxiang0907/langchain-academy

文章目录

  • [Creating a deployment 创建部署](#Creating a deployment 创建部署)
    • [Code structure 代码结构](#Code structure 代码结构)
    • [CLI 命令行界面(CLI)](#CLI 命令行界面(CLI))
      • [Build Docker Image for LangGraph Server 为 LangGraph 服务器构建 Docker 镜像](#Build Docker Image for LangGraph Server 为 LangGraph 服务器构建 Docker 镜像)
      • [Set Up Redis and PostgreSQL 设置 Redis 和 PostgreSQL](#Set Up Redis and PostgreSQL 设置 Redis 和 PostgreSQL)

Creating a deployment 创建部署

Let's create a deployment of the task_maistro app that we created in module 5.

让我们为我们在模块 5 中创建的 task_maistro 应用创建一个部署。

Code structure 代码结构

The following information should be provided to create a LangGraph Platform deployment:

以下信息应被提供,以创建 LangGraph 平台部署:

  • A LangGraph API Configuration file - langgraph.json

  • The graphs that implement the logic of the application - e.g., task_maistro.py

    • 实现应用逻辑的图(graph)------例如,task_maistro.py
  • A file that specifies dependencies required to run the application - requirements.txt

    • 指定运行应用所需依赖项的文件 --- requirements.txt
  • Supply environment variables needed for the application to run - .env or docker-compose.yml

    • 提供应用运行所需的环境变量 --- .env 或 docker-compose.yml

We have this already in the module-6/deployment directory!

这些文件我们已在 module-6/deployment 目录中准备就绪!

CLI 命令行界面(CLI)

The LangGraph CLI is a command-line interface for creating a LangGraph Platform deployment.

LangGraph CLI 是用于创建 LangGraph 平台部署的命令行接口。

python 复制代码
%%capture --no-stderr
%pip install -U langgraph-cli

To create a self-hosted deployment, we'll follow a few steps.

为创建 自托管部署,我们将按几个步骤操作。

Build Docker Image for LangGraph Server 为 LangGraph 服务器构建 Docker 镜像

We first use the langgraph CLI to create a Docker image for the LangGraph Server.

我们首先使用 langgraph CLI 为 LangGraph 服务器 创建一个 Docker 镜像。

This will package our graph and dependencies into a Docker image.

该操作会将我们的图及其依赖项打包进一个 Docker 镜像。

A Docker image is a template for a Docker container that contains the code and dependencies required to run the application.

Docker 镜像是 Docker 容器的模板,其中包含运行应用所需的代码和依赖项。

Ensure that Docker is installed and then run the following command to create the Docker image, my-image:

请确保已安装 Docker,然后运行以下命令创建名为 my-image 的 Docker 镜像:

复制代码
$ cd module-6/deployment
$ langgraph build -t my-image

Set Up Redis and PostgreSQL 设置 Redis 和 PostgreSQL

If you already have Redis and PostgreSQL running (e.g., locally or on other servers), then create and run the LangGraph Server container by itself with the URIs for Redis and PostgreSQL:

如果你已有正在运行的 Redis 和 PostgreSQL(例如,在本地或其他服务器上),则可 单独 创建并运行 LangGraph 服务器容器,并传入 Redis 和 PostgreSQL 的 URI。

复制代码
docker run \
    --env-file .env \
    -p 8123:8000 \
    -e REDIS_URI="foo" \
    -e DATABASE_URI="bar" \
    -e LANGSMITH_API_KEY="baz" \
    my-image

Alternatively, you can use the provided docker-compose.yml file to create three separate containers based on the services defined:

或者,你可以使用提供的 docker-compose.yml 文件,基于所定义的服务创建三个独立的容器:

  • langgraph-redis: Creates a new container using the official Redis image.

    • langgraph-redis:使用官方 Redis 镜像创建新容器。
  • langgraph-postgres: Creates a new container using the official Postgres image.

    • langgraph-postgres:使用官方 Postgres 镜像创建新容器。
  • langgraph-api: Creates a new container using your pre-built image.

    • langgraph-api:使用你预先构建的镜像创建新容器。

Simply copy the docker-compose-example.yml and add the following environment variables to run the deployed task_maistro app:

只需复制 docker-compose-example.yml,并添加以下环境变量,即可运行已部署的 task_maistro 应用:

  • IMAGE_NAME (e.g., my-image)

  • LANGSMITH_API_KEY

  • OPENAI_API_KEY

Then, launch the deployment!

然后,启动部署!

复制代码
$ cd module-6/deployment
$ docker compose up
相关推荐
Maiko Star10 天前
【HM-LG】Think In LangGraph
langgraph
谙弆悕博士12 天前
多智能体架构详解:层级树状架构(分级主从型)
运维·架构·大模型·agent·多智能体·langgraph·层级树状
Maiko Star12 天前
*【HM-LG】LangGraph基本概念和入门
langgraph
谙弆悕博士13 天前
多智能体架构详解:网状去中心化架构(Mesh对等P2P)
人工智能·架构·去中心化·p2p·多智能体·智能体·langgraph
学无止境小袁同学14 天前
LangGraph 深度指南
语言模型·框架·agent·并发·上下文·langgraph·长期记忆
典学长编程14 天前
LangGraph 快速入门:从 StateGraph 到 ReAct Agent
python·有向图·无向图·langgraph·react agent·stategraph
大可不必了15 天前
06 langgraph运行三要素State Node Edge
langgraph
M--Y16 天前
LangGraph 架构基石:持久化与运行控制
python·langchain·大模型·llm·持久化·langgraph
M--Y17 天前
LangGraph 工作流模式
开发语言·javascript·python·langchain·大模型·llm·langgraph
承渊政道22 天前
LangChainAI应用开发框架【LangChain与LangGraph介绍】
langchain·大模型·langgraph·ai应用开发