上文我们创建了一个langchain 链,这篇文章中我们承接上面的逻辑,来生成一个智能体,所谓的智能体是langchain的组件,用来告诉大模型需要做什么事。 首先我们构建一个检索器
from langchain.tools.retriever import create_retriever_tool
retriever_tool = create_retriever_tool(
retriever,
"langsmith_search",
"Search for information about LangSmith. For any questions about LangSmith, you must use this tool!",
)
我们使用Tavily检索工具,注册后需要配置环境变量(也可以省略注册,不配置api key)
export TAVILY_API_KEY=...
from langchain_community.tools.tavily_search import TavilySearchResults
search = TavilySearchResults()
构建一个工具列表
tools = [retriever_tool, search]
安装langchain hub和langchain openapi依赖
pip install langchainhub
pip install langchain-openai
现在我们构建一个预定义的提示词
from langchain_openai import ChatOpenAI
from langchain import hub
from langchain.agents import create_openai_functions_agent
from langchain.agents import AgentExecutor
# Get the prompt to use - you can modify this!
prompt = hub.pull("hwchase17/openai-functions-agent")
# You need to set OPENAI_API_KEY environment variable or pass it as argument `api_key`.
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
agent_executor.invoke({"input": "what is the weather in beijing?"})
执行后输出
> Entering new AgentExecutor chain...
Invoking: `tavily_search_results_json` with `{'query': 'weather in Beijing'}`
[{'url': 'https://www.weatherapi.com/', 'content': "{'location': {'name': 'Beijing', 'region': 'Beijing', 'country': 'China', 'lat': 39.93, 'lon': 116.39, 'tz_id': 'Asia/Shanghai', 'localtime_epoch': 1715825219, 'localtime': '2024-05-16 10:06'}, 'current': {'last_updated_epoch': 1715824800, 'last_updated': '2024-05-16 10:00', 'temp_c': 21.0, 'temp_f': 69.8, 'is_day': 1, 'condition': {'text': 'Sunny', 'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png', 'code': 1000}, 'wind_mph': 2.2, 'wind_kph': 3.6, 'wind_degree': 252, 'wind_dir': 'WSW', 'pressure_mb': 1009.0, 'pressure_in': 29.8, 'precip_mm': 0.0, 'precip_in': 0.0, 'humidity': 31, 'cloud': 0, 'feelslike_c': 21.0, 'feelslike_f': 69.8, 'vis_km': 10.0, 'vis_miles': 6.0, 'uv': 6.0, 'gust_mph': 6.7, 'gust_kph': 10.8}}"}, {'url': 'https://www.weatherandclimate.info/monitor/54511', 'content': 'The table shows the main characteristics of weather in Beijing - air temperature and precipitation shown for each day of may 2024. Monthly mean temperature normal for May: 21.3°. Monthly mean temperature in this month: 20.9°. Departure of temperature from normal: +1.1°. Precipitation normal for May: 36 mm. Precipitation total in this month ...'}, {'url': 'https://www.whereandwhen.net/when/east-asia/china/beijing/may/', 'content': 'Average weather throughout may\nperfect weather\nUV index: 7\nClear/Sunny62% of time\n62%\n24%\n7%\n7%\nClear/Sunny63% of time\n63%\n26%\n4%\n4%\nClear/Sunny60% of time\n60%\n22%\n8%\n7%\n65%\n20%\n8%\n6%\nEvolution of daily average temperature and precipitation in Beijing in may\nThese charts show the evolution of average minimum/maximum temperatures as well as average daily precipitation volume in Beijing in may.\n Find a flight to China:\nFind the best price for your hotel room\nFind the best price for your car rental\nSearch for a Flight+Hotel package to China in may\nSeasonal average climate and temperature of Beijing in may\nCheck below seasonal norms These datas are set from the weather statements of the last years of the month of may.\n Here is the day by day recorded weather in Beijing in may 2023:\nMap: other cities in China in may\nCities near Beijing:\nClick over cities on the map for information about the weather in may.\n The climate of Beijing in may is perfect\nFollowing the decrease of precipitation that accompanies the rise in temperatures, the weather in Beijing throughout May is simply perfect. And When site:\nBeijing in may: average Weather, Temperature and Climate\nYou want to go to Beijing in China in may : check the weather and seasonal norms below.\n'}, {'url': 'https://weatherspark.com/h/y/131055/2024/Historical-Weather-during-2024-in-Beijing-China', 'content': 'Beijing Temperature History 2024\nHourly Temperature in 2024 in Beijing\nCompare Beijing to another city:\nCloud Cover in 2024 in Beijing\nObserved Weather in 2024 in Beijing\nHours of Daylight and Twilight in 2024 in Beijing\nSunrise & Sunset with Twilight in 2024 in Beijing\nSolar Elevation and Azimuth in 2024 in Beijing\nMoon Rise, Set & Phases in 2024 in Beijing\nHumidity Comfort Levels in 2024 in Beijing\nWind Speed in 2024 in Beijing\nHourly Wind Speed in 2024 in Beijing\nHourly Wind Direction in 2024 in Beijing\nAtmospheric Pressure in 2024 in Beijing\nData Sources\n See all nearby weather stations\nLatest Report — 12:00 AM\nThu, Feb 1, 2024\xa0\xa0\xa0\xa025 min ago\xa0\xa0\xa0\xa0UTC 16:00\nCall Sign ZBAA\nTemp.\n12°F\nPrecipitation\nNo Report\nWind\n2.2 mph\nCloud Cover\nCeiling and Visibility OK\nRaw: ZBAA 011600Z While having the tremendous advantages of temporal and spatial completeness, these reconstructions: (1) are based on computer models that may have model-based errors, (2) are coarsely sampled on a 50 km grid and are therefore unable to reconstruct the local variations of many microclimates, and (3) have particular difficulty with the weather in some coastal areas, especially small islands.\n We further caution that our travel scores are only as good as the data that underpin them, that weather conditions at any given location and time are unpredictable and variable, and that the definition of the scores reflects a particular set of preferences that may not agree with those of any particular reader.\n See all nearby weather stations\nDisclaimer\nThe information on this site is provided as is, without any assurances as to its accuracy or suitability for any purpose.'}, {'url': 'https://www.weather-atlas.com/en/china/beijing-weather-may', 'content': 'In Beijing, China, during the entire year, the rain falls for 70.6 days and collects up to 572mm (22.52") of precipitation. Daylight In Beijing, the average length of the day in May is 14h and 23min. On the first day of May, sunrise is at 05:14 and sunset at 19:08. On the last day of the month, sunrise is at 04:48 and sunset at 19:36 CST. Sunshine'}]The current weather in Beijing is sunny with a temperature of 69.8°F (21°C). The wind speed is 3.6 kph from the WSW direction, and the humidity is 31%.
如何学习大模型 AI ?
由于新岗位的生产效率,要优于被取代岗位的生产效率,所以实际上整个社会的生产效率是提升的。
但是具体到个人,只能说是:
“最先掌握AI的人,将会比较晚掌握AI的人有竞争优势”。
这句话,放在计算机、互联网、移动互联网的开局时期,都是一样的道理。
我在一线互联网企业工作十余年里,指导过不少同行后辈。帮助很多人得到了学习和成长。
我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在人工智能学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。但苦于知识传播途径有限,很多互联网行业朋友无法获得正确的资料得到学习提升,故此将并将重要的AI大模型资料包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来。
第一阶段(10天):初阶应用
该阶段让大家对大模型 AI有一个最前沿的认识,对大模型 AI 的理解超过 95% 的人,可以在相关讨论时发表高级、不跟风、又接地气的见解,别人只会和 AI 聊天,而你能调教 AI,并能用代码将大模型和业务衔接。
- 大模型 AI 能干什么?
- 大模型是怎样获得「智能」的?
- 用好 AI 的核心心法
- 大模型应用业务架构
- 大模型应用技术架构
- 代码示例:向 GPT-3.5 灌入新知识
- 提示工程的意义和核心思想
- Prompt 典型构成
- 指令调优方法论
- 思维链和思维树
- Prompt 攻击和防范
- …
第二阶段(30天):高阶应用
该阶段我们正式进入大模型 AI 进阶实战学习,学会构造私有知识库,扩展 AI 的能力。快速开发一个完整的基于 agent 对话机器人。掌握功能最强的大模型开发框架,抓住最新的技术进展,适合 Python 和 JavaScript 程序员。
- 为什么要做 RAG
- 搭建一个简单的 ChatPDF
- 检索的基础概念
- 什么是向量表示(Embeddings)
- 向量数据库与向量检索
- 基于向量检索的 RAG
- 搭建 RAG 系统的扩展知识
- 混合检索与 RAG-Fusion 简介
- 向量模型本地部署
- …
第三阶段(30天):模型训练
恭喜你,如果学到这里,你基本可以找到一份大模型 AI相关的工作,自己也能训练 GPT 了!通过微调,训练自己的垂直大模型,能独立训练开源多模态大模型,掌握更多技术方案。
到此为止,大概2个月的时间。你已经成为了一名“AI小子”。那么你还想往下探索吗?
- 为什么要做 RAG
- 什么是模型
- 什么是模型训练
- 求解器 & 损失函数简介
- 小实验2:手写一个简单的神经网络并训练它
- 什么是训练/预训练/微调/轻量化微调
- Transformer结构简介
- 轻量化微调
- 实验数据集的构建
- …
第四阶段(20天):商业闭环
对全球大模型从性能、吞吐量、成本等方面有一定的认知,可以在云端和本地等多种环境下部署大模型,找到适合自己的项目/创业方向,做一名被 AI 武装的产品经理。
- 硬件选型
- 带你了解全球大模型
- 使用国产大模型服务
- 搭建 OpenAI 代理
- 热身:基于阿里云 PAI 部署 Stable Diffusion
- 在本地计算机运行大模型
- 大模型的私有化部署
- 基于 vLLM 部署大模型
- 案例:如何优雅地在阿里云私有部署开源大模型
- 部署一套开源 LLM 项目
- 内容安全
- 互联网信息服务算法备案
- …
学习是一个过程,只要学习就会有挑战。天道酬勤,你越努力,就会成为越优秀的自己。
如果你能在15天内完成所有的任务,那你堪称天才。然而,如果你能完成 60-70% 的内容,你就已经开始具备成为一名大模型 AI 的正确特征了。
这份完整版的大模型 AI 学习资料已经上传CSDN,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费
】
![](https://img-blog.csdnimg.cn/img_convert/0dc35641cd2d85e39db6e8cb368fa5cb.png)