跳转到内容
AggregaAggrega
选择语言: 简体中文
本页面由机器翻译。阅读英文原文。

导入 LangGraph 应用程序

本演练导入一个 LangGraph 应用程序的配置——其中只有一个图,负责回答客户关于其订单的问题——并为 Docker Compose 构建该应用程序。导入会起草构建读取的每个文件:图、其 checkpointer 用于保存状态的 PostgreSQL 数据库、它调用的模型、作为变量引用的密码和密钥,以及它们各自的实现。它只询问一次任何配置中都没有的两个值:图的代码调用的模型,以及应用程序运行所在的镜像。下面的每个文件和每段输出都来自一次真实运行;配置和演练的每个阶段都位于 import-langgraph 示例中,其中的检查脚本会再次运行导入,将它写出的内容、打印的内容以及本页引用的代码块与那里保存的文件进行比较,并验证和构建导入写出的内容。

生成示例

你可以使用本页的命令运行此导入,也可以让你的 AI 助手替你运行。

将示例写入一个以其命名的新文件夹:

Terminal window
aggrega scaffold --example import-langgraph

然后它会打印接下来要运行的命令。第一条命令进入新文件夹;其后的那条命令见下文,它进入新文件夹的 source 文件夹,该文件夹包含本页导入的内容,也是运行导入的位置:

Terminal window
cd import-langgraph

在 Visual Studio Code 中打开的脚手架示例的 source 文件夹,显示其 LangGraph 配置,其中指定了一个图 support。

项目

LangGraph 应用程序将其图保存在代码中,并在 langgraph.json 中声明它们,这是 LangGraph 命令行工具的配置文件。本例是为本演练编写的,它声明了一个图 support,给出该图在应用程序代码中的导入路径和一段描述:

{
"$schema": "https://langgra.ph/schema.json",
"dependencies": ["."],
"python_version": "3.12",
"graphs": {
"support": {
"path": "./src/support_agent/graph.py:graph",
"description": "Answers a question from a customer about their order, and hands it to a person when it cannot."
}
}
}

导入只读取 langgraph.json,从不读取应用程序的代码,因此该示例只包含配置。在它旁边,一个 .aggrega-config.yaml 使该文件夹成为工作区:

# The workspace key marks this directory as the workspace root, so an import run
# here writes its drafts beside langgraph.json.
workspace: {}
# The registry the importer is fetched from the first time an import needs it.
default_registry: hub.aggrega.ai

导入会引用目录中的 LangGraph 代理、PostgreSQL 和 OpenAI 模型 Components,而 --target 会根据目录的 Recipes 起草一个 Manifest。工作区没有指定目录文件夹,因此导入会从获取其导入器的注册表中读取标准库目录:这是已发布目录的一个签名快照,由第一次导入获取、验证并保存在工作区的内容缓存中,并在导入写在其草稿旁的记录中以其摘要标明。指定了自己的目录文件夹的工作区——在 AGGREGA_CATALOG_DIRS 中,或在 workspace.catalog_dirs 下——则改为针对这些文件夹进行导入。

导入会询问什么

LangGraph 配置不指定模型,因为模型由图的代码选择;也不指定镜像,因为该镜像由你从自己的项目构建。因此导入会询问这两者:图所调用的模型的名称(用于它起草的 OpenAI 模型),以及应用程序运行所在的镜像。在终端中,它会提问,并将答案写入草稿和答案文件 import-answers.yaml,该文件位于它所导入的目录中——此处为项目根目录 .——这样下一次导入会从那里读取答案而不再提问。没有终端时——在持续集成中,或通过管道——它不提问:它写入键为空的文件,然后停止:

2 values the drafts leave empty are still owed, listed in the answers file <workspace>/import-answers.yaml: write each beside its key there, then run the import again

示例中已经包含该文件,且已填写答案:图调用 OpenAI 的 gpt-4o-mini,而 ghcr.io/example/support-agent:1.0.0 代表你构建的镜像:

# Values the import could not draft from the source, keyed by the drafted file and the key path inside
# it. Write each one beside its key; an import of the same source, and a sync, read them from here and
# ask nothing. A secret is never written here: its key asks where the secret comes from — a variable
# name, ${NAME}, or the name of a Kubernetes Secret.
aggregate.yaml:
# Left for the author, since the configuration names no model: values.model, the name of the model
# core/ai-model/openai serves.
spec.components.model.values.model: "gpt-4o-mini"
release.yaml:
# Container image running the LangGraph application code. The Docker Compose Recipe runs the catalog's
# quickstart agent when it is unset.
spec.components.support.infra.image: "ghcr.io/example/support-agent:1.0.0"
# The origin of the secret value, written by the operator in the Release. Read exactly as
# values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes
# from, never the value.
spec.components.support.uses.checkpointer_db.postgres.features.credential.infra.origin: "support-db-password"
# The origin of the secret value, written by the operator in the Release. Read exactly as
# values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes
# from, never the value.
spec.components.support.uses.model.model.features.credential.infra.origin: "openai-api-key"
# The origin of the secret value, written by the operator in the Release. Read exactly as
# values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes
# from, never the value.
spec.components.postgres.features.password.infra.origin: "support-db-password"

三个 origin 答案用于面向 Kubernetes 的构建,即使用 --target helm 时:此时数据库的密码和 OpenAI 密钥从 Kubernetes Secret 中读取,每个答案都是一个 Secret 的名称——数据库的密码来自 support-db-password(两端均是如此),密钥来自 openai-api-key——而绝不是密码或密钥本身。面向 Docker Compose 的构建则从你的 shell 中读取它们,因此本次导入不使用这些答案。导入答案文件介绍了该文件、各个问题以及机密答案的规则。

aggrega import 列出了该命令接受的每个标志,其中包括 --answers,它指定保存在其他位置的应答文件。

进入 source:

Terminal window
cd source

运行导入

指定应用程序的目录。导入只读取其中的 langgraph.json,不读取其中的任何其他文件:

Terminal window
aggrega import . --target compose

它在标准输出上列出所写的内容:

wrote aggregate.yaml
wrote release.yaml
wrote manifest.yaml
wrote .aggrega-import.json

在标准错误上,其中 <workspace> 代表你运行它的文件夹:

[… omitted: a warning that the importer runs unverified, printed where its module is read from beside its Plugin entity in a catalog folder rather than fetched]
read as the langgraph format, with drafted paths relative to <workspace>
info: the answers file <workspace>/import-answers.yaml also answers spec.components.postgres.features.password.infra.origin in release.yaml, spec.components.support.uses.checkpointer_db.postgres.features.credential.infra.origin in release.yaml, spec.components.support.uses.model.model.features.credential.infra.origin in release.yaml, which these drafts do not leave empty; those answers are kept there and not applied
mapped support (graph) to core/ai-agent/langgraph as a reference, NONE
mapped checkpointer (checkpointer) to core/datastore/postgres as a reference, NONE
mapped model (model) to core/ai-model/openai as a reference, NONE
Pull complete: <workspace>/release.lock (entities=10, source_artifacts=0, external_inputs=0)

从编辑器运行的导入:生成的 Aggregate、Release 和 Manifest 出现在 LangGraph 配置旁边,Aggrega 输出列出了图、其检查点保存器和模型的映射方式以及写出的文件,一条通知说明导入生成了 3 个文件,识别为 langgraph。

  • info 行指出 Docker Compose 草稿未使用的答案,这些答案保留在答案文件中,供面向 Kubernetes 的构建使用。
  • mapped 行表明:该图是标准库 LangGraph 代理 core/ai-agent/langgraph 的一个实例;它的检查点保存器(LangGraph 保存每个图状态的地方)是 core/datastore/postgres 的一个实例,因为配置没有指定检查点保存器,此时 LangGraph 会将状态保存在 PostgreSQL 中;而每个图所调用的模型是 core/ai-model/openai 的一个实例。它们的层级显示为 NONE:LangGraph 导入根据配置所声明的内容引用这些 Components,而不是将每一个与目录进行权衡比较。checkpointer.backend 为 mongo 的配置,会起草为基于 core/datastore/documentdb 的 core/datastore/ferretdb(它使用 MongoDB 的协议),两者的连接方式与目录中 FerretDB Aggregate 的连接方式相同,并共用同一个密码。
  • Pull complete 这一行表示导入正在像 aggrega pull 那样,将草拟的 Release 所依赖的内容获取到 release.lock 中,使草稿可以立即通过验证并构建。在 --offline 下,导入不拉取任何内容,并给出需要运行的 aggrega pull。

它写出的内容

该 Aggregate、Release 和 Manifest 命名为 imported/support,取自 langgraph.json 所服务的唯一一个图 support,因为配置不带自己的名称——服务多个图的配置按其文件命名,或者在像这里这样把目录交给导入时,按其目录命名——位于导入器的 target_namespace 设置所设定的命名空间下,除非你另行设置,否则该命名空间为 imported(设置)。

aggregate.yaml——图、其保存状态所用的数据库以及它调用的模型,每个连接都声明了自己出示的凭据,开头的注释说明了读取了什么、没有读取什么:

# LangGraph configurations read:
# - langgraph.json
# Not read: the application's code, which defines each graph; it runs in the image the Release names for each graph.
# Not carried, since they configure the server image langgraph build builds, and the image the Release names is the application's own: dependencies, python_version.
apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/support
version: 0.1.0
description: Draft Aggregate imported from a source in the langgraph format.
spec:
components:
support:
type: core/ai-agent/langgraph
values:
graph_entrypoint: "./src/support_agent/graph.py:graph"
description: "Answers a question from a customer about their order, and hands it to a person when it cannot."
uses:
checkpointer_db:
postgres:
target: postgres
# For the compose target, the lines below declare credential on postgres: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none.
features:
credential:
type: core/secret-value
values:
key: POSTGRES_PASSWORD
model:
model:
target: model
# For the compose target, the lines below declare credential on model: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none.
features:
credential:
type: core/secret-value
values:
key: OPENAI_API_KEY
# The database the configuration's checkpointer keeps each graph's state in, PostgreSQL.
postgres:
type: core/datastore/postgres
features:
# For the compose target, the lines below declare password on postgres: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none.
password:
type: core/secret-value
values:
key: POSTGRES_PASSWORD
# The model every graph calls, which the configuration does not name.
model:
type: core/ai-model/openai
values:
# Left for the author, since the configuration names no model: values.model, the name of the model core/ai-model/openai serves.
model: "gpt-4o-mini"

graph_entrypoint 是配置中所写的图导入路径。其 checkpointer_db 连接接到该数据库,其 model 连接接到模型,模型名称是导入从 import-answers.yaml 中读取的答案。recursion_limit 没有写出,因此沿用 Component 的默认值 25。数据库获得一个密码,因此 PostgreSQL Recipe 不再自行写入密码,而图在连接数据库时出示同一个密码。

release.yaml——环境、镜像、发布的端口,以及密钥和密码的来源,图上方的注释说明了它的镜像是什么、它会收到什么:

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/support
# environment is a drafted default, since no source names the environment this Release deploys to; change it to name the one it deploys to.
environment: development
version: 0.1.0
description: Draft Release imported from a source in the langgraph format.
spec:
aggregate: imported/support
manifest: imported/support
components:
# Each graph's image is the application's own, not the server image langgraph build builds: its code, with LangGraph installed.
# It is handed, for its code to read, the graph to run as LANGGRAPH_GRAPH_ENTRYPOINT, the model's name as OPENAI_MODEL, the checkpointer store's host and port as LANGGRAPH_CHECKPOINTER_HOST and LANGGRAPH_CHECKPOINTER_PORT, its user and database, where the store publishes them, as LANGGRAPH_CHECKPOINTER_USER and LANGGRAPH_CHECKPOINTER_DATABASE, and a password attached on the checkpointer_db connection as LANGGRAPH_CHECKPOINTER_PASSWORD.
# It is also handed the model's address as OPENAI_BASE_URL and a key attached on the model connection as OPENAI_API_KEY, which the OpenAI client library reads, and recursion_limit as LANGGRAPH_DEFAULT_RECURSION_LIMIT, which LangGraph reads.
# An inject: block on the graph's own instance, through an entry reading graph_entrypoint alone, replaces LANGGRAPH_GRAPH_ENTRYPOINT with the name it writes; one on the model connection replaces OPENAI_MODEL, and one on the checkpointer_db connection the store's host, port, user and database, with the names it writes.
support:
infra:
# Left for the Release, since the source cannot supply it: infra.image, the container image running the application
image: "ghcr.io/example/support-agent:1.0.0"
# Published on this machine's loopback address, 127.0.0.1: reachable from this machine only, by any process running on it. Delete this line to keep the service internal.
published_port: 8000
uses:
checkpointer_db:
postgres:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential support presents to postgres on its checkpointer_db connection, the password of postgres (the configuration names no variable for it), read from the variable POSTGRES_PASSWORD, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value.
origin: "${POSTGRES_PASSWORD}"
model:
model:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential support presents to model on its model connection (the source names no variable for it, so it is read from the one OpenAI's client libraries read the API key from), read from the variable OPENAI_API_KEY, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value.
origin: "${OPENAI_API_KEY}"
postgres:
features:
password:
type: core/secret-value
infra:
# Attached by reference, never as a value: the password of postgres (the configuration names no variable for it), read from the variable POSTGRES_PASSWORD, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value.
origin: "${POSTGRES_PASSWORD}"
model: {}

环境 development 是导入写入的默认值,因为没有任何配置指定环境;在 Release 部署到其他地方时修改它。镜像是导入从 import-answers.yaml 中读取的答案。图发布在你机器的环回地址的 8000 端口上,并转发到其程序监听的端口 infra.port,除非你另行设置,否则为 8000。密钥和密码是变量引用 ${OPENAI_API_KEY} 和 ${POSTGRES_PASSWORD},绝不是值。

manifest.yaml——每种类型的 Compose Recipe,以及将每个变量引用按原样写入 Compose 文件的实现:

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/support
version: 0.1.0
spec:
mappings:
components:
type:
core/ai-agent/langgraph: compose/langgraph
core/datastore/postgres: compose/postgres
core/ai-model/openai: compose/openai
features:
type:
core/secret-value: compose/dotenv-secret

release.lock 按摘要记录该 Release 解析到的目录实体,.aggrega-import.json 则是导入所写内容的记录,之后的 aggrega import --sync 会读取它。

验证并构建

Terminal window
aggrega validate --release release.yaml
aggrega build --release release.yaml

验证后在编辑器中打开的生成的 Release,Aggrega 输出和一条通知都报告未发现问题。

生成的 Release 的构建:资源管理器中出现一个 dist 文件夹,Aggrega 输出列出了写出的 Docker Compose 文件,一条通知说明写出了 1 个文件。

验证打印:

notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)
release dependency validation passed: release.yaml (schema-pillar + dependency pillars)

以及构建,其中 <workspace> 代表你运行它的文件夹:

notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)
[… omitted: a total build time, which differs per run]
Build completed: 1 file written to <workspace>/dist

notice 行仅供参考:机密 Feature 从 Aggregate 的 values 或 Release 的 infra 接受其 origin,该通知报告有一个叶节点在两者中都有声明。它不会改变任何判定结果。

构建会写出 dist/compose/docker-compose.yaml,其中包含图的一个服务、数据库的一个服务,以及一个等待数据库的服务。图的服务:

support:
image: ghcr.io/example/support-agent:1.0.0
environment:
LANGGRAPH_DEFAULT_RECURSION_LIMIT: "25"
OPENAI_BASE_URL: https://api.openai.com/v1
OPENAI_MODEL: gpt-4o-mini
LANGGRAPH_CHECKPOINTER_HOST: postgres
LANGGRAPH_CHECKPOINTER_PORT: "5432"
LANGGRAPH_CHECKPOINTER_USER: appuser
LANGGRAPH_CHECKPOINTER_DATABASE: appdb
LANGGRAPH_GRAPH_ENTRYPOINT: ./src/support_agent/graph.py:graph
OPENAI_API_KEY: ${OPENAI_API_KEY}
LANGGRAPH_CHECKPOINTER_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- 127.0.0.1:8000:8000
[… omitted: the labels the build writes on every service, naming the Aggregate, the component, the environment and the compiler's version]
networks:
- compose
depends_on:
support--wait-for-store:
condition: service_completed_successfully
postgres:
condition: service_started

图接收模型的地址、名称和密钥,数据库的主机、端口、用户、数据库名称和密码,以及它自己的图入口点。用户和数据库名称是 PostgreSQL Component 的默认值 appuser 和 appdb,下文的数据库服务正是用它们创建的;图之所以收到它们,是因为 PostgreSQL Recipe 发布了这两项,而对于两项都不发布的存储(例如 Valkey),图两项都不会收到。模型的名称、数据库的主机、端口、用户和数据库名称以及图入口点会以 LangGraph Component 默认提供的名称到达;在连接上添加 inject: 块,或针对组件自身的值在组件自身上添加该块,可将这些名称替换为你的代码读取的名称。模型的地址、密钥和数据库的密码保持这些块中所写的名称,LANGGRAPH_DEFAULT_RECURSION_LIMIT 也是如此,LangGraph 会自行读取它,作为配置中未设置步数限制的运行的步数限制。数据库自身的服务使用同一个密码:

postgres:
image: postgres:16
environment:
POSTGRES_USER: appuser
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: appdb
[… omitted: the labels the build writes on every service, the network, and a health check running PostgreSQL's pg_isready]

图的服务只有在第三个服务完成后才会启动。第三个服务只运行一次,使用目录中 quickstart 智能体的镜像,而不是图自己的镜像,它会等待数据库的地址接受 TCP 连接,每 2 秒尝试一次,最长 300 秒;如果届时仍未建立连接,它会退出并指出该地址,图也不会启动。它只接收数据库的主机和端口,别无其他:

support--wait-for-store:
image: hub.aggrega.ai/tools/quickstart-agent:1.0.1@sha256:a5f8dcfbb670d86a0cae0aadd2844bec93221a651238f8be3863873e261ee168
[… omitted: the command and the entrypoint, a bash loop that opens a connection to the address]
environment:
STORE_HOST: postgres
STORE_PORT: "5432"
[… omitted: the labels the build writes on every service, and the network]
restart: "no"

密钥和密码都是变量引用,在栈启动时从你的 shell 中填充。模型没有自己的服务:图通过 OpenAI API 自身的地址访问它。图的服务只在 127.0.0.1 上发布其端口,而数据库自身的端口在栈的网络上访问,不发布任何内容。

借助 AI 助手

配置了 Aggrega 工具的 AI 助手也可以完成同样的操作:将下面的提示词粘贴给它。

只使用 Aggrega 工具,不要自行创建任何文件夹。如果 Workspace 文件夹中还没有 `import-langgraph` 文件夹,请调用一次 `scaffold` 工具,将 `example` 设为 `import-langgraph`,且不设 `dir`:它会把示例写入新的 `import-langgraph` 文件夹,其中的 `source` 文件夹包含本页导入的内容。然后调用 `import` 工具,将 `workspace_root` 设为 `import-langgraph/source`,`source` 设为 `.`,`target` 设为 `compose`:它会从 `langgraph.json` 旁边的 `import-answers.yaml` 读取所需的回答,将草稿写入 `import-langgraph/source`,并拉取草稿所需的内容。然后调用 `validate` 工具,将 `workspace_root` 设为 `import-langgraph/source`,`release` 设为 `release.yaml`;再调用 `build` 工具,将 `workspace_root` 设为 `import-langgraph/source`,`release` 设为 `release.yaml`,`write` 设为 true。告诉我构建写出了哪些文件;它们位于 `import-langgraph/source/dist/` 下。

在 VS Code 中打开

安装 Visual Studio Code 的 Aggrega 扩展 后,在 VS Code 中打开导入写入草稿的文件夹 import-langgraph/source。该文件夹只包含一个 Release,即生成的 release.yaml,因此编辑器会为你选中它,并在你编辑草稿时根据该 Release 检查草稿,在文件中和“问题”面板中标出发现的内容。命令面板中的 Aggrega: Show topology graph 会绘制该 Release 的组件及其之间的连接。Aggrega: Build、Aggrega: Preview build 和 Aggrega: Pull 作用于同一个 Release,并且每个命令也是活动栏中 Aggrega 视图的 Commands 面板上的一个按钮;Build 会将文件写入该文件夹的 dist/ 中。其余内容见 在 Visual Studio Code 中使用 Aggrega。

运行

你使用自己的 Dockerfile 从项目构建镜像:其中是图的代码,并安装了 LangGraph。由于 Recipe 没有设置命令,Docker Compose 会将镜像自身的命令作为图的服务运行,因此该命令必须持续运行,并且如果你想访问图,它还必须处理请求。它通过上面的变量找到图、模型和数据库。地址、路由和回复由你的程序决定。

下面的运行使用了这样一个镜像:图位于 langgraph.json 指定的路径 src/support_agent/graph.py,一个节点通过 OPENAI_MODEL 指定的模型作答,镜像的命令则是程序自带的一个小型 HTTP 服务器,监听 8000 端口。镜像在其工作目录中保留项目的目录结构,因此 LANGGRAPH_GRAPH_ENTRYPOINT 指定的、相对于该目录的路径能够找到图。服务器加载该图,通过 LangGraph 的 PostgreSQL checkpointer 将每个对话的状态保存在数据库中(该 checkpointer 使用数据库的主机、端口、用户、数据库名称和密码打开,每一项都从其到达时所在的 LANGGRAPH_CHECKPOINTER_ 变量中读取,因此程序自身不写入其中任何一项),并针对每个 POST /threads/<thread>/runs 运行一次图。图的服务会在数据库开始接受连接后启动,因此在启动时打开 checkpointer 的服务器会发现数据库已在接受连接。在项目根目录构建你的镜像,在 import-answers.yaml 中用它的名称替换 ghcr.io/example/support-agent:1.0.0,然后使用 --sync 再次导入,它会把新答案写入草稿并再次拉取;然后构建:

Terminal window
docker build -t order-support:local .
aggrega import . --sync
aggrega build --release release.yaml

然后在你的 shell 中设置密钥和数据库密码,并启动堆栈:

Terminal window
export OPENAI_API_KEY='your OpenAI key'
export POSTGRES_PASSWORD='a password of your own'
docker compose -p order-support -f dist/compose/docker-compose.yaml up -d --wait

-p 用于为项目命名,正如 导入如何运行 中的运行步骤所述。--wait 会在数据库报告健康、对数据库的等待已完成且图的服务运行后返回。

测试

下面的请求会到达本演练的镜像所运行的程序:位于端口 8000 上一个小型 HTTP 服务器之后的图,它响应 POST /threads/<thread>/runs。你自己的程序自行决定其路由和回复。将请求发送到 published_port 所发布的地址 http://127.0.0.1:8000:

Terminal window
curl -sS -X POST http://127.0.0.1:8000/threads/order-1234/runs -H 'Content-Type: application/json' \
-d '{"message": "Where is my order 1234? It has not arrived yet."}'
{
"thread": "order-1234",
"error": "the run failed: OpenAIAuthenticationError: Error code: 401 - Incorrect API key provided: sk-place************-key. [… omitted: where to find an API key]"
}

本次运行将 OPENAI_API_KEY 设置为占位值,因此回复是 OpenAI 对它的拒绝,由程序转发。图的请求携带构建所提供的密钥到达了 OpenAI API,发出请求的程序已使用构建所提供的凭据在数据库中打开了其 checkpointer。

使用以下命令停止该栈:

Terminal window
docker compose -p order-support -f dist/compose/docker-compose.yaml down -v

-v 会删除数据库存放数据的卷,对话也随之删除。

在 Kubernetes 上,使用 --target helm 导入,并将镜像推送到你的集群可从中拉取的镜像仓库,在 import-answers.yaml 中写明其名称。然后创建 Secret openai-api-key 和 support-db-password,并按照 导入如何运行 中运行步骤的说明应用构建。图的 Deployment 没有 Service。在数据库接受连接之前,它的 pod 会不断重启,因为程序在启动时打开其 checkpointer。将一个本地端口转发到它;该命令会一直运行,直到你停止它:

Terminal window
kubectl port-forward deploy/support 8000:8000
Forwarding from 127.0.0.1:8000 -> 8000
Forwarding from [::1]:8000 -> 8000

在另一个终端中,向转发的端口发送同样的请求:

Terminal window
curl -sS -X POST http://127.0.0.1:8000/threads/order-1234/runs -H 'Content-Type: application/json' \
-d '{"message": "Where is my order 1234? It has not arrived yet."}'
{
"thread": "order-1234",
"error": "the run failed: OpenAIAuthenticationError: Error code: 401 - Incorrect API key provided: sk-place************-key. [… omitted: where to find an API key]"
}