autogen框架中使用chatglm4模型实现react

本文将介绍如何使用使用chatglm4实现react,利用环境变量、Tavily API和ReAct代理模式来回答用户提出的问题。

环境变量

首先,我们需要加载环境变量。这可以通过使用dotenv库来实现。

from dotenv import load_dotenv_ = load_dotenv()

注意.env文件处于当前文件同一目录,如图:
在这里插入图片描述

配置

接下来,我们需要配置Tavily API和OpenAI API的密钥和基础URL。

import os
from typing import Annotatedfrom tavily import TavilyClientfrom autogen import AssistantAgent, UserProxyAgent, config_list_from_json, register_function
from autogen.agentchat.contrib.capabilities import teachability
from autogen.cache import Cache
from autogen.coding import DockerCommandLineCodeExecutor, LocalCommandLineCodeExecutorconfig_list = [{ "model": "GLM-4-Plus", "api_key": os.environ["OPENAI_API_KEY"], "base_url":os.environ["OPENAI_API_BASE"]}
]

Tavily API

然后,我们需要创建一个Tavily API客户端,并定义一个搜索工具函数。

tavily = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])def search_tool(query: Annotated[str, "The search query"]) -> Annotated[str, "The search results"]:return tavily.get_search_context(query=query, search_depth="advanced")

ReAct代理

接下来,我们定义一个ReAct代理模式,用于回答用户的问题。

ReAct_prompt = """
Answer the following questions as best you can. You have access to tools provided.Use the following format:Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take
Action Input: the input to the action
Observation: the result of the action
... (this process can repeat multiple times)
Thought: I now know the final answer
Final Answer: the final answer to the original input questionBegin!
Question: {input}
"""def react_prompt_message(sender, recipient, context):return ReAct_prompt.format(input=context["question"])

代码执行器

然后,我们设置一个代码执行器,用于在容器中运行代码。

os.makedirs("coding", exist_ok=True)
code_executor = LocalCommandLineCodeExecutor(work_dir="coding")

用户代理和助手代理

接下来,我们创建一个用户代理和一个助手代理,用于与用户进行交互。

user_proxy = UserProxyAgent(name="User",is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"),human_input_mode="ALWAYS",max_consecutive_auto_reply=10,code_execution_config={"executor": code_executor},
)assistant = AssistantAgent(name="Assistant",system_message="Only use the tools you have been provided with.Give the args when you need to use the tool. Reply 'TERMINATE' at the end of answer when all the task is done. ",llm_config={"config_list": config_list , "cache_seed": None},
)

注册搜索工具

然后,我们将搜索工具注册到助手代理中。

register_function(search_tool,caller=assistant,executor=user_proxy,name="search_tool",description="Search the web for the given query",
)

缓存

接下来,我们使用缓存来存储LLM的响应。

with Cache.disk(cache_seed=43) as cache:user_proxy.initiate_chat(assistant,message=react_prompt_message,question="What is the result of super bowl 2024?",cache=cache,)

输出:

[33mUser[0m (to Assistant):Answer the following questions as best you can. You have access to tools provided.Use the following format:Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take
Action Input: the input to the action
Observation: the result of the action
... (this process can repeat multiple times)
Thought: I now know the final answer
Final Answer: the final answer to the original input questionBegin!
Question: What is the result of super bowl 2024?--------------------------------------------------------------------------------
[autogen.oai.client: 11-25 17:31:24] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[33mAssistant[0m (to User):[32m***** Suggested tool call (call_-9217975427127676990): search_tool *****[0m
Arguments: 
{"query": "Super Bowl 2024 result"}
[32m************************************************************************[0m--------------------------------------------------------------------------------
[31m
>>>>>>>> NO HUMAN INPUT RECEIVED.[0m
[31m
>>>>>>>> USING AUTO REPLY...[0m
[35m
>>>>>>>> EXECUTING FUNCTION search_tool...[0m
[33mUser[0m (to Assistant):[33mUser[0m (to Assistant):[32m***** Response from calling tool (call_-9217975427127676990) *****[0m
"[\"{\\\"url\\\": \\\"https://www.espn.com/nfl/story/_/id/39480722/49ers-chiefs-live-super-bowl-lviii-updates-moments-highlights\\\", \\\"content\\\": \\\"With a relentless defense and opportune plays by their star quarterback -- including a pair of gutsy overtime scrambles -- the Chiefs won their third Super Bowl in five years in a 25-22 overtime victory against the San Francisco 49ers in only the second overtime game in Super Bowl history.\\\\n Staff\\\\nTaylor Swift supports Travis Kelce, chugs drink at Super Bowl LVIII10hTory Barron\\\\nAfter posting a losing record in December, the Chiefs embraced an underdog, villain mentality throughout the postseason, upsetting three teams en route to their second consecutive Super Bowl title, becoming the ninth team to repeat as Super Bowl champions and first since the 2004 New England Patriots.\\\\n ESPN\\\\nSuper Bowl 2024 - Highlights from Chiefs' win vs. 49ers\\\\nMike Tannenbaum and Tim Hasselbeck react to the Chiefs' thrilling overtime victory over the 49ers in the Super Bowl. The 49ers had the ball with 2:51 to go in a tied game, but a signature Steve Spagnuolo blitz on third down late in the fourth quarter forced a 49ers field goal. Led by their captains, most of the Chiefs arrived to Allegiant Stadium in Las Vegas on Sunday in all black, signaling a steely resolve to upset Brock Purdy and the NFC's best offensive ensemble.\\\\n\\\"}\", \"{\\\"url\\\": \\\"https://www.cbssports.com/nfl/news/2024-super-bowl-chiefs-vs-49ers-score-patrick-mahomes-leads-ot-comeback-as-k-c-wins-back-to-back-titles/live/\\\", \\\"content\\\": \\\"The championship-winning drive, which included a fourth-and-1 scramble from Mahomes and a clutch 7-yard catch from tight end Travis Kelce, was a must-score for K.C. The NFL's new playoff overtime rules -- both teams are guaranteed at least one possession in the extra period -- were in effect for the first time, and the Chiefs needed to answer the Niners' field goal.\\\\n Held out of the end zone until that point, Kansas City grabbed its first lead of the game at 13-10.\\\\nJennings' touchdown receiving (followed by a missed extra point) concluded a 75-yard drive that put the Niners back on top, 16-13, as the wideout joined former Philadelphia Eagles quarterback Nick Foles as the only players to throw and catch a touchdown in a Super Bowl.\\\\n He spread the ball around -- eight pass-catchers had at least two receptions -- slowly but surely overcoming a threatening 49ers defense that knocked him off his spot consistently in the first half.\\\\nMahomes, with his third Super Bowl MVP, now sits alongside Tom Brady (five) and Joe Montana (three) atop the mountain while becoming just the third player to win the award back-to-back, joining Bart Starr (I-II) and Terry Bradshaw (XIII-XIV).\\\\n The muffed punt that bounced off of cornerback Darrell Luter Jr.'s ankle was also the big break that the Chiefs needed as they scored on the very next play to take the lead for the first time in the game. College Pick'em\\\\nA Daily SportsLine Betting Podcast\\\\nNFL Playoff Time!\\\\n2024 Super Bowl, Chiefs vs. 49ers score: Patrick Mahomes leads OT comeback as K.C. wins back-to-back titles\\\\nCall it a dynasty; the Chiefs are the first team to win consecutive Super Bowls since 2003-04\\\\nThe Kansas City Chiefs are Super Bowl champions, again.\\\"}\", \"{\\\"url\\\": \\\"https://sports.yahoo.com/super-bowl-2024-chiefs-beat-49ers-in-ot-thriller-on-walk-off-td-pass-by-patrick-mahomes-035151467.html\\\", \\\"content\\\": \\\"Chiefs beat 49ers in OT thriller on walk-off TD pass by Patrick Mahomes\\\\nThe Kansas City Chiefs are Super Bowl champions for a third time in the Patrick Mahomes era.\\\\n Taylor Swift and the Kelce family make it down to the field after the Chiefs win the Super Bowl \\\\ud83d\\\\udc4f pic.twitter.com/FkbFIMiIxA\\\\n\\\\u2014 The Sporting News (@sportingnews) Travis Kelce was excited, as expected:\\\\nTravis never disappoints \\\\ud83d\\\\ude02 #ChiefsKingdom pic.twitter.com/Gr2J7JoF4c\\\\n\\\\u2014 NFL (@NFL) February 12, 2024\\\\nPatrick Mahomes: \\\\\\\"The Kansas City Chiefs are never underdogs. February 12, 2024\\\\nWith the Super Bowl on the line, the Chiefs just converted on fourth-and-1. February 12, 2024\\\\nNow, the Chiefs convert on third-and-6 to keep the drive moving.\\\\n\\\"}\", \"{\\\"url\\\": \\\"https://www.usatoday.com/story/sports/nfl/super-bowl/2024/02/11/super-bowl-2024-score-live-updates/72481979007/\\\", \\\"content\\\": \\\"- Nate Davis\\\\nThe 58 greatest NFL teams to play in the Super Bowl \\\\u2013 and not all won Lombardi Trophy\\\\nThe 2023 Kansas City Chiefs and San Francisco 49ers will become the 115th and 116th Super Bowl participants on Sunday, when they cross paths at Allegiant Stadium in Las Vegas. Super Bowl 2024 live updates: Keep up with Chiefs vs. 49ers score, highlights and analysis\\\\nThe\\\\u00a0Kansas City Chiefs\\\\u00a0will take on the\\\\u00a0San Francisco 49ers\\\\u00a0in\\\\u00a0Super Bowl 58\\\\u00a0tonight at\\\\u00a0Allegiant Stadium\\\\u00a0in\\\\u00a0Las Vegas\\\\u00a0for\\\\u00a0NFL\\\\u00a0supremacy.\\\\n Meanwhile, the 49ers will don their traditional road white uniform.\\\\u00a0 \\\\u2014 Jordan Mendoza\\\\nSuper Bowl 58 predictions\\\\nHere are our NFL expert picks based on the early odds for Super Bowl 58:\\\\nChiefs vs. 49ers moneyline\\\\nThe most basic of all bets is called the moneyline. \\\\u2014 Cydney Henderson\\\\nHighest-paid players in Super Bowl 58\\\\nHere are the highest-paid players in Super Bowl 58 based on average annual value, according to Over The Cap. \\\\u2014 Cydney Henderson\\\\nThe 58 greatest players in Super Bowl history: Meet the Chiefs kicker\\\\nHarrison Butker\\\\u00a0may be called upon to hit the biggest kick of his career if\\\\u00a0Super Bowl 58\\\\u00a0against the\\\\u00a0San Francisco 49ers\\\\u00a0is close in the fourth quarter.\\\\n\\\"}\", \"{\\\"url\\\": \\\"https://apnews.com/live/super-bowl-2024-updates\\\", \\\"content\\\": \\\"Throw in the fact that Chiefs coach Andy Reid will be in his fifth Super Bowl, the third most in NFL history, and has a chance to win a third ring, and the knowledge on the Kansas City sideline will be an advantage too big for the 49ers to overcome.\\\\n She performed in Japan on Saturday night before a flight across nine time zones and the international date line to reach the U.S.\\\\nRihanna performs during halftime of the NFL Super Bowl 57 football game between the Philadelphia Eagles and the Kansas City Chiefs, Sunday, Feb. 12, 2023, in Glendale, Ariz. (AP Photo/David J. Phillip)\\\\n After the teams take the field, Post Malone will perform \\\\u201cAmerica the Beautiful\\\\u201d and Reba McEntire will sing \\\\u201cThe Star-Spangled Banner.\\\\u201d\\\\nSan Francisco 49ers quarterback Brock Purdy (13) warms up before the NFL Super Bowl 58 football game against the Kansas City Chiefs, Sunday, Feb. 11, 2024, in Las Vegas. He was also the referee when the Chiefs beat the 49ers in the Super Bowl four years ago \\\\u2014 and when the Rams beat the Saints in the 2019 NFC championship game after an infamous missed call.\\\\n Purdy\\\\u2019s comeback from the injury to his throwing arm suffered in last season\\\\u2019s NFC championship loss to the Philadelphia Eagles has been part of the storybook start to his career that started as Mr. Irrelevant as the 262nd pick in the 2022 draft.\\\\n\\\"}\"]"
[32m******************************************************************[0m--------------------------------------------------------------------------------
[autogen.oai.client: 11-25 17:31:33] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[33mAssistant[0m (to User):Thought: The result of Super Bowl 2024 has been found.Final Answer: The Kansas City Chiefs won Super Bowl 2024 with a 25-22 overtime victory against the San Francisco 49ers.TERMINATE--------------------------------------------------------------------------------
[31m
>>>>>>>> NO HUMAN INPUT RECEIVED.[0m

Teachability能力

最后,我们添加Teachability能力到助手代理中,并再次与用户进行交互。

teachability = teachability.Teachability(verbosity=0,reset_db=True,path_to_db_dir="coding",recall_threshold=1.5,
)teachability.add_to_agent(assistant)with Cache.disk(cache_seed=44) as cache:user_proxy.initiate_chat(assistant,message=react_prompt_message,question="What is the result of super bowl 2024?",cache=cache,)

输出:

[92m
CLEARING MEMORY[0m
[33mUser[0m (to Assistant):Answer the following questions as best you can. You have access to tools provided.Use the following format:Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take
Action Input: the input to the action
Observation: the result of the action
... (this process can repeat multiple times)
Thought: I now know the final answer
Final Answer: the final answer to the original input questionBegin!
Question: What is the result of super bowl 2024?--------------------------------------------------------------------------------
[autogen.oai.client: 11-25 17:37:22] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:37:24] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:37:25] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:37:26] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.C:\Users\32564\.cache\chroma\onnx_models\all-MiniLM-L6-v2\onnx.tar.gz: 100%|██████████| 79.3M/79.3M [00:21<00:00, 3.92MiB/s][autogen.oai.client: 11-25 17:37:49] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:37:53] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[33mAssistant[0m (to User):[32m***** Suggested tool call (call_-9217975392767912887): search_tool *****[0m
Arguments: 
{"query": "Super Bowl 2024 result"}
[32m************************************************************************[0m--------------------------------------------------------------------------------
[31m
>>>>>>>> NO HUMAN INPUT RECEIVED.[0m
[31m
>>>>>>>> USING AUTO REPLY...[0m
[35m
>>>>>>>> EXECUTING FUNCTION search_tool...[0m
[33mUser[0m (to Assistant):[33mUser[0m (to Assistant):[32m***** Response from calling tool (call_-9217975392767912887) *****[0m
"[\"{\\\"url\\\": \\\"https://www.espn.com/nfl/story/_/id/39480722/49ers-chiefs-live-super-bowl-lviii-updates-moments-highlights\\\", \\\"content\\\": \\\"With a relentless defense and opportune plays by their star quarterback -- including a pair of gutsy overtime scrambles -- the Chiefs won their third Super Bowl in five years in a 25-22 overtime victory against the San Francisco 49ers in only the second overtime game in Super Bowl history.\\\\n Staff\\\\nTaylor Swift supports Travis Kelce, chugs drink at Super Bowl LVIII10hTory Barron\\\\nAfter posting a losing record in December, the Chiefs embraced an underdog, villain mentality throughout the postseason, upsetting three teams en route to their second consecutive Super Bowl title, becoming the ninth team to repeat as Super Bowl champions and first since the 2004 New England Patriots.\\\\n ESPN\\\\nSuper Bowl 2024 - Highlights from Chiefs' win vs. 49ers\\\\nMike Tannenbaum and Tim Hasselbeck react to the Chiefs' thrilling overtime victory over the 49ers in the Super Bowl. The 49ers had the ball with 2:51 to go in a tied game, but a signature Steve Spagnuolo blitz on third down late in the fourth quarter forced a 49ers field goal. Led by their captains, most of the Chiefs arrived to Allegiant Stadium in Las Vegas on Sunday in all black, signaling a steely resolve to upset Brock Purdy and the NFC's best offensive ensemble.\\\\n\\\"}\", \"{\\\"url\\\": \\\"https://www.cbssports.com/nfl/news/2024-super-bowl-chiefs-vs-49ers-score-patrick-mahomes-leads-ot-comeback-as-k-c-wins-back-to-back-titles/live/\\\", \\\"content\\\": \\\"The championship-winning drive, which included a fourth-and-1 scramble from Mahomes and a clutch 7-yard catch from tight end Travis Kelce, was a must-score for K.C. The NFL's new playoff overtime rules -- both teams are guaranteed at least one possession in the extra period -- were in effect for the first time, and the Chiefs needed to answer the Niners' field goal.\\\\n Held out of the end zone until that point, Kansas City grabbed its first lead of the game at 13-10.\\\\nJennings' touchdown receiving (followed by a missed extra point) concluded a 75-yard drive that put the Niners back on top, 16-13, as the wideout joined former Philadelphia Eagles quarterback Nick Foles as the only players to throw and catch a touchdown in a Super Bowl.\\\\n He spread the ball around -- eight pass-catchers had at least two receptions -- slowly but surely overcoming a threatening 49ers defense that knocked him off his spot consistently in the first half.\\\\nMahomes, with his third Super Bowl MVP, now sits alongside Tom Brady (five) and Joe Montana (three) atop the mountain while becoming just the third player to win the award back-to-back, joining Bart Starr (I-II) and Terry Bradshaw (XIII-XIV).\\\\n The muffed punt that bounced off of cornerback Darrell Luter Jr.'s ankle was also the big break that the Chiefs needed as they scored on the very next play to take the lead for the first time in the game. College Pick'em\\\\nA Daily SportsLine Betting Podcast\\\\nNFL Playoff Time!\\\\n2024 Super Bowl, Chiefs vs. 49ers score: Patrick Mahomes leads OT comeback as K.C. wins back-to-back titles\\\\nCall it a dynasty; the Chiefs are the first team to win consecutive Super Bowls since 2003-04\\\\nThe Kansas City Chiefs are Super Bowl champions, again.\\\"}\", \"{\\\"url\\\": \\\"https://sports.yahoo.com/super-bowl-2024-chiefs-beat-49ers-in-ot-thriller-on-walk-off-td-pass-by-patrick-mahomes-035151467.html\\\", \\\"content\\\": \\\"Chiefs beat 49ers in OT thriller on walk-off TD pass by Patrick Mahomes\\\\nThe Kansas City Chiefs are Super Bowl champions for a third time in the Patrick Mahomes era.\\\\n Taylor Swift and the Kelce family make it down to the field after the Chiefs win the Super Bowl \\\\ud83d\\\\udc4f pic.twitter.com/FkbFIMiIxA\\\\n\\\\u2014 The Sporting News (@sportingnews) Travis Kelce was excited, as expected:\\\\nTravis never disappoints \\\\ud83d\\\\ude02 #ChiefsKingdom pic.twitter.com/Gr2J7JoF4c\\\\n\\\\u2014 NFL (@NFL) February 12, 2024\\\\nPatrick Mahomes: \\\\\\\"The Kansas City Chiefs are never underdogs. February 12, 2024\\\\nWith the Super Bowl on the line, the Chiefs just converted on fourth-and-1. February 12, 2024\\\\nNow, the Chiefs convert on third-and-6 to keep the drive moving.\\\\n\\\"}\", \"{\\\"url\\\": \\\"https://www.usatoday.com/story/sports/nfl/super-bowl/2024/02/11/super-bowl-2024-score-live-updates/72481979007/\\\", \\\"content\\\": \\\"- Nate Davis\\\\nThe 58 greatest NFL teams to play in the Super Bowl \\\\u2013 and not all won Lombardi Trophy\\\\nThe 2023 Kansas City Chiefs and San Francisco 49ers will become the 115th and 116th Super Bowl participants on Sunday, when they cross paths at Allegiant Stadium in Las Vegas. Super Bowl 2024 live updates: Keep up with Chiefs vs. 49ers score, highlights and analysis\\\\nThe\\\\u00a0Kansas City Chiefs\\\\u00a0will take on the\\\\u00a0San Francisco 49ers\\\\u00a0in\\\\u00a0Super Bowl 58\\\\u00a0tonight at\\\\u00a0Allegiant Stadium\\\\u00a0in\\\\u00a0Las Vegas\\\\u00a0for\\\\u00a0NFL\\\\u00a0supremacy.\\\\n Meanwhile, the 49ers will don their traditional road white uniform.\\\\u00a0 \\\\u2014 Jordan Mendoza\\\\nSuper Bowl 58 predictions\\\\nHere are our NFL expert picks based on the early odds for Super Bowl 58:\\\\nChiefs vs. 49ers moneyline\\\\nThe most basic of all bets is called the moneyline. \\\\u2014 Cydney Henderson\\\\nHighest-paid players in Super Bowl 58\\\\nHere are the highest-paid players in Super Bowl 58 based on average annual value, according to Over The Cap. \\\\u2014 Cydney Henderson\\\\nThe 58 greatest players in Super Bowl history: Meet the Chiefs kicker\\\\nHarrison Butker\\\\u00a0may be called upon to hit the biggest kick of his career if\\\\u00a0Super Bowl 58\\\\u00a0against the\\\\u00a0San Francisco 49ers\\\\u00a0is close in the fourth quarter.\\\\n\\\"}\", \"{\\\"url\\\": \\\"https://apnews.com/live/super-bowl-2024-updates\\\", \\\"content\\\": \\\"Throw in the fact that Chiefs coach Andy Reid will be in his fifth Super Bowl, the third most in NFL history, and has a chance to win a third ring, and the knowledge on the Kansas City sideline will be an advantage too big for the 49ers to overcome.\\\\n She performed in Japan on Saturday night before a flight across nine time zones and the international date line to reach the U.S.\\\\nRihanna performs during halftime of the NFL Super Bowl 57 football game between the Philadelphia Eagles and the Kansas City Chiefs, Sunday, Feb. 12, 2023, in Glendale, Ariz. (AP Photo/David J. Phillip)\\\\n After the teams take the field, Post Malone will perform \\\\u201cAmerica the Beautiful\\\\u201d and Reba McEntire will sing \\\\u201cThe Star-Spangled Banner.\\\\u201d\\\\nSan Francisco 49ers quarterback Brock Purdy (13) warms up before the NFL Super Bowl 58 football game against the Kansas City Chiefs, Sunday, Feb. 11, 2024, in Las Vegas. He was also the referee when the Chiefs beat the 49ers in the Super Bowl four years ago \\\\u2014 and when the Rams beat the Saints in the 2019 NFC championship game after an infamous missed call.\\\\n Purdy\\\\u2019s comeback from the injury to his throwing arm suffered in last season\\\\u2019s NFC championship loss to the Philadelphia Eagles has been part of the storybook start to his career that started as Mr. Irrelevant as the 262nd pick in the 2022 draft.\\\\n\\\"}\"]"
[32m******************************************************************[0m--------------------------------------------------------------------------------
[autogen.oai.client: 11-25 17:38:05] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:06] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:07] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:09] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:15] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:17] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[33mAssistant[0m (to User):Thought: I now know the final answer
Final Answer: The Kansas City Chiefs won Super Bowl 2024 with a 25-22 overtime victory against the San Francisco 49ers.
TERMINATE--------------------------------------------------------------------------------
[31m
>>>>>>>> NO HUMAN INPUT RECEIVED.[0m

再访问一次:

# Use a different cache_seed.
with Cache.disk(cache_seed=110) as cache:user_proxy.initiate_chat(assistant,message=react_prompt_message,question="What is the result of super bowl 2024?",max_turns=1,cache=cache,)
[33mUser[0m (to Assistant):Answer the following questions as best you can. You have access to tools provided.Use the following format:Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take
Action Input: the input to the action
Observation: the result of the action
... (this process can repeat multiple times)
Thought: I now know the final answer
Final Answer: the final answer to the original input questionBegin!
Question: What is the result of super bowl 2024?--------------------------------------------------------------------------------
[autogen.oai.client: 11-25 17:38:47] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:50] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:51] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:51] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:54] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:54] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:55] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:38:56] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[autogen.oai.client: 11-25 17:39:02] {351} WARNING - Model GLM-4-Plus is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
[33mAssistant[0m (to User):Question: What is the result of Super Bowl 2024?Thought: I have prior knowledge about the Super Bowl 2024 result from the provided memories. I should use this information to answer the question.Action: Utilize the memories to construct the answer.Observation: From the memories:
- Chiefs won with a 25-22 overtime victory against the San Francisco 49ers.
- It was only the second overtime game in Super Bowl history.
- Patrick Mahomes led the winning drive and won his third Super Bowl MVP.
- Chiefs became the first team to win consecutive Super Bowls since 2003-04.Thought: I now know the final answer.Final Answer: The Kansas City Chiefs won Super Bowl 2024 with a 25-22 overtime victory against the San Francisco 49ers. This marked their third Super Bowl win in five years and made them the first team to win consecutive Super Bowls since the 2003-04 season. Patrick Mahomes played a crucial role and secured his third Super Bowl MVP award.TERMINATE--------------------------------------------------------------------------------

总结

本文介绍了如何使用autogen框架中使用chatglm4模型实现react,利用环境变量、Tavily API和ReAct代理模式来回答用户提出的问题。通过使用缓存和Teachability能力,我们可以提高系统的性能和准确性。

注意事项

提示词跟llm模型有关,对其他的模型需要微调提示词

参考链接:https://microsoft.github.io/autogen/0.2/docs/topics/prompting-and-reasoning/react
如果有任何问题,欢迎在评论区提问。

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

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

相关文章

Neural Magic 发布 LLM Compressor:提升大模型推理效率的新工具

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗&#xff1f;订阅我们的简报&#xff0c;深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同&#xff0c;从行业内部的深度分析和实用指南中受益。不要错过这个机会&#xff0c;成为AI领…

LabVIEW实现TCP/IP通信

目录 1、TCP通信原理 2、硬件环境部署 3、云端环境部署 4、TCP通信函数 5、程序架构 6、前面板设计 7、程序框图设计 8、测试验证 本专栏以LabVIEW为开发平台&#xff0c;讲解物联网通信组网原理与开发方法&#xff0c;覆盖RS232、TCP、MQTT、蓝牙、Wi-Fi、NB-IoT等协议。 结合…

Linux系统Docker部署开源在线协作笔记Trilium Notes与远程访问详细教程

目录 ⛳️推荐 前言 1. 安装docker与docker-compose 2. 启动容器运行镜像 3. 本地访问测试 4.安装内网穿透 5. 创建公网地址 6. 创建固定公网地址 ⛳️推荐 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下…

Linux关于vim的笔记

Linux关于vim的笔记&#xff1a;(vimtutor打开vim 教程) --------------------------------------------------------------------------------------------------------------------------------- 1. 光标在屏幕文本中的移动既可以用箭头键&#xff0c;也可以使用 hjkl 字母键…

Swift 实现链表重新排列:L0 → Ln → L1 → Ln-1

前言 本题由于没有合适答案为以往遗留问题&#xff0c;最近有时间将以往遗留问题一一完善。 143. 重排链表 不积跬步&#xff0c;无以至千里&#xff1b;不积小流&#xff0c;无以成江海&#xff0c;Swift社区 伴你前行。如果大家有建议和意见欢迎在文末留言&#xff0c;我们会…

C++ —— 以真我之名 如飞花般绚丽 - 智能指针

目录 1. RAII和智能指针的设计思路 2. C标准库智能指针的使用 2.1 auto_ptr 2.2 unique_ptr 2.3 简单模拟实现auto_ptr和unique_ptr的核心功能 2.4 shared_ptr 2.4.1 make_shared 2.5 weak_ptr 2.6 shared_ptr的缺陷&#xff1a;循环引用问题 3. shared_ptr 和 unique_…

Macos远程连接Linux桌面教程;Ubuntu配置远程桌面;Mac端远程登陆Linux桌面;可能出现的问题

文章目录 1. Ubuntu配置远程桌面2. Mac端远程登陆Linux桌面3. 可能出现的问题1.您用来登录计算机的密码与登录密钥环里的密码不再匹配2. 找不到org->gnome->desktop->remote-access 1. Ubuntu配置远程桌面 打开设置->共享->屏幕共享。勾选允许连接控制屏幕&…

ElasticSearch学习了解笔记

搜索引擎的原理&#xff1a; 1、查询分析&#xff08;自然语言处理&#xff09;理解用户需求 2、分词技术 3、关键词搜索匹配 4、搜索排序 lucence Lucene 是一个成熟的权威检索库 Elasticsearch 的搜索原理简单过程是&#xff0c;索引系统通过扫描文章中的每一个词&#xff…

GoF设计模式——结构型设计模式分析与应用

文章目录 UML图的结构主要表现为&#xff1a;继承&#xff08;抽象&#xff09;、关联 、组合或聚合 的三种关系。1. 继承&#xff08;抽象&#xff0c;泛化关系&#xff09;2. 关联3. 组合/聚合各种可能的配合&#xff1a;1. 关联后抽象2. 关联的集合3. 组合接口4. 递归聚合接…

【C++】C++11新特性详解:可变参数模板与emplace系列的应用

C语法相关知识点可以通过点击以下链接进行学习一起加油&#xff01;命名空间缺省参数与函数重载C相关特性类和对象-上篇类和对象-中篇类和对象-下篇日期类C/C内存管理模板初阶String使用String模拟实现Vector使用及其模拟实现List使用及其模拟实现容器适配器Stack与QueuePriori…

多模态大型语言模型(MLLM)综述

目录 多模态大语言模型的基础 长短期网络结构(LSTM) 自注意力机制 基于Transformer架构的自然语言处理模型 多模态嵌入的关键步骤 TF-IDF TF-IDF的概念 TF-IDF的计算公式 TF-IDF的主要思路 TF-IDF的案例 训练和微调多模态大语言模型(MLLM) 对比学习 (CLIP, ALIG…

Otter 安装流程

优质博文&#xff1a;IT-BLOG-CN 一、背景 随着公司的发展&#xff0c;订单库的数据目前已达到千万级别&#xff0c;需要进行分表分库&#xff0c;就需要对数据进行迁移&#xff0c;我们使用了otter&#xff0c;这里简单整理下&#xff0c;otter 的安装过程&#xff0c;希望对…

Web3 游戏周报(11.17 - 11.23)

回顾上周的区块链游戏概况&#xff0c;查看 Footprint Analytics 与 ABGA 最新发布的数据报告。 【11.17 - 11.23】Web3 游戏行业动态&#xff1a; 加密游戏开发商 Gunzilla Games 发推表示&#xff0c;其已与 Coinbase Ventures 达成合作并获得其投资。 国际足联将与 Mythica…

【linux学习指南】初识Linux进程信号与使用

文章目录 &#x1f4dd;信号快速认识&#x1f4f6;⽣活⻆度的信号&#x1f4f6; 技术应⽤⻆度的信号&#x1f309; 前台进程&#xff08;键盘&#xff09;&#x1f309;⼀个系统函数 &#x1f4f6;信号概念&#x1f4f6;查看信号 &#x1f320; 信号处理&#x1f309; 忽略此信…

3DEXPERIENCE软件是干什么的—3DE软件代理商微辰三维

在当今数字化转型浪潮席卷全球各个行业的大背景下&#xff0c;3DEXPERIENCE 软件宛如一颗璀璨的明星&#xff0c;闪耀在产品设计、制造以及协同创新等诸多领域。它是由达索系统公司推出的一款综合性的、功能强大的商业软件平台&#xff0c;为企业的整个产品生命周期管理带来了前…

【大数据学习 | Spark-Core】广播变量和累加器

1. 共享变量 Spark两种共享变量&#xff1a;广播变量&#xff08;broadcast variable&#xff09;与累加器&#xff08;accumulator&#xff09;。 累加器用来对信息进行聚合&#xff0c;相当于mapreduce中的counter&#xff1b;而广播变量用来高效分发较大的对象&#xff0c…

STM32编程小工具FlyMcu和STLINK Utility 《通俗易懂》破解

FlyMcu FlyMcu 模拟仿真软件是一款用于 STM32 芯片 ISP 串口烧录程序的专用工具&#xff0c;免费&#xff0c;且较为非常容易下手&#xff0c;好用便捷。 注意&#xff1a;STM32 芯片的 ISP 下载&#xff0c;只能使用串口1&#xff08;USART1&#xff09;&#xff0c;对应的串口…

MTK主板_安卓主板方案_MTK联发科主板定制开发

联发科(MTK)主板以其强大的性能和多样化的功能而受到广泛关注。该平台包括多个型号&#xff0c;例如MT6761、MT8766、MT6762、MT6765、MT8768和MT8788等&#xff0c;均配置了四核或八核64位处理器&#xff0c;主频可高达2.0GHz。采用先进的12nm工艺&#xff0c;搭载Android 11.…

信息收集(1)

学习视频引路信息收集&#xff08;1&#xff09;_哔哩哔哩_bilibili View信息收集&#xff08;1&#xff09; 分享一个漏洞挖掘平台&#xff1a;补天 以吉林通用航空职业技术学院|官网 (jlthedu.com)为目标 第一步&#xff1a;查看cdn和域名被注册的信息 可以查询域名信息的…

React(六)——Redux

文章目录 项目地址基本理解一、配置Redux store二、创建slice配置到store里并使用三、给Slice配置reducers&#xff0c;用来修改初始值 项目地址 教程作者&#xff1a;教程地址&#xff1a; 代码仓库地址&#xff1a; 所用到的框架和插件&#xff1a; dbt airflow基本理解 s…