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

杭州高瑞网站建设百度竞价开户哪家好

杭州高瑞网站建设,百度竞价开户哪家好,做门户网站多少钱,网站开发语言太老1. 导入必要的库 首先,我们需要导入所需的库。这里我们使用 langchain_openai 来与 智谱AI 模型进行交互,并使用 langchain_core.tools 来定义自定义工具。 from langchain_openai import ChatOpenAI from typing import Literal from langchain_core.…

1. 导入必要的库

首先,我们需要导入所需的库。这里我们使用 langchain_openai 来与 智谱AI 模型进行交互,并使用 langchain_core.tools 来定义自定义工具。

from langchain_openai import ChatOpenAI
from typing import Literal
from langchain_core.tools import tool

2. 初始化 智谱AI 模型

接下来,我们初始化 智谱AI 模型。这里需要指定模型的参数,包括温度、模型名称、API 密钥和 API 基地址。

model = ChatOpenAI(temperature=0,model="glm-4-plus",openai_api_key="your_api_key",openai_api_base="https://open.bigmodel.cn/api/paas/v4/"
)

3. 定义自定义工具

我们定义一个获取天气信息的工具 get_weather,该工具接受一个城市名称作为参数,并返回相应的天气信息。

@tool
def get_weather(city: Literal["nyc", "sf"]):"""Use this to get weather information."""if city == "nyc":return "It might be cloudy in nyc"elif city == "sf":return "It's always sunny in sf"else:raise AssertionError("Unknown city")

4. 创建工具列表

将定义好的工具添加到工具列表中。

tools = [get_weather]

5. 初始化记忆存储

使用 MemorySaver 来存储对话过程中的状态。

from langgraph.checkpoint.memory import MemorySavermemory = MemorySaver()

6. 创建反应式代理

使用 create_react_agent 函数创建一个反应式代理,该代理将模型和工具结合在一起。

from langgraph.prebuilt import create_react_agentgraph = create_react_agent(model, tools=tools, checkpointer=memory)

7. 定义打印流函数

为了更好地展示对话过程,我们定义一个 print_stream 函数,用于打印流式输出的消息。

def print_stream(stream):for s in stream:message = s["messages"][-1]if isinstance(message, tuple):print(message)else:message.pretty_print()

8. 发送查询并打印结果

配置输入参数,并发送查询请求,最后打印结果。

config = {"configurable": {"thread_id": "1"}}
inputs = {"messages": [("user", "What's the weather in NYC?")]}print_stream(graph.stream(inputs, config=config, stream_mode="values"))

输出结果如下:

==============================[1m Human Message [0m=================================What's the weather in NYC?
================================[1m Ai Message [0m==================================
Tool Calls:get_weather (call_9208192282885233822)Call ID: call_9208192282885233822Args:city: nyc
================================[1m Tool Message [0m=================================
Name: get_weatherIt might be cloudy in nyc
================================[1m Ai Message [0m==================================It might be cloudy in NYC.

9. 发送另一个查询并打印结果

再次配置输入参数,发送新的查询请求,并打印结果。

inputs = {"messages": [("user", "What's it known for?")]}
print_stream(graph.stream(inputs, config=config, stream_mode="values"))

输出结果如下:

==============================[1m Human Message [0m=================================What's it known for?
================================[1m Ai Message [0m==================================New York City is known for a multitude of things, making it one of the most iconic and influential cities in the world. Here are some highlights:1. **Statue of Liberty**: A symbol of freedom and democracy, this iconic statue is located on Liberty Island.2. **Central Park**: An expansive urban park in the heart of Manhattan, known for its lush landscapes, recreational activities, and cultural events.3. **Broadway**: The pinnacle of American theater, Broadway is famous for its high-quality performances and historic theaters.4. **Times Square**: A bustling commercial intersection known for its bright lights, massive digital billboards, and the annual New Year's Eve ball drop.5. **Empire State Building**: An Art Deco skyscraper that once held the title of the world's tallest building and remains a symbol of New York's skyline.6. **Museums and Art**: Home to world-renowned institutions like the Metropolitan Museum of Art, the Museum of Modern Art (MoMA), and the Guggenheim.7. **Diverse Cuisine**: Reflecting its status as a melting pot, NYC offers an incredible variety of global cuisines.8. **Financial Hub**: Wall Street and the New York Stock Exchange are central to the global economy.9. **Fashion Capital**: Known for its influence on global fashion trends, hosting events like New York Fashion Week.10. **Cultural Diversity**: A city of immigrants, NYC boasts a rich tapestry of cultures, languages, and traditions.These are just a few aspects that contribute to NYC's global reputation and appeal.

参考链接:https://langchain-ai.github.io/langgraph/how-tos/create-react-agent-memory/

http://www.15wanjia.com/news/26672.html

相关文章:

  • 南宁手机做网站公司app拉新推广平台代理
  • 网站集约化建设必要性热搜榜排名前十
  • wordpress 党建模板关键词优化难度分析
  • 平阳住房和城乡规划建设局网站常见的网络营销工具
  • 法院网站建设爱站网关键词搜索
  • wordpress能用的插件合肥优化
  • 建一个网站大约需要花费多少钱宝塔建站系统
  • 上海门户网保定seo推广公司
  • html5做简单网站舆情报告
  • 免费网站可以做淘宝客吗宁国网络推广
  • 建设一个视频网站需要什么条件正规的计算机培训机构
  • 做外卖网站网站推广优化外包便宜
  • 精美网站欣赏爱站网seo
  • 河南省建设注册执业中心网站广告宣传网站
  • 道教佛像网站怎么做seo标题生成器
  • 网页和网站区别seo交互论坛
  • 网页游戏4399在线游戏安徽seo报价
  • 福田建网站公司南宁seo外包要求
  • 微网罗湖区seo排名
  • 如何取一个大气的名字的做网站网页设计与制作模板
  • 怎么做电脑端网站设计稿优化设计电子版在哪找
  • 山东淄博微信网站制作建站系统有哪些
  • 专注于上海seo做网站建设搜索引擎排名优化程序
  • 网站转换模块怎么做排名软件
  • wordpress的插件seo技术培训东莞
  • 怎么设置网站国外服务器免费ip地址
  • 潜江招聘网网站关键词排名怎么优化
  • 外包网站开发重庆seo网络优化师
  • 自己做的网站怎么搜不到长沙网站外包公司
  • 烟台外贸网站建设潍坊seo招聘