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
如果有任何问题,欢迎在评论区提问。
相关文章:

autogen框架中使用chatglm4模型实现react
本文将介绍如何使用使用chatglm4实现react,利用环境变量、Tavily API和ReAct代理模式来回答用户提出的问题。 环境变量 首先,我们需要加载环境变量。这可以通过使用dotenv库来实现。 from dotenv import load_dotenv_ load_dotenv()注意.env文件处于…...

读《Effective Java》笔记 - 条目9
条目9:与try-finally 相比,首选 try -with -resource 什么是 try-finally? try-finally 是 Java 中传统的资源管理方式,通常用于确保资源(如文件流、数据库连接等)被正确关闭。 BufferedReader reader n…...

【软件入门】Git快速入门
Git快速入门 文章目录 Git快速入门0.前言1.安装和配置2.新建版本库2.1.本地创建2.2.云端下载 3.版本管理3.1.添加和提交文件3.2.回退版本3.2.1.soft模式3.2.2.mixed模式3.2.3.hard模式3.2.4.使用场景 3.3.查看版本差异3.4.忽略文件 4.云端配置4.1.Github4.1.1.SSH配置4.1.2.关联…...

nextjs window is not defined
问题产生的原因 在 Next.js 中,“window is not defined” 错误通常出现在服务器端渲染(Server - Side Rendering,SSR)的代码中。这是因为window对象是浏览器环境中的全局对象,在服务器端没有window这个概念。例如&am…...

C语言实现冒泡排序:从基础到优化全解析
一、什么是冒泡排序? 冒泡排序(Bubble Sort)是一种经典的排序算法,其工作原理非常直观:通过多次比较和交换相邻元素,将较大的元素“冒泡”到数组的末尾。经过多轮迭代,整个数组会变得有序。 二…...

windows11下git与 openssl要注意的问题
看了一下自己贴文的历史,有一条重要的忘了写了。 当时帮有位同事配置gitlab,众说周知gitlab是不太好操作。 但我还是自认自己git还是相当熟的。 解决了一系列问题,如配置代理,sshkey,私有库,等等࿰…...

lua除法bug
故事背景,新来了一个数值,要改公式。神奇的一幕出现了,公式算出一个非常大的数。排查是lua有一个除法bug,1除以大数得到一个非常大的数。 function div(a, b)return tonumber(string.format("%.2f", a/b)) end print(1/73003) pri…...

Ubuntu下Docker容器java服务往mysql插入中文数据乱码
一、问题描述 1、java服务部署在ubuntu下的docker容器内,但是会出现部分插入中文数据显示乱码,如图所示: 二、解决方案 1、查看mysql是否支持utf8,登录进入Mysql 输入命令: mysql -u root -pshow variables like c…...

C语言根据字符串变量获取/设置结构体成员值
一、背景 在项目中需要根据从数据库中获取的字段与对应的键值付给对应结构体成员上,而c语言中没有类似的反射机制,所以需要实现类似功能。例,从表中查到a 10,在结构体t中,需要将 t.a 10。 二、实现 感谢ChatGPT&…...

Selenium 自动化测试demo
场景描述: 模拟用户登录页面操作,包括输入用户名、密码、验证码。验证码为算数运算,如下: 使用到的工具和依赖: 1. Selenium:pip install selenium 2. 需要安装浏览器驱动:这里使用的是Edge 3…...

LeetCode 111.二叉树的最小深度
题目: 给定一个二叉树,找出其最小深度。 最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 说明:叶子节点是指没有子节点的节点。 思路:自底向上(归)/自顶向下(递) DF…...

大工C语言作业答案
前言 这里是大连理工大学新版C语言课程MOOC作业的答案。 后期我会把全部的作业答案开源出来,希望对大家有帮助。 第九周第一题 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int B(int i) {int sum 1;while (i > 0){sum i * sum;i--;}return su…...

【Unity踩坑】Unity中父对象是非均匀缩放时出现倾斜或剪切现象
The game object is deformed when the parent object is in non-uniform scaling. 先来看一下现象 有两个Cube, Cube1(Scale2,1,1),Cube2(Scale1,1,1) 将Cube2拖拽为Cube2的子对象。并且将position设置为(-0.6,1,0&a…...

QT 跨平台实现 SSDP通信 支持多网卡
一.多网卡场景 在做SSDP通信的时候,客户端发出M-search命令后, 主机没有捕捉到SSDP的消息,你可以查看下,是不是局域网下,既打开了wifi,又连接了本地网络,mac os下很容易出现这种场景。此时,我们发送消息时,需要遍历所有网卡并发送M-search命令。 二.QT相关接口介绍 1…...

如何寻找适合的HTTP代理IP资源?
一、怎么找代理IP资源? 在选择代理IP资源的时候,很多小伙伴往往将可用率作为首要的参考指标。事实上,市面上的住宅IP或拨号VPS代理IP资源,其可用率普遍在95%以上,因此IP可用率并不是唯一的评判标准 其实更应该关注的…...

数据结构(ArrayList顺序表)
一、引言 1.什么是顺序表 定义: 顺序表是一种基于阵列实现的线性表结构,用连续的存储空间保存表中的数据元素,并按顺序排列。 底层依赖阵列,支持随机访问。元素之间没有额外的连接信息,如指针或链表节点。通过动态扩容…...

直接抄作业!Air780E模组LuatOS开发:位运算(bit)示例
在嵌入式开发中,位运算是一种高效且常用的操作技巧。本文将介绍如何使用Air780E模组和LuatOS进行位运算,并通过示例代码帮助读者快速上手。 一、位运算概述 位运算是一种在计算机系统中对二进制数位进行操作的运算。由于计算机内部数据的存储和处理都是…...

RK3588-LinuxSDK安装
安装依赖软件 执行如下命令,安装 LinuxSDK 开发包依赖软件。 备注:安装过程中,请保证 Ubuntu 可正常访问互联网,若提示"*** is already the newest version ***"表示该软件已安装,请忽略。 Host# sudo apt-get install -y git ssh make gcc libssl-dev \ liblz…...

MATLAB 中有关figure图表绘制函数设计(论文中常用)
在撰写论文时,使用 MATLAB 导出的图像常常因大小和格式不统一,导致投稿时编辑部频繁退稿,要求修改和调整。这不仅浪费时间,也增加了工作量。为了减少这些麻烦,可以在 MATLAB 中导出图像时提前设置好图表的大小、格式和…...

Unity UGUI原理剖析
UI最重要的两部分 UI是如何渲染出来的点击事件如何触发何时发生UI重绘 1:UI如何渲染出来的 UI渲染一定是有顶点的,没有顶点就没法确定贴图的采样,UGUI的顶点在一张Mesh上创建,经过渲染管线UI就渲染到屏幕上了,UI的渲染…...

Spring框架使用xml方式配置ThreadPoolTaskExecutor线程池,并且自定义线程工厂
一、自定义线程工厂 自定义线程工厂需要实现java.util.concurrent.ThreadFactory接口,重写newThread方法。 示例代码: package com.xiaobai.thread;import org.apache.log4j.Logger;import java.util.concurrent.ThreadFactory; import java.util.conc…...

架构-微服务-服务网关
文章目录 前言一、网关介绍1. 什么是API网关2. 核心功能特性3. 解决方案 二、Gateway简介三、Gateway快速入门1. 基础版2. 增强版3. 简写版 四、Gateway核心架构1. 基本概念2. 执行流程 五、Gateway断言1. 内置路由断言工厂2. 自定义路由断言工厂 六、过滤器1. 基本概念2. 局部…...

基于springboot的HttpClient、OKhttp、RestTemplate对比
HttpClient详细 Httpclient基础!!!!实战训练!!!!-CSDN博客 OKhttp使用 OKhttp导包 <!-- ok的Http连接池 --><dependency><groupId>com.squareup.okhttp3</g…...

(计算机组成原理)期末复习
第一章 计算机的基本组成:硬件软件(程序)计算机系统 软件有系统软件(系统管理工具),应用软件 计算机硬件:包括主机和外设,主机包括CPU和内存,***CPU由运算器和控制器所组…...

从0到1部署Tomcat和添加servlet(IDEA2024最新版详细教程)
本文不仅细化了每一个步骤,实现了从0到1部署Tomcat和添加servlet。还针对IDEA2024版和以前的版本在部署上的区别,做了详细介绍,尤其是add framework support部分。与此同时,针对控制台中文乱码问题,本文也给出了详细解…...

【Java从入门到放弃 之 Java程序基础】
Java程序基础 Java程序基础基本数据类型和变量数据类型变量赋值基本运算算术运算比较运算逻辑运算 Java程序基础 基本数据类型和变量 数据类型 对Java语言而言,有如下基本数据类型。 整数类型:有4种整型byte/short/int/long,它们占用的字…...

2024年11月26日Github流行趋势
项目名称:v2rayN 项目维护者:2dust yfdyh000 CGQAQ ShiinaRinne Lemonawa 项目介绍:一个支持Xray核心及其他功能的Windows和Linux图形用户界面客户端。 项目star数:70,383 项目fork数:11,602 项目名称:fre…...

相亲交友小程序项目介绍
一、项目背景 在当今快节奏的社会生活中,人们忙于工作和事业,社交圈子相对狭窄,寻找合适的恋爱对象变得愈发困难。相亲交友作为一种传统而有效的社交方式,在现代社会依然有着巨大的需求。我们的相亲交友项目旨在为广大单身人士提…...

使用ENSP实现默认路由
一、项目拓扑 二、项目实现 1.路由器AR1配置 进入系统试图 sys将路由器命名为R1 sysname R1关闭信息中心 undo info-center enable 进入g0/0/0接口 int g0/0/0将g0/0/0接口IP地址配置为2.2.2.1/24 ip address 2.2.2.1 24进入g0/0/1接口 int g0/0/1将g0/0/1接口IP地址配置为1.…...

CSGO游戏搬砖党如何应对上海Major
大家最近都关注major比赛了吗?目前已经有不少顶尖CSGO战队来到了上海,备战即将到来的2024上海Major赛。本次比赛正赛将于11月30日开打,欧洲、美洲和亚太地区的24支顶尖战队通过两周的角逐,包括揭幕赛、淘汰赛以及决赛三种…...