当前位置: 首页 > 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.zhongyajixie.com/news/28203.html

相关文章:

  • 免费微信建站有哪些网站湖南专业的关键词优化
  • 网站建设seo 视频游戏代理怎么找渠道
  • 做视频网站需要什么架构宁波seo网站排名
  • 大连网络备案做网站汕头网站推广
  • 花都网站制作公司影视剪辑培训机构排名
  • 芜湖网站建设怎么做家电企业网站推广方案
  • 平面设计专业网站郑州优化公司有哪些
  • o2o信息类平台有哪些昆明seo排名外包
  • 手机和wap网站建设网店代运营一年的费用是多少
  • 一般网站图标是用什么做的武汉关键词排名推广
  • 网站备案名字要怎么写大连网络推广公司哪家好
  • 福建个人网站备案做直销去哪里找客户
  • 什么网站做教育的比较多新闻最近的大事10件
  • 北京做网站设计招聘新软件推广
  • 做哪种网站比较简单网站网络推广服务
  • 河北石家庄建设信息网网站优化seo推广服务
  • 如何给网站做关键字百度seo霸屏软件
  • 企业做响应式网站好吗中国搜索引擎大全
  • 手机商城网站免费建站百度关键词怎么刷上去
  • app案例网站免费推广引流平台有哪些
  • 高端定制网站开发需要多少钱新闻稿
  • wordpress 技术分析手机优化软件下载
  • 中国石油工程建设有限公司网站外贸推广方式都有哪些
  • 大气的个人网站怎样在百度做广告宣传
  • 网站怎么做qq登录电商营销策略
  • 国外免费个人网站空间宣传软文是什么意思
  • 辽宁天一建设有限责任公司网站2021最火营销方案
  • 那个公司可以做网站网店推广有哪些
  • 九尾狐建站网址2345网址导航下载桌面
  • 网站报纸什么软件做推广软件赚钱违法吗