当前位置: 首页 > news >正文

使用大语言模型对接OA系统,实现会议室预定功能

随着人工智能技术的不断进步,越来越多的企业开始借助 AI 助手来提高工作效率,尤其是在日常事务的自动化处理中。比如,在许多公司里,会议室的预定是一个常见且频繁的需求,通常需要员工手动检查空闲时间并做出选择。而通过集成 AI 和自动化工具,这个过程可以变得更加智能和高效。

本文将展示如何利用 LangChain 和 LangGraph 两个强大的工具,构建一个会议室预订系统。这一系统能够与用户进行自然语言交互,帮助用户自动预订会议室,并确保预订信息的准确性。我们会详细讲解如何实现从查询空闲会议室到确认预订的整个过程。

关键代码

下面是实现该系统的核心代码。在这个代码段中,我们通过 LangChain 定义了几个重要的工具,分别是:获取所有会议室、查询指定时间段内可用的会议室和预订会议室。

from config import *
from datetime import datetime
from langchain_core.tools import tool
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_openai import ChatOpenAI
from langgraph.types import Command, interrupt
from langgraph.prebuilt import create_react_agent
from IPython.display import Image, display
from langgraph.checkpoint.memory import InMemorySaver
/Users/zhengjie/Documents/learn-langchain/venv/lib/python3.9/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020warnings.warn(
@tool(parse_docstring=True)
def get_all_rooms() -> list:"""Get a list of all available meeting rooms.Returns:list: A list of all available meeting rooms."""return ["Room 1", "Room 2", "Room 3", "888 Multimedia Conference Room"]@tool(parse_docstring=True)
def get_available_rooms(start_time: str, end_time: str) -> list:"""Get a list of all available meeting rooms during the specified time period.Args:start_time (str): The start time of the booking (e.g., "2025-02-23 14:00").end_time (str): The end time of the booking (e.g., "2025-02-23 15:00").Returns:list: A list of all available meeting rooms during the specified time period."""return ["Room 1", "Room 2"]@tool(parse_docstring=True)
def book_room(name: str, start_time: str, end_time: str) -> str:"""Book a specified meeting room for the user, only after the user confirms the details.Args:name (str): The name of the meeting room to be booked.start_time (str): The start time of the booking (e.g., "2025-02-23 14:00").end_time (str): The end time of the booking (e.g., "2025-02-23 15:00").Returns:str: A message indicating whether the booking was successful or failed."""if name in ["Room 1", "Room 2", "Room 3", "888 Multimedia Conference Room"]:if name in ["Room 1", "Room 2"]:return "Booking successful"else:return "The room is not available"else:return "Invalid room name"
tools = [get_all_rooms, get_available_rooms, book_room]
llm = ChatOpenAI(model="qwen-max")
memory = InMemorySaver()
prompt = SystemMessage(f"You are an AI assistant. The current time is: {datetime.now().strftime('%Y-%m-%d %H:%M')}. "f"Please assist the user in booking a meeting room by confirming the meeting time and room step by step. "f"Keep your language as concise as possible.\n"f"The most important thing is that before using book_room, make sure to confirm the information with the user one last time. "f"Only proceed with book_room if everything is correct. Do not skip this step."
)
agent = create_react_agent(llm, tools, checkpointer=memory, prompt=prompt)
prompt.pretty_print()
================================[1m System Message [0m================================You are an AI assistant. The current time is: 2025-02-23 21:58. Please assist the user in booking a meeting room by confirming the meeting time and room step by step. Keep your language as concise as possible.
The most important thing is that before using book_room, make sure to confirm the information with the user one last time. Only proceed with book_room if everything is correct. Do not skip this step.
display(Image(agent.get_graph().draw_mermaid_png()))

请添加图片描述

使用案例

会议室预订案例1

config = {"configurable": {"thread_id": "abc123"}}
result = agent.invoke({"messages": [{"role": "user", "content": "帮我预定一个会议室"}]},config=config
)
for m in result['messages']:m.pretty_print()
================================[1m Human Message [0m=================================帮我预定一个会议室
==================================[1m Ai Message [0m==================================好的,我来帮您预定会议室。请告诉我您计划的会议开始时间和结束时间。例如:14:00到16:00。
config = {"configurable": {"thread_id": "abc123"}}
result = agent.invoke({"messages": [{"role": "user", "content": "明天上午10点到11点"}]},config=config
)
for m in result['messages']:m.pretty_print()
================================[1m Human Message [0m=================================帮我预定一个会议室
==================================[1m Ai Message [0m==================================好的,我来帮您预定会议室。请告诉我您计划的会议开始时间和结束时间。例如:14:00到16:00。
================================[1m Human Message [0m=================================明天上午10点到11点
==================================[1m Ai Message [0m==================================
Tool Calls:get_available_rooms (call_a39d8e624ae845b6a1e02b)Call ID: call_a39d8e624ae845b6a1e02bArgs:start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
=================================[1m Tool Message [0m=================================
Name: get_available_rooms["Room 1", "Room 2"]
==================================[1m Ai Message [0m==================================明天上午10点到11点之间有以下会议室可供选择:- Room 1
- Room 2您想要预定哪一个会议室呢?请告诉我会议室的名称。
config = {"configurable": {"thread_id": "abc123"}}
result = agent.invoke({"messages": [{"role": "user", "content": "第一个"}]},config=config
)
for m in result['messages']:m.pretty_print()
================================[1m Human Message [0m=================================帮我预定一个会议室
==================================[1m Ai Message [0m==================================好的,我来帮您预定会议室。请告诉我您计划的会议开始时间和结束时间。例如:14:00到16:00。
================================[1m Human Message [0m=================================明天上午10点到11点
==================================[1m Ai Message [0m==================================
Tool Calls:get_available_rooms (call_a39d8e624ae845b6a1e02b)Call ID: call_a39d8e624ae845b6a1e02bArgs:start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
=================================[1m Tool Message [0m=================================
Name: get_available_rooms["Room 1", "Room 2"]
==================================[1m Ai Message [0m==================================明天上午10点到11点之间有以下会议室可供选择:- Room 1
- Room 2您想要预定哪一个会议室呢?请告诉我会议室的名称。
================================[1m Human Message [0m=================================第一个
==================================[1m Ai Message [0m==================================好的,您选择了Room 1。请确认您的预定信息:会议室为Room 1,时间是明天上午10点到11点。如果这些信息正确,我将为您完成预定。信息正确吗?请回复“正确”或“不正确”。
config = {"configurable": {"thread_id": "abc123"}}
result = agent.invoke({"messages": [{"role": "user", "content": "确认"}]},config=config
)
for m in result['messages']:m.pretty_print()
================================[1m Human Message [0m=================================帮我预定一个会议室
==================================[1m Ai Message [0m==================================好的,我来帮您预定会议室。请告诉我您计划的会议开始时间和结束时间。例如:14:00到16:00。
================================[1m Human Message [0m=================================明天上午10点到11点
==================================[1m Ai Message [0m==================================
Tool Calls:get_available_rooms (call_a39d8e624ae845b6a1e02b)Call ID: call_a39d8e624ae845b6a1e02bArgs:start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
=================================[1m Tool Message [0m=================================
Name: get_available_rooms["Room 1", "Room 2"]
==================================[1m Ai Message [0m==================================明天上午10点到11点之间有以下会议室可供选择:- Room 1
- Room 2您想要预定哪一个会议室呢?请告诉我会议室的名称。
================================[1m Human Message [0m=================================第一个
==================================[1m Ai Message [0m==================================好的,您选择了Room 1。请确认您的预定信息:会议室为Room 1,时间是明天上午10点到11点。如果这些信息正确,我将为您完成预定。信息正确吗?请回复“正确”或“不正确”。
================================[1m Human Message [0m=================================确认
==================================[1m Ai Message [0m==================================
Tool Calls:book_room (call_824c897caa2d40f98328a9)Call ID: call_824c897caa2d40f98328a9Args:name: Room 1start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
=================================[1m Tool Message [0m=================================
Name: book_room预定成功
==================================[1m Ai Message [0m==================================您的会议室预定已经成功。预定的是Room 1,时间为明天上午10点到11点。如果有其他需要帮助的地方,请随时告诉我。

会议室预订案例2

config = {"configurable": {"thread_id": "abc1235"}}
result = agent.invoke({"messages": [{"role": "user", "content": "帮我订明天上午10点到11点1号会议室"}]},config=config
)
for m in result['messages']:m.pretty_print()
================================[1m Human Message [0m=================================帮我订明天上午10点到11点1号会议室
==================================[1m Ai Message [0m==================================
Tool Calls:get_available_rooms (call_fefded82be70420182322d)Call ID: call_fefded82be70420182322dArgs:start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
=================================[1m Tool Message [0m=================================
Name: get_available_rooms["Room 1", "Room 2"]
==================================[1m Ai Message [0m==================================明天上午10点到11点,1号会议室是可用的。您想要预订1号会议室对吗?
Tool Calls:book_room (call_4637776f50e644d0889c6d)Call ID: call_4637776f50e644d0889c6dArgs:name: Room 1start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
=================================[1m Tool Message [0m=================================
Name: book_roomBooking successful
==================================[1m Ai Message [0m==================================已成功为您预订了明天上午10点到11点的1号会议室。

会议室预订案例3

config = {"configurable": {"thread_id": "abc12345"}}
result = agent.invoke({"messages": [{"role": "user", "content": "帮我订1号会议室"}]},config=config
)
for m in result['messages']:m.pretty_print()
================================[1m Human Message [0m=================================帮我订1号会议室
==================================[1m Ai Message [0m==================================好的,我需要确认一下您希望预订1号会议室的具体时间段。请告诉我您打算从什么时候开始到什么时候结束?
config = {"configurable": {"thread_id": "abc12345"}}
result = agent.invoke({"messages": [{"role": "user", "content": "明天下午2点至4点"}]},config=config
)
for m in result['messages']:m.pretty_print()
================================[1m Human Message [0m=================================帮我订1号会议室
==================================[1m Ai Message [0m==================================好的,我需要确认一下您希望预订1号会议室的具体时间段。请告诉我您打算从什么时候开始到什么时候结束?
================================[1m Human Message [0m=================================明天下午2点至4点
==================================[1m Ai Message [0m==================================
Tool Calls:get_available_rooms (call_d817bfbe8e9d4eb49aa8e9)Call ID: call_d817bfbe8e9d4eb49aa8e9Args:start_time: 2025-02-24 14:00end_time: 2025-02-24 16:00
=================================[1m Tool Message [0m=================================
Name: get_available_rooms["Room 1", "Room 2"]
==================================[1m Ai Message [0m==================================明天下午2点到4点之间,1号会议室是可用的。在继续预订前,请确认以下信息是否正确:- 会议室:1号
- 开始时间:明天下午2点(2025年2月24日 14:00)
- 结束时间:明天下午4点(2025年2月24日 16:00)如果这些信息都正确,我将为您预订1号会议室。请回复“正确”以确认或提供修改的信息。
正确
config = {"configurable": {"thread_id": "abc12345"}}
result = agent.invoke({"messages": [{"role": "user", "content": "确认"}]},config=config
)
for m in result['messages']:m.pretty_print()
================================[1m Human Message [0m=================================帮我订1号会议室
==================================[1m Ai Message [0m==================================好的,我需要确认一下您希望预订1号会议室的具体时间段。请告诉我您打算从什么时候开始到什么时候结束?
================================[1m Human Message [0m=================================明天下午2点至4点
==================================[1m Ai Message [0m==================================
Tool Calls:get_available_rooms (call_d817bfbe8e9d4eb49aa8e9)Call ID: call_d817bfbe8e9d4eb49aa8e9Args:start_time: 2025-02-24 14:00end_time: 2025-02-24 16:00
=================================[1m Tool Message [0m=================================
Name: get_available_rooms["Room 1", "Room 2"]
==================================[1m Ai Message [0m==================================明天下午2点到4点之间,1号会议室是可用的。在继续预订前,请确认以下信息是否正确:- 会议室:1号
- 开始时间:明天下午2点(2025年2月24日 14:00)
- 结束时间:明天下午4点(2025年2月24日 16:00)如果这些信息都正确,我将为您预订1号会议室。请回复“正确”以确认或提供修改的信息。
正确
================================[1m Human Message [0m=================================确认
==================================[1m Ai Message [0m==================================
Tool Calls:book_room (call_1772161999ae43edb35d66)Call ID: call_1772161999ae43edb35d66Args:name: Room 1start_time: 2025-02-24 14:00end_time: 2025-02-24 16:00
=================================[1m Tool Message [0m=================================
Name: book_roomBooking successful
==================================[1m Ai Message [0m==================================已成功为您预订1号会议室,时间段为明天下午2点到4点。如果有任何其他需求,请告诉我。

相关文章:

使用大语言模型对接OA系统,实现会议室预定功能

随着人工智能技术的不断进步,越来越多的企业开始借助 AI 助手来提高工作效率,尤其是在日常事务的自动化处理中。比如,在许多公司里,会议室的预定是一个常见且频繁的需求,通常需要员工手动检查空闲时间并做出选择。而通…...

Ryu控制器:L2交换功能实现案例

基于 Ryu控制器 在 VM1--OVS--VM2 的简单拓扑中实现流量自动下发(流表动态安装)的完整案例。通过该案例,当VM1与VM2首次通信时,Ryu控制器会动态学习路径并下发流表,后续流量将直接由交换机转发,无需控制器介…...

动手学深度学习2025.2.23-预备知识之-线性代数

3.线性代数 (1)向量维数和张量维数的区别: (2)普通矩阵乘法: 要求左矩阵的列数等于右矩阵的行数 import torch ​ # 创建两个矩阵 A torch.tensor([[1, 2], [3, 4]], dtypetorch.float32) B torch.tensor([[5, 6], [7, 8]], d…...

登录-07.JWT令牌-登录后下发令牌

一.思路 我们首先完成令牌生成。 在响应数据这一块 该响应数据是一个标准的Result结构,其中"data"的值就是一个JWT令牌。因此我们只需要将生成的JWT令牌封装在Result当中然后返回给前端即可。 备注是给前端看的,不用管。以后我们做校验时&…...

机器学习实战(7):聚类算法——发现数据中的隐藏模式

第7集:聚类算法——发现数据中的隐藏模式 在机器学习中,聚类(Clustering) 是一种无监督学习方法,用于发现数据中的隐藏模式或分组。与分类任务不同,聚类不需要标签,而是根据数据的相似性将其划…...

【数据序列化协议】Protocol Buffers

一、为什么需要序列化? 数据跨平台/语言交互: 不同编程语言(如 Java、Python、Go)的数据结构不兼容,序列化提供统一的数据表示。例如:Java 的 HashMap 和 Python 的 dict 需转换为通用格式(如 …...

基于 Python 的电影市场预测分析系统设计与实现(源码 + 文档)

大家好,今天要和大家聊的是一款基于 Python 的“电影市场预测分析”系统的设计与实现。项目源码以及部署相关事宜请联系我,文末附上联系方式。 项目简介 基于 Python 的“电影市场预测分析”系统主要面向以下用户角色:电影制片方、电影发行…...

计算机三级网络技术知识汇总【6】

第六章 交换机及其配置 1. 交换机基础 1.1 基本概念 局域网交换机是一种基于 MAC 地址识别,完成转发数据帧功能的一种网络连接设备。 工作在数据链路层,根据进入端口数据帧中的 MAC 地址进行数据帧的过滤、转发(也是交换机的工作原理&…...

2025教育与科研领域实战全解析:DeepSeek赋能细分场景深度指南(附全流程案例与资源)

🚀 2025教育与科研领域实战全解析:DeepSeek赋能细分场景深度指南(附全流程案例与资源)🚀 📚 目录 DeepSeek在教育与科研中的核心价值教学场景应用:从备课到课堂管理的全流程革新科研场景应用:从数据分析到论文写作的智能跃迁师生协同创新:AI赋能的个性化学习与科研…...

Linux 命令大全完整版(10)

4. 压缩与解压缩命令 gzip(gnu zip) 功能说明&#xff1a;压缩文件。语  法&#xff1a;gzip [-acdfhlLnNqrtvV][-S <压缩字尾字符串>][-<压缩效率>][–best/fast][文件…] 或 gzip [-acdfhlLnNqrtvV][-S <压缩字尾字符串>][-<压缩效率>][–best/f…...

彻底卸载kubeadm安装的k8s集群

目录 一、删除资源 二、停止k8s服务 三、重置集群 四、卸载k8s安装包 五、清理残留文件和目录 六、删除k8s相关镜像 七、重启服务器 一、删除资源 # 删除集群中的所有资源&#xff0c;包括 Pod、Deployment、Service&#xff0c;任意节点执行 kubectl delete --all pod…...

vue+element-plus简洁完美实现淘宝网站模板

目录 一、项目介绍 二、项目截图 1.项目结构图 2.首页 3.详情 4.购物车 5.登陆页 三、源码实现 1.路由配置 2.依赖包 四、总结 一、项目介绍 项目在线预览&#xff1a;点击访问 本项目为vue项目&#xff0c;参考淘宝官方样式为主题来设计元素&#xff0c;简洁美观&…...

学习aigc

DALLE2 论文 Hierarchical Text-Conditional Image Generation with CLIP Latents [2204.06125] Hierarchical Text-Conditional Image Generation with CLIP LatentsAbstract page for arXiv paper 2204.06125: Hierarchical Text-Conditional Image Generation with CLIP L…...

深度学习-127-LangGraph之基础知识(四)自定义状态添加额外字段的聊天机器人

文章目录 1 自定义状态2 自定义工具2.1 完善工具human_assistance2.2 浏览器工具baidu_search3 聊天机器人3.1 绑定工具的聊天模型3.2 聊天机器人(带记忆)4 调用图4.1 调用工具时中断4.2 人工提供信息恢复4.3 查询存储的状态4.4 手动更新状态5 参考附录使用LangGraph,在状态中…...

广东英语十二种应用文模版范文

1. 邀请信&#xff08;Invitation Letter&#xff09; 模版 Dear [Recipients Name],I hope this letter finds you well. I am writing to invite you to [Event Name] which will be held on [Date] at [Location]. The event will start at [Time] and we would be deligh…...

python使用httpx_sse调用sse流式接口对响应格式为application/json的错误信息的处理

目录 问题描述方案 问题描述 调用sse流式接口使用httpx_sse的方式 import httpxfrom httpx_sse import connect_sse# 省略无关代码try:with httpx.Client() as client:with connect_sse(client, "GET", url, paramsparam) as event_source:clear_textbox(response_t…...

Leetcode-407. Trapping Rain Water II [C++][Java]

目录 一、题目描述 二、解题思路 【C】 【Java】 Leetcode-407. Trapping Rain Water IIhttps://leetcode.com/problems/trapping-rain-water-ii/description/ 一、题目描述 Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D…...

详解 torch.triu:上三角矩阵的高效构造(中英双语)

详解 torch.triu&#xff1a;上三角矩阵的高效构造 在深度学习和矩阵运算中&#xff0c;我们经常需要构造上三角矩阵&#xff08;Upper Triangular Matrix&#xff09;&#xff0c;其中主对角线以下的元素全部设为 0。PyTorch 提供了一个高效的函数 torch.triu()&#xff0c;用…...

[ TypeScript ] “undefined extends xxx“ 总是为 true 的 bug

版本号 "typescript": "^5.7.3", "unplugin": "^2.2.0",说明 在使用 unplugin 时 , 我定义插件的参数是 必填的, 使用时却是一个可空参数, 不传参也不会报错, (options?: UserOptions) > Return &#x1f632;&#x1f632;&…...

高清下载油管视频到本地

下载工具并安装: yt-dlp官网地址&#xff1a; GitHub - yt-dlp/yt-dlp: A feature-rich command-line audio/video downloader ffmpeg官网地址&#xff1a; Download FFmpeg 注&#xff1a;记住为其添加环境变量 操作命令&#xff1a; 该指令表示以720p码率下载VIDEO_UR…...

Day131 | 灵神 | 回溯算法 | 子集型 子集

Day131 | 灵神 | 回溯算法 | 子集型 子集 78.子集 78. 子集 - 力扣&#xff08;LeetCode&#xff09; 思路&#xff1a; 笔者写过很多次这道题了&#xff0c;不想写题解了&#xff0c;大家看灵神讲解吧 回溯算法套路①子集型回溯【基础算法精讲 14】_哔哩哔哩_bilibili 完…...

LeetCode - 394. 字符串解码

题目 394. 字符串解码 - 力扣&#xff08;LeetCode&#xff09; 思路 使用两个栈&#xff1a;一个存储重复次数&#xff0c;一个存储字符串 遍历输入字符串&#xff1a; 数字处理&#xff1a;遇到数字时&#xff0c;累积计算重复次数左括号处理&#xff1a;保存当前状态&a…...

拉力测试cuda pytorch 把 4070显卡拉满

import torch import timedef stress_test_gpu(matrix_size16384, duration300):"""对GPU进行压力测试&#xff0c;通过持续的矩阵乘法来最大化GPU利用率参数:matrix_size: 矩阵维度大小&#xff0c;增大可提高计算复杂度duration: 测试持续时间&#xff08;秒&…...

Typeerror: cannot read properties of undefined (reading ‘XXX‘)

最近需要在离线机器上运行软件&#xff0c;所以得把软件用docker打包起来&#xff0c;大部分功能都没问题&#xff0c;出了一个奇怪的事情。同样的代码&#xff0c;在本机上用vscode可以运行起来&#xff0c;但是打包之后在docker里出现了问题。使用的是dialog组件&#xff0c;…...

HarmonyOS运动开发:如何用mpchart绘制运动配速图表

##鸿蒙核心技术##运动开发##Sensor Service Kit&#xff08;传感器服务&#xff09;# 前言 在运动类应用中&#xff0c;运动数据的可视化是提升用户体验的重要环节。通过直观的图表展示运动过程中的关键数据&#xff0c;如配速、距离、卡路里消耗等&#xff0c;用户可以更清晰…...

音视频——I2S 协议详解

I2S 协议详解 I2S (Inter-IC Sound) 协议是一种串行总线协议&#xff0c;专门用于在数字音频设备之间传输数字音频数据。它由飞利浦&#xff08;Philips&#xff09;公司开发&#xff0c;以其简单、高效和广泛的兼容性而闻名。 1. 信号线 I2S 协议通常使用三根或四根信号线&a…...

STM32---外部32.768K晶振(LSE)无法起振问题

晶振是否起振主要就检查两个1、晶振与MCU是否兼容&#xff1b;2、晶振的负载电容是否匹配 目录 一、判断晶振与MCU是否兼容 二、判断负载电容是否匹配 1. 晶振负载电容&#xff08;CL&#xff09;与匹配电容&#xff08;CL1、CL2&#xff09;的关系 2. 如何选择 CL1 和 CL…...

API网关Kong的鉴权与限流:高并发场景下的核心实践

&#x1f525;「炎码工坊」技术弹药已装填&#xff01; 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 引言 在微服务架构中&#xff0c;API网关承担着流量调度、安全防护和协议转换的核心职责。作为云原生时代的代表性网关&#xff0c;Kong凭借其插件化架构…...

【安全篇】金刚不坏之身:整合 Spring Security + JWT 实现无状态认证与授权

摘要 本文是《Spring Boot 实战派》系列的第四篇。我们将直面所有 Web 应用都无法回避的核心问题&#xff1a;安全。文章将详细阐述认证&#xff08;Authentication) 与授权&#xff08;Authorization的核心概念&#xff0c;对比传统 Session-Cookie 与现代 JWT&#xff08;JS…...

6.9-QT模拟计算器

源码: 头文件: widget.h #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QMouseEvent>QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACEclass Widget : public QWidget {Q_OBJECTpublic:Widget(QWidget *parent nullptr);…...