(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
相关推荐
云水初3 天前
【项目篇】基于LanGraph的自动处理客服邮件的 Agent汇总
开发语言·笔记·python·学习·fastapi·langgraph
坊钰6 天前
【LangGraph框架入门级】12. 人机交互:interrupt 中断与 Command 恢复
开发语言·数据库·python·人机交互·ai编程·langgraph
范中勤7 天前
LangGraph Checkpointer 封装(下):with 的双层上下文与 MemorySaver 为什么不用 with
python·大模型·llm·agent·langgraph
for_ever_love__8 天前
LangGraph State 设计:多节点之间怎么安全地共享数据
redis·mysql·状态模式·checkpoint·state·状态图·langgraph
for_ever_love__8 天前
LangGraph Checkpointer:持久化、断点续跑与多轮记忆
服务器·数据库·学习·持久化·langgraph·checkpointer·断点续跑
for_ever_love__8 天前
LangChain 多工具协作:一个 Agent 不够用时怎么办
人工智能·langchain·langgraph·协作·多agent·多工具·工具编排
寻道码路8 天前
AI Agent 工程化开发实战(一):Agent 开发的四个层次——积木、运行时、薄壳、套件
人工智能·langchain·大模型·ai agent·langgraph·ai工程化·deep agents
旖旎夜光8 天前
【LangGraph实战】LangGraph 学习笔记(五):信息裁剪、人机交互与时间旅行
笔记·python·学习·ai·人机交互·langgraph
范中勤8 天前
LangChain / LangGraph Memory 记忆体系技术文档(作用域判定 · 官方现版本实现 · 工程坑点)
langchain·大模型·agent·langgraph·记忆体系
坊钰9 天前
【LangGraph框架入门级】4. 支持联网搜索的智能代理系统
python·ai编程·langgraph