新闻详情

新闻详情

首页 / 资讯中心 / 详情

(LangGraph教程)1. Introduction——Lesson 8: Deployment(可选)(好像没啥用,还得开会员)

发布时间:2026/11/15 2:44:08来源:尧图网络
(LangGraph教程)1. Introduction——Lesson 8: Deployment(可选)(好像没啥用,还得开会员)
https://academy.langchain.com/courses/intro-to-langgraphhttps://github.com/shangxiang0907/langchain-academy文章目录[Optional] Lesson 8: DeploymentLangSmith Deployment was formerly LangGraph Platform.Deployment 部署Review 回顾Goals 目标Concepts 概念Testing Locally 本地测试StudioTesting with Cloud 使用云服务测试Create a New Repository on GitHub 在 GitHub 上新建仓库Add Your GitHub Repository as a Remote 将您的 GitHub 仓库添加为远程仓库Connect LangSmith to your GitHub Repository 将 LangSmith 连接到您的 GitHub 仓库Work with your deployment 与你的部署交互[Optional] Lesson 8: Deployment中文[可选] 第8课部署Currently, LangSmith Deployment is available only for LangSmith Plus plan users.中文目前LangSmith Deployment 仅向 LangSmith Plus 套餐用户开放。Lesson 8 in this course is optional.中文本课程的第8课为可选内容。LangSmith Deployment was formerly LangGraph Platform.中文LangSmith Deployment 原名为 LangGraph Platform。Notebook Reference: deployment.ipynb中文笔记本参考文件deployment.ipynbDownload Notebook onGitHub中文在GitHub上下载笔记本。View Notebook onGoogle Colab中文在Google Colab上查看笔记本。Deployment 部署Review 回顾We built up to an agent with memory:我们已构建出一个具备记忆能力的智能体act- let the model call specific toolsact— 允许模型调用特定工具observe- pass the tool output back to the modelobserve— 将工具输出传回模型reason- let the model reason about the tool output to decide what to do next (e.g., call another tool or just respond directly)reason— 让模型基于工具输出进行推理以决定下一步操作例如调用另一工具或直接响应persist state- use an in memory checkpointer to support long-running conversations with interruptionspersist state— 使用内存中的检查点器checkpointer支持带中断的长时间运行对话Goals 目标Now, we’ll cover how to actually deploy our agent locally to Studio and toLangGraph Cloud.接下来我们将介绍如何将智能体实际部署到本地 Studio 和LangGraph Cloud。%%capture--no-stderr%pip install--quiet-U langgraph_sdk langchain_coreConcepts 概念There are a few central concepts to understand -需理解若干核心概念 —LangGraph—LangGraph—Python and JavaScript libraryPython 与 JavaScript 库Allows creation of agent workflows支持创建智能体工作流LangGraph API—LangGraph API—Bundles the graph code封装图graph代码Provides a task queue for managing asynchronous operations提供任务队列用于管理异步操作Offers persistence for maintaining state across interactions提供持久化能力以在多次交互间维持状态LangSmith Deployment(formerlyLangGraph Cloud) –LangSmith Deployment原LangGraph Cloud——Hosted service for the LangGraph API托管式 LangGraph API 服务Allows deployment of graphs from GitHub repositories支持从 GitHub 仓库部署图Also provides monitoring and tracing for deployed graphs还为已部署的图提供监控与追踪功能Accessible via a unique URL for each deployment每个部署均通过唯一 URL 访问LangSmith Studio(formerlyLangGraph Studio) –LangSmith Studio原LangGraph Studio——Integrated Development Environment (IDE) for LangGraph applications面向 LangGraph 应用的集成开发环境IDEUses the API as its back-end, allowing real-time testing and exploration of graphs以后端 API 为基础支持对图进行实时测试与探索Can be run locally or with cloud-deployment. See below.可本地运行亦支持云部署。详见下文。LangGraph SDK–LangGraph SDK——Python library for programmatically interacting with LangGraph graphs用于以编程方式与 LangGraph 图交互的 Python 库Provides a consistent interface for working with graphs, whether served locally or in the cloud无论图是本地托管还是云端托管均提供统一接口Allows creation of clients, access to assistants, thread management, and execution of runs支持创建客户端、访问助手、线程管理及执行运行runTesting Locally 本地测试Studio⚠️ Notice⚠️ 注意Since filming these videos, we’ve updated Studio so that it can now be run locally and accessed through your browser.自录制本系列视频以来我们已更新 Studio使其现在可本地运行并可通过浏览器访问。This is the preferred way to run Studio instead of using the Desktop App shown in the video.这是运行 Studio 的首选方式而非视频中演示的桌面应用。It is now calledLangSmith Studioinstead ofLangGraph Studio.它现称为LangSmith Studio而非LangGraph Studio。Detailed setup instructions are available in the “Getting Setup” guide at the start of the course.详细安装说明请参阅本课程开头的“开始设置”指南。You can find a description of Studio here, and specific details for local deployment here.您可在此处查看 Studio 的说明文档 此处本地部署的具体细节请参见 此处。To start the local development server, run the following command in your terminal in the/studiodirectory in this module:要在本地启动开发服务器请在本模块的/studio目录下于终端中运行以下命令langgraph devYou should see the following output:您应看到如下输出- API: http://127.0.0.1:2024 - Studio UI: https://smith.langchain.com/studio/?baseUrlhttp://127.0.0.1:2024 - API Docs: http://127.0.0.1:2024/docsOpen your browser and navigate to theStudio UIURL shown above.打开浏览器并导航至上方显示的Studio UIURL。ifgoogle.colabinstr(get_ipython()):raiseException(Unfortunately LangGraph Studio is currently not supported on Google Colab)fromlanggraph_sdkimportget_client# This is the URL of the local development serverURLhttp://127.0.0.1:2024clientget_client(urlURL)# Search all hosted graphsassistantsawaitclient.assistants.search()assistants[-3]{assistant_id: fe096781-5601-53d2-b2f6-0d3403f7e9ca, graph_id: agent, config: {}, metadata: {created_by: system}, name: agent, created_at: 2025-03-04T22:57:28.42456500:00, updated_at: 2025-03-04T22:57:28.42456500:00, version: 1}# We create a thread for tracking the state of our runthreadawaitclient.threads.create()Now, we can run our agent withclient.runs.streamwith:现在我们可以使用client.runs.stream运行我们的智能体Thethread_idThegraph_idTheinputThestream_modeWe’ll discuss streaming in depth in a future module.我们将在后续模块中深入探讨流式处理streaming。For now, just recognize that we are streaming the full value of the state after each step of the graph withstream_modevalues.目前只需了解我们正以stream_modevalues方式 流式传输即在图每一步执行后输出完整状态值。The state is captured in thechunk.data.状态值保存在chunk.data中。fromlangchain_core.messagesimportHumanMessage# Inputinput{messages:[HumanMessage(contentMultiply 3 by 2.)]}# Streamasyncforchunkinclient.runs.stream(thread[thread_id],agent,inputinput,stream_modevalues,):ifchunk.dataandchunk.event!metadata:print(chunk.data[messages][-1]){content: Multiply 3 by 2., additional_kwargs: {example: False, additional_kwargs: {}, response_metadata: {}}, response_metadata: {}, type: human, name: None, id: cdbd7bd8-c476-4ad4-8ab7-4ad9e3654267, example: False} {content: , additional_kwargs: {tool_calls: [{index: 0, id: call_iIPryzZZxRtXozwwhVtFObNO, function: {arguments: {a:3,b:2}, name: multiply}, type: function}]}, response_metadata: {finish_reason: tool_calls, model_name: gpt-4o-2024-05-13, system_fingerprint: fp_157b3831f5}, type: ai, name: None, id: run-06c7243c-426d-4c81-a113-f1335dda5fb2, example: False, tool_calls: [{name: multiply, args: {a: 3, b: 2}, id: call_iIPryzZZxRtXozwwhVtFObNO, type: tool_call}], invalid_tool_calls: [], usage_metadata: None} {content: 6, additional_kwargs: {}, response_metadata: {}, type: tool, name: multiply, id: 988cb170-f6e6-43c1-82fd-309f519abe6d, tool_call_id: call_iIPryzZZxRtXozwwhVtFObNO, artifact: None, status: success} {content: The result of multiplying 3 by 2 is 6., additional_kwargs: {}, response_metadata: {finish_reason: stop, model_name: gpt-4o-2024-05-13, system_fingerprint: fp_157b3831f5}, type: ai, name: None, id: run-7bda0aa0-6895-4250-9625-18419c5dc171, example: False, tool_calls: [], invalid_tool_calls: [], usage_metadata: None}Testing with Cloud 使用云服务测试We can deploy to Cloud via LangSmith, as outlined here.我们可通过 LangSmith 部署至云服务具体步骤详见 此处。Create a New Repository on GitHub 在 GitHub 上新建仓库Go to your GitHub account前往您的 GitHub 账户Click on the “” icon in the upper-right corner and selectNew repository点击右上角的 “” 图标选择“New repository”Name your repository (e.g.,langchain-academy)为您的仓库命名例如langchain-academyAdd Your GitHub Repository as a Remote 将您的 GitHub 仓库添加为远程仓库Go back to your terminal where you clonedlangchain-academyat the start of this course返回本课程初始时克隆langchain-academy的终端Add your newly created GitHub repository as a remote将新创建的 GitHub 仓库添加为远程仓库git remote add origin https://github.com/your-username/your-repo-name.gitPush to it推送至该仓库git push -u origin mainConnect LangSmith to your GitHub Repository 将 LangSmith 连接到您的 GitHub 仓库Go to LangSmith访问 LangSmithClick ondeploymentstab on the left LangSmith panel点击 LangSmith 左侧面板中的deployments标签页Add New Deployment添加 新建部署Then, select the Github repository (e.g.,langchain-academy) that you just created for the course然后选择你为本课程刚刚创建的 GitHub 仓库例如langchain-academyPoint theLangGraph API config fileat one of thestudiodirectories将LangGraph API 配置文件指向某个studio目录For example, for module-1 use:module-1/studio/langgraph.json例如对于 module-1请使用module-1/studio/langgraph.jsonSet your API keys (e.g., you can just copy from yourmodule-1/studio/.envfile)设置你的 API 密钥例如可直接从module-1/studio/.env文件中复制Work with your deployment 与你的部署交互We can then interact with our deployment a few different ways:随后我们可通过几种不同方式与部署进行交互With the SDK, as before.使用 SDK方式与之前相同。With LangGraph Studio.使用 LangGraph Studio。To use the SDK here in the notebook, simply ensure thatLANGSMITH_API_KEYis set!若要在本笔记本中使用 SDK请确保已设置LANGSMITH_API_KEYimportos,getpassdef_set_env(var:str):ifnotos.environ.get(var):os.environ[var]getpass.getpass(f{var}: )_set_env(LANGSMITH_API_KEY)# Replace this with the URL of your deployed graphURLhttps://langchain-academy-8011c561878d50b1883f7ed11b32d720.default.us.langgraph.appclientget_client(urlURL)# Search all hosted graphsassistantsawaitclient.assistants.search()# Select the agentagentassistants[0]agent{assistant_id: fe096781-5601-53d2-b2f6-0d3403f7e9ca, graph_id: agent, created_at: 2024-08-23T17:58:02.72292000:00, updated_at: 2024-08-23T17:58:02.72292000:00, config: {}, metadata: {created_by: system}}fromlangchain_core.messagesimportHumanMessage# We create a thread for tracking the state of our runthreadawaitclient.threads.create()# Inputinput{messages:[HumanMessage(contentMultiply 3 by 2.)]}# Streamasyncforchunkinclient.runs.stream(thread[thread_id],agent,inputinput,stream_modevalues,):ifchunk.dataandchunk.event!metadata:print(chunk.data[messages][-1]){content: Multiply 3 by 2., additional_kwargs: {example: False, additional_kwargs: {}, response_metadata: {}}, response_metadata: {}, type: human, name: None, id: 8ea04559-f7d4-4c82-89d9-c60fb0502f21, example: False} {content: , additional_kwargs: {tool_calls: [{index: 0, id: call_EQoolxFaaSVU8HrTnCmffLk7, function: {arguments: {a:3,b:2}, name: multiply}, type: function}]}, response_metadata: {finish_reason: tool_calls, model_name: gpt-4o-2024-05-13, system_fingerprint: fp_3aa7262c27}, type: ai, name: None, id: run-b0ea5ddd-e9ba-4242-bb8c-80eb52466c76, example: False, tool_calls: [{name: multiply, args: {a: 3, b: 2}, id: call_EQoolxFaaSVU8HrTnCmffLk7, type: tool_call}], invalid_tool_calls: [], usage_metadata: None} {content: 6, additional_kwargs: {}, response_metadata: {}, type: tool, name: multiply, id: 1bf558e7-79ef-4f21-bb66-acafbd04677a, tool_call_id: call_EQoolxFaaSVU8HrTnCmffLk7, artifact: None, status: success} {content: 3 multiplied by 2 equals 6., additional_kwargs: {}, response_metadata: {finish_reason: stop, model_name: gpt-4o-2024-05-13, system_fingerprint: fp_3aa7262c27}, type: ai, name: None, id: run-ecc4b6ad-af15-4a85-a76c-de2ed0ed8ed9, example: False, tool_calls: [], invalid_tool_calls: [], usage_metadata: None}
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

【外设】之大彩串口显示屏 2026/11/14 3:51:47

【外设】之大彩串口显示屏

大彩串口屏初步使用 1 .官网下载 STM32 屏幕 GUI 设计资料 http://www.gz-dc.com/category/typeid/4112 找到 STM32 Keil 工程,移植相关代码因项目而异进行移植,由于项目简单,本人只对用到的指令接口进行修改。 比如:注意事项&…

阅读更多 →
无法下载Windows系统iso文件 2026/11/15 2:04:12

无法下载Windows系统iso文件

当我遇到这个问题的时候,我打开了一个网站: 登录 然后我打算下载的时候: 突然那个官方的连接就可以下载了:

阅读更多 →
【清华代码熊】DeepSeek V4.1 Flash 后训练详解 2026/11/14 10:11:15

【清华代码熊】DeepSeek V4.1 Flash 后训练详解

📌 上期解析了 DeepSeek V4.1 Flash 模型架构改进,本期解析 DeepSeek V4.1 Flash 预训练/后训练技术: 🌟 预训练:45T 文本 多模态混合语料、直接训练 sparse attention(取消 DeepSeek V4 的 dense 冷启动&…

阅读更多 →
Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ... 2026/11/14 17:14:38

Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ...

文章主要内容和创新点 主要内容 本文聚焦于多模态大语言模型(MLLM)强化学习(RL)训练中的效率问题,提出了一个名为Shuffle-R1的框架。研究发现,当前RL训练存在两个关键缺陷: 优势值坍缩(Advantage Collapsing):批次中大多数优势值集中在零附近,导致有效梯度信号被淹…

阅读更多 →
PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction 2026/11/14 16:35:50

PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction

一、文章主要内容总结 本文聚焦于利用大型语言模型(LLMs)实现个人身份信息(PII)脱敏的研究,旨在解决传统脱敏方法(如基于规则的系统、领域特定命名实体识别(NER)模型)泛化能力差、跨格式/跨语境适应性弱的问题。 研究通过全面评估多种LLM架构(包括密集型LLM(D-LLM…

阅读更多 →
LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model 2026/11/14 3:51:43

LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model

文章主要内容和创新点 主要内容 本文聚焦于二进制图像-文本相关性评估任务(判断图像与文本“相关”或“不相关”),针对该任务中文本格式多样、相关性定义随场景变化等挑战,提出了基于多模态大语言模型(MLLM)的解决方案LLaVA-RE。 模型设计:LLaVA-RE基于LLaVA 1.5架构,…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉