langchain 实现多智能体多轮对话

这里写目录标题

    • 工具定义
    • 模型选择
    • graph节点函数定义
    • graph 运行

工具定义

import random
from typing import Annotated, Literalfrom langchain_core.tools import tool
from langchain_core.tools.base import InjectedToolCallId
from langgraph.prebuilt import InjectedState
from langgraph.types import Command@tool
def get_travel_recommendations():"""Get recommendation for travel destinations"""return random.choice(["aruba", "turks and caicos"])@tool
def get_hotel_recommendations(location: Literal["aruba", "turks and caicos"]):"""Get hotel recommendations for a given destination."""return {"aruba": ["The Ritz-Carlton, Aruba (Palm Beach)""Bucuti & Tara Beach Resort (Eagle Beach)"],"turks and caicos": ["Grace Bay Club", "COMO Parrot Cay"],}[location]def make_handoff_tool(*, agent_name: str):"""Create a tool that can return handoff via a Command"""tool_name = f"transfer_to_{agent_name}"@tool(tool_name)def handoff_to_agent(state: Annotated[dict, InjectedState],tool_call_id: Annotated[str, InjectedToolCallId],):"""Ask another agent for help."""tool_message = {"role": "tool","content": f"Successfully transferred to {agent_name}","name": tool_name,"tool_call_id": tool_call_id,}return Command(# navigate to another agent node in the PARENT graphgoto=agent_name,graph=Command.PARENT,# This is the state update that the agent `agent_name` will see when it is invoked.# We're passing agent's FULL internal message history AND adding a tool message to make sure# the resulting chat history is valid.update={"messages": state["messages"] + [tool_message]},)return handoff_to_agent

模型选择

from langchain_openai import ChatOpenAI
model = ChatOpenAI(temperature=0,model="GLM-4-PLUS",openai_api_key="your api key",openai_api_base="https://open.bigmodel.cn/api/paas/v4/"
)

graph节点函数定义

from langgraph.graph import MessagesState, StateGraph, START
from langgraph.prebuilt import create_react_agent, InjectedState
from langgraph.types import Command, interrupt
from langgraph.checkpoint.memory import MemorySaver# Define travel advisor tools and ReAct agent
travel_advisor_tools = [get_travel_recommendations,make_handoff_tool(agent_name="hotel_advisor"),
]
travel_advisor = create_react_agent(model,travel_advisor_tools,prompt=("You are a general travel expert that can recommend travel destinations (e.g. countries, cities, etc). ""If you need hotel recommendations, ask 'hotel_advisor' for help. ""You MUST include human-readable response before transferring to another agent."),
)def call_travel_advisor(state: MessagesState,
) -> Command[Literal["hotel_advisor", "human"]]:# You can also add additional logic like changing the input to the agent / output from the agent, etc.# NOTE: we're invoking the ReAct agent with the full history of messages in the stateresponse = travel_advisor.invoke(state)return Command(update=response, goto="human")# Define hotel advisor tools and ReAct agent
hotel_advisor_tools = [get_hotel_recommendations,make_handoff_tool(agent_name="travel_advisor"),
]
hotel_advisor = create_react_agent(model,hotel_advisor_tools,prompt=("You are a hotel expert that can provide hotel recommendations for a given destination. ""If you need help picking travel destinations, ask 'travel_advisor' for help.""You MUST include human-readable response before transferring to another agent."),
)def call_hotel_advisor(state: MessagesState,
) -> Command[Literal["travel_advisor", "human"]]:response = hotel_advisor.invoke(state)return Command(update=response, goto="human")def human_node(state: MessagesState, config
) -> Command[Literal["hotel_advisor", "travel_advisor", "human"]]:"""A node for collecting user input."""user_input = input("Ready for user input.")# identify the last active agent# (the last active node before returning to human)langgraph_triggers = config["metadata"]["langgraph_triggers"]if len(langgraph_triggers) != 1:raise AssertionError("Expected exactly 1 trigger in human node")active_agent = langgraph_triggers[0].split(":")[1]return Command(update={"messages": [{"role": "human","content": user_input,}]},goto=active_agent,)builder = StateGraph(MessagesState)
builder.add_node("travel_advisor", call_travel_advisor)
builder.add_node("hotel_advisor", call_hotel_advisor)# This adds a node to collect human input, which will route
# back to the active agent.
builder.add_node("human", human_node)# We'll always start with a general travel advisor.
builder.add_edge(START, "travel_advisor")checkpointer = MemorySaver()
graph = builder.compile(checkpointer=checkpointer)

Graph可视化

from IPython.display import display, Imagedisplay(Image(graph.get_graph().draw_mermaid_png()))

在这里插入图片描述

graph 运行

import uuidthread_config = {"configurable": {"thread_id": uuid.uuid4()}}user_input = {"messages": [{"role": "user", "content": "i wanna go somewhere warm in the caribbean"}]}for update in graph.stream(user_input,config=thread_config,stream_mode="updates",):for node_id, value in update.items():print(f"{node_id}: {value}")
travel_advisor: {'messages': [HumanMessage(content='i wanna go somewhere warm in the caribbean', additional_kwargs={}, response_metadata={}, id='b7a9d8a8-f569-464a-8942-c98f477b8ce2'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_-9024507181658326780', 'function': {'arguments': '{}', 'name': 'get_travel_recommendations'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 7, 'prompt_tokens': 203, 'total_tokens': 210, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-9ed5c54c-2540-41d2-9704-769075778a98-0', tool_calls=[{'name': 'get_travel_recommendations', 'args': {}, 'id': 'call_-9024507181658326780', 'type': 'tool_call'}], usage_metadata={'input_tokens': 203, 'output_tokens': 7, 'total_tokens': 210, 'input_token_details': {}, 'output_token_details': {}}), ToolMessage(content='turks and caicos', name='get_travel_recommendations', id='9dbe9001-1341-40fd-a431-b391bcfab0d8', tool_call_id='call_-9024507181658326780'), AIMessage(content="For a warm getaway in the Caribbean, I recommend visiting Turks and Caicos. It's known for its beautiful beaches and pleasant climate. Would you like hotel recommendations for Turks and Caicos? If so, I can ask the hotel advisor for assistance.", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 52, 'prompt_tokens': 217, 'total_tokens': 269, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-aed9c540-eb16-4782-8dc2-aae47932df30-0', usage_metadata={'input_tokens': 217, 'output_tokens': 52, 'total_tokens': 269, 'input_token_details': {}, 'output_token_details': {}})]}
human: {'messages': [{'role': 'human', 'content': 'hotel recommendation'}]}
travel_advisor: {'messages': [HumanMessage(content='i wanna go somewhere warm in the caribbean', additional_kwargs={}, response_metadata={}, id='b7a9d8a8-f569-464a-8942-c98f477b8ce2'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_-9024507181658326780', 'function': {'arguments': '{}', 'name': 'get_travel_recommendations'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 7, 'prompt_tokens': 203, 'total_tokens': 210, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-9ed5c54c-2540-41d2-9704-769075778a98-0', tool_calls=[{'name': 'get_travel_recommendations', 'args': {}, 'id': 'call_-9024507181658326780', 'type': 'tool_call'}], usage_metadata={'input_tokens': 203, 'output_tokens': 7, 'total_tokens': 210, 'input_token_details': {}, 'output_token_details': {}}), ToolMessage(content='turks and caicos', name='get_travel_recommendations', id='9dbe9001-1341-40fd-a431-b391bcfab0d8', tool_call_id='call_-9024507181658326780'), AIMessage(content="For a warm getaway in the Caribbean, I recommend visiting Turks and Caicos. It's known for its beautiful beaches and pleasant climate. Would you like hotel recommendations for Turks and Caicos? If so, I can ask the hotel advisor for assistance.", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 52, 'prompt_tokens': 217, 'total_tokens': 269, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-aed9c540-eb16-4782-8dc2-aae47932df30-0', usage_metadata={'input_tokens': 217, 'output_tokens': 52, 'total_tokens': 269, 'input_token_details': {}, 'output_token_details': {}}), HumanMessage(content='hotel recommendation', additional_kwargs={}, response_metadata={}, id='931caa5f-a5c7-4c4c-991a-d7e3843c7aa6'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_-9024511201749198020', 'function': {'arguments': '{}', 'name': 'transfer_to_hotel_advisor'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 273, 'total_tokens': 282, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-92da714d-1d8c-4a96-b6c8-3b0d2ac916c6-0', tool_calls=[{'name': 'transfer_to_hotel_advisor', 'args': {}, 'id': 'call_-9024511201749198020', 'type': 'tool_call'}], usage_metadata={'input_tokens': 273, 'output_tokens': 9, 'total_tokens': 282, 'input_token_details': {}, 'output_token_details': {}}), {'role': 'tool', 'content': 'Successfully transferred to hotel_advisor', 'name': 'transfer_to_hotel_advisor', 'tool_call_id': 'call_-9024511201749198020'}]}
hotel_advisor: {'messages': [HumanMessage(content='i wanna go somewhere warm in the caribbean', additional_kwargs={}, response_metadata={}, id='b7a9d8a8-f569-464a-8942-c98f477b8ce2'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_-9024507181658326780', 'function': {'arguments': '{}', 'name': 'get_travel_recommendations'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 7, 'prompt_tokens': 203, 'total_tokens': 210, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-9ed5c54c-2540-41d2-9704-769075778a98-0', tool_calls=[{'name': 'get_travel_recommendations', 'args': {}, 'id': 'call_-9024507181658326780', 'type': 'tool_call'}], usage_metadata={'input_tokens': 203, 'output_tokens': 7, 'total_tokens': 210, 'input_token_details': {}, 'output_token_details': {}}), ToolMessage(content='turks and caicos', name='get_travel_recommendations', id='9dbe9001-1341-40fd-a431-b391bcfab0d8', tool_call_id='call_-9024507181658326780'), AIMessage(content="For a warm getaway in the Caribbean, I recommend visiting Turks and Caicos. It's known for its beautiful beaches and pleasant climate. Would you like hotel recommendations for Turks and Caicos? If so, I can ask the hotel advisor for assistance.", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 52, 'prompt_tokens': 217, 'total_tokens': 269, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-aed9c540-eb16-4782-8dc2-aae47932df30-0', usage_metadata={'input_tokens': 217, 'output_tokens': 52, 'total_tokens': 269, 'input_token_details': {}, 'output_token_details': {}}), HumanMessage(content='hotel recommendation', additional_kwargs={}, response_metadata={}, id='931caa5f-a5c7-4c4c-991a-d7e3843c7aa6'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_-9024511201749198020', 'function': {'arguments': '{}', 'name': 'transfer_to_hotel_advisor'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 273, 'total_tokens': 282, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-92da714d-1d8c-4a96-b6c8-3b0d2ac916c6-0', tool_calls=[{'name': 'transfer_to_hotel_advisor', 'args': {}, 'id': 'call_-9024511201749198020', 'type': 'tool_call'}], usage_metadata={'input_tokens': 273, 'output_tokens': 9, 'total_tokens': 282, 'input_token_details': {}, 'output_token_details': {}}), ToolMessage(content='Successfully transferred to hotel_advisor', name='transfer_to_hotel_advisor', id='ce44c5c6-0fa4-4d7e-9452-60399000e83f', tool_call_id='call_-9024511201749198020'), AIMessage(content="I've transferred your request to the hotel advisor who will provide you with hotel recommendations for Turks and Caicos. They will assist you in finding the perfect accommodation for your warm Caribbean getaway.", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 39, 'prompt_tokens': 334, 'total_tokens': 373, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-08b49c36-2726-4935-bf7e-ed6149d03f00-0', usage_metadata={'input_tokens': 334, 'output_tokens': 39, 'total_tokens': 373, 'input_token_details': {}, 'output_token_details': {}})]}
human: {'messages': [{'role': 'human', 'content': 'Well, give me some hotel recom'}]}
hotel_advisor: {'messages': [HumanMessage(content='i wanna go somewhere warm in the caribbean', additional_kwargs={}, response_metadata={}, id='b7a9d8a8-f569-464a-8942-c98f477b8ce2'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_-9024507181658326780', 'function': {'arguments': '{}', 'name': 'get_travel_recommendations'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 7, 'prompt_tokens': 203, 'total_tokens': 210, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-9ed5c54c-2540-41d2-9704-769075778a98-0', tool_calls=[{'name': 'get_travel_recommendations', 'args': {}, 'id': 'call_-9024507181658326780', 'type': 'tool_call'}], usage_metadata={'input_tokens': 203, 'output_tokens': 7, 'total_tokens': 210, 'input_token_details': {}, 'output_token_details': {}}), ToolMessage(content='turks and caicos', name='get_travel_recommendations', id='9dbe9001-1341-40fd-a431-b391bcfab0d8', tool_call_id='call_-9024507181658326780'), AIMessage(content="For a warm getaway in the Caribbean, I recommend visiting Turks and Caicos. It's known for its beautiful beaches and pleasant climate. Would you like hotel recommendations for Turks and Caicos? If so, I can ask the hotel advisor for assistance.", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 52, 'prompt_tokens': 217, 'total_tokens': 269, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-aed9c540-eb16-4782-8dc2-aae47932df30-0', usage_metadata={'input_tokens': 217, 'output_tokens': 52, 'total_tokens': 269, 'input_token_details': {}, 'output_token_details': {}}), HumanMessage(content='hotel recommendation', additional_kwargs={}, response_metadata={}, id='931caa5f-a5c7-4c4c-991a-d7e3843c7aa6'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_-9024511201749198020', 'function': {'arguments': '{}', 'name': 'transfer_to_hotel_advisor'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 273, 'total_tokens': 282, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-92da714d-1d8c-4a96-b6c8-3b0d2ac916c6-0', tool_calls=[{'name': 'transfer_to_hotel_advisor', 'args': {}, 'id': 'call_-9024511201749198020', 'type': 'tool_call'}], usage_metadata={'input_tokens': 273, 'output_tokens': 9, 'total_tokens': 282, 'input_token_details': {}, 'output_token_details': {}}), ToolMessage(content='Successfully transferred to hotel_advisor', name='transfer_to_hotel_advisor', id='ce44c5c6-0fa4-4d7e-9452-60399000e83f', tool_call_id='call_-9024511201749198020'), AIMessage(content="I've transferred your request to the hotel advisor who will provide you with hotel recommendations for Turks and Caicos. They will assist you in finding the perfect accommodation for your warm Caribbean getaway.", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 39, 'prompt_tokens': 334, 'total_tokens': 373, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-08b49c36-2726-4935-bf7e-ed6149d03f00-0', usage_metadata={'input_tokens': 334, 'output_tokens': 39, 'total_tokens': 373, 'input_token_details': {}, 'output_token_details': {}}), HumanMessage(content='Well, give me some hotel recom', additional_kwargs={}, response_metadata={}, id='8a6d6e7f-5d26-4c77-aa7c-95485581e7e4'), AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_-9024517077266482785', 'function': {'arguments': '{"location": "turks and caicos"}', 'name': 'get_hotel_recommendations'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 17, 'prompt_tokens': 382, 'total_tokens': 399, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-b072e101-db1e-4809-b87d-d767df0e9f10-0', tool_calls=[{'name': 'get_hotel_recommendations', 'args': {'location': 'turks and caicos'}, 'id': 'call_-9024517077266482785', 'type': 'tool_call'}], usage_metadata={'input_tokens': 382, 'output_tokens': 17, 'total_tokens': 399, 'input_token_details': {}, 'output_token_details': {}}), ToolMessage(content='["Grace Bay Club", "COMO Parrot Cay"]', name='get_hotel_recommendations', id='45cc7ee3-9d7e-4df5-aacc-914878812d5b', tool_call_id='call_-9024517077266482785'), AIMessage(content='Here are some hotel recommendations for Turks and Caicos:\n\n1. Grace Bay Club\n2. COMO Parrot Cay\n\nThese hotels are known for their excellent amenities and beautiful locations. Enjoy your stay in Turks and Caicos!', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 48, 'prompt_tokens': 413, 'total_tokens': 461, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'GLM-4-PLUS', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-76dc546c-5272-48cc-ae1b-63437bf6051f-0', usage_metadata={'input_tokens': 413, 'output_tokens': 48, 'total_tokens': 461, 'input_token_details': {}, 'output_token_details': {}})]}
human: {'messages': [{'role': 'human', 'content': ''}]}

参考链接:https://langchain-ai.github.io/langgraph/how-tos/multi-agent-multi-turn-convo-functional/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/69817.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Block总结】CPCA,通道优先卷积注意力|即插即用

论文信息 标题: Channel Prior Convolutional Attention for Medical Image Segmentation 论文链接: arxiv.org 代码链接: GitHub 创新点 本文提出了一种新的通道优先卷积注意力(CPCA)机制,旨在解决医学图像分割中存在的低对比度和显著…

Python从零构建macOS状态栏应用(仿ollama)并集成AI同款流式聊天 API 服务(含打包为独立应用)

在本教程中,我们将一步步构建一个 macOS 状态栏应用程序,并集成一个 Flask 服务器,提供流式响应的 API 服务。 如果你手中正好持有一台 MacBook Pro,又怀揣着搭建 AI 聊天服务的想法,却不知从何处迈出第一步,那么这篇文章绝对是你的及时雨。 最终,我们将实现以下功能: …

强化学习、深度学习、深度强化学习的区别是什么?

前言 深度强化学习就是 深度学习 和 强化学习 的结合体。它让计算机程序(也就是智能体)在特定环境中不断尝试,从错误中学习,最终找到最优的行动策略。 深度学习是AlphaGo从棋谱里学习,强化学些Alphazero 学习规则&am…

string类(详解)

为什么学习string类? 1.1 C语言中的字符串 C语言中,字符串是以\0结尾的一些字符的集合,为了操作方便,C标准库中提供了一些str系列的库函数,但是这些库函数与字符串是分离开的,不太符合OOP的思想&#xf…

【Redis】set 和 zset 类型的介绍和常用命令

1. set 1.1 介绍 set 类型和 list 不同的是,存储的元素是无序的,并且元素不允许重复,Redis 除了支持集合内的增删查改操作,还支持多个集合取交集,并集,差集 1.2 常用命令 命令 介绍 时间复杂度 sadd …

一些计算机零碎知识随写(25年2月)

今天复习 MySQL 的时候,我突然冒出一个想法:能不能远程连接 MySQL 呢?虽说心里清楚理论上可行,但一直没实际操作过。 于是,起床后我立马打开服务器,准备启动 MySQL。结果,这一启动就发现问题了&…

ESP32-c3实现获取土壤湿度(ADC模拟量)

1硬件实物图 2引脚定义 3使用说明 4实例代码 // 定义土壤湿度传感器连接的模拟输入引脚 const int soilMoisturePin 2; // 假设连接到GPIO2void setup() {// 初始化串口通信Serial.begin(115200); }void loop() {// 读取土壤湿度传感器的模拟值int sensorValue analogRead…

Java 大视界 -- Java 大数据在量子通信安全中的应用探索(69)

💖亲爱的朋友们,热烈欢迎来到 青云交的博客!能与诸位在此相逢,我倍感荣幸。在这飞速更迭的时代,我们都渴望一方心灵净土,而 我的博客 正是这样温暖的所在。这里为你呈上趣味与实用兼具的知识,也…

86.(2)攻防世界 WEB PHP2

之前做过&#xff0c;回顾一遍&#xff0c;详解见下面这篇博客 29.攻防世界PHP2-CSDN博客 既然是代码审计题目&#xff0c;打开后又不显示代码&#xff0c;肯定在文件里 <?php // 首先检查通过 GET 请求传递的名为 "id" 的参数值是否严格等于字符串 "admi…

从理论到实践:Linux 进程替换与 exec 系列函数

个人主页&#xff1a;chian-ocean 文章专栏-Linux 前言&#xff1a; 在Linux中&#xff0c;进程替换&#xff08;Process Substitution&#xff09;是一个非常强大的特性&#xff0c;它允许将一个进程的输出直接当作一个文件来处理。这种技术通常用于Shell脚本和命令行操作中…

【数据结构】初识链表

顺序表的优缺点 缺点&#xff1a; 中间/头部的插入删除&#xff0c;时间复杂度效率较低&#xff0c;为O(N) 空间不够的时候需要扩容。 如果是异地扩容&#xff0c;增容需要申请新空间&#xff0c;拷贝数据&#xff0c;释放旧空间&#xff0c;会有不小的消耗。 扩容可能会存在…

增删改查(CRUD)操作

文章目录 MySQL系列&#xff1a;1.CRUD简介2.Create(创建)2.1单行数据全列插入2.2 单行数据指定插入2.3 多⾏数据指定列插⼊ 3.Retrieve(读取)3.1 Select查询3.1.1 全列查询3.1.2 指定列查询3.1.3 查询字段为表达式&#xff08;都是临时表不会对原有表数据产生影响&#xff09;…

使用Pygame制作“贪吃蛇”游戏

贪吃蛇 是一款经典的休闲小游戏&#xff1a;玩家通过操控一条会不断变长的“蛇”在屏幕中移动&#xff0c;去吃随机出现的食物&#xff0c;同时要避免撞到墙壁或自己身体的其他部分。由于其逻辑相对简单&#xff0c;但可玩性和扩展性都不错&#xff0c;非常适合作为新手练习游戏…

JavaScript闭包深入剖析:性能剖析与优化技巧

一、引言 在 JavaScript 的奇妙世界里&#xff0c;闭包无疑是一个既强大又迷人的特性。它就像是一把万能钥匙&#xff0c;为开发者打开了实现各种高级功能的大门。从数据封装与保护&#xff0c;到函数的记忆化&#xff0c;再到模块化开发&#xff0c;闭包都发挥着举足轻重的作…

蓝桥杯嵌入式赛道备考1 —— 基础GPIO实战

1. 点亮一个LED 蓝桥杯的板子资料的URL&#xff0c;笔者是从GitHub - JoyRiderJie/LanQiaoBei-QianRuShi拉去下来的。这个是Github仓库地址。 从应用层去玩一个开发板子&#xff0c;首先需要的是去尝试是点亮一个LED。让我们切换到手册《CT117E——产品手册》的第11页&#x…

浅析DNS污染及防范

DNS污染&#xff08;DNS Cache Poisoning&#xff09;是一种网络攻击手段&#xff0c;通过篡改DNS服务器的缓存数据&#xff0c;将域名解析结果指向错误的IP地址&#xff0c;从而误导用户访问恶意网站或无法访问目标网站。这种攻击利用了DNS协议的特性&#xff0c;例如“只认第…

AI编程:如何编写提示词

这是小卷对AI编程工具学习的第2篇文章&#xff0c;今天讲讲如何编写AI编程的提示词&#xff0c;并结合实际功能需求案例来进行开发 1.编写提示词的技巧 好的提示词应该是&#xff1a;目标清晰明确&#xff0c;具有针对性&#xff0c;能引导模型理解问题 下面是两条提示词的对…

linux asio网络编程理论及实现

最近在B站看了恋恋风辰大佬的asio网络编程&#xff0c;质量非常高。在本章中将对ASIO异步网络编程的整体及一些实现细节进行完整的梳理&#xff0c;用于复习与分享。大佬的博客&#xff1a;恋恋风辰官方博客 Preactor/Reactor模式 在网络编程中&#xff0c;通常根据事件处理的触…

【思维导图】并发编程

学习计划&#xff1a;将目前已经学的知识点串成一个思维导图。在往后的学习过程中&#xff0c;不断往思维导图里补充&#xff0c;形成自己整个知识体系。对于思维导图里的每个技术知识&#xff0c;自己用简洁的话概括出来&#xff0c; 训练自己的表达能力。 并发和并行的区别 并…

【B站保姆级视频教程:Jetson配置YOLOv11环境(四)cuda cudnn tensorrt配置】

Jetson配置YOLOv11环境&#xff08;4&#xff09;cuda cudnn tensorrt配置 文章目录 0. 简介1. cuda配置&#xff1a;添加cuda环境变量2. cudnn配置3. TensorRT Python环境配置3.1 系统自带Python环境中的TensorRT配置3.2 Conda 虚拟Python环境中的TensorRT配置 0. 简介 官方镜…