【GPT入门】第30课 langchain的自问自搜刮答复agent不同模型对比 ...

打印 上一主题 下一主题

主题 1399|帖子 1399|积分 4197

概要

利用自问自搜自答agent,对比不同模型的执行结果。
gpt4:很牛
gpt3.5: 有的标题会失败
通义千问:执行失败
智谱:执行失败
结论:不同模型的大脑的真的不一样
1. 代码

  1. from langchain import hub
  2. from langchain.agents import AgentExecutor, create_self_ask_with_search_agent
  3. from langchain_community.tools.tavily_search import TavilyAnswer
  4. from langchain_openai import ChatOpenAI
  5. # 将初始化工具,让它提供答案而不是文档
  6. tools = [TavilyAnswer(max_results=1, name="Intermediate Answer", description="Answer Search")]
  7. # 初始化大模型
  8. # llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613")
  9. import os
  10. from langchain_community.chat_models import ChatTongyi
  11. # llm = ChatTongyi(
  12. #     model="qwen-max",
  13. #     api_key=os.getenv("DASHSCOPE_API_KEY"),
  14. #     base_url=os.getenv("DASHSCOPE_BASE_URL")
  15. # )
  16. from langchain_community.chat_models import ChatZhipuAI
  17. llm = ChatZhipuAI(
  18.     model="glm-4-flash",
  19.     api_key=os.getenv("ZHIPUAI_API_KEY"),
  20.     base_url=os.getenv("ZHIPUAI_BASE_URL")
  21. )
  22. # 获取使用提示 可以修改此提示
  23. prompt = hub.pull("hwchase17/self-ask-with-search")
  24. print(prompt.template)
  25. # 使用搜索代理构建自助询问
  26. agent = create_self_ask_with_search_agent(llm, tools, prompt)
  27. # 通过传入代理和工具创建代理执行程序
  28. agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, handle_parsing_errors=True)
  29. # 运行代理
  30. res = agent_executor.invoke({"input": "中国有哪些省份呢?"})
  31. print('res:',res)
复制代码
2 输出结果

用智谱和通义千问,执行都报错; 用GPT3.5 可以正常执行
  1. Question: Who lived longer, Muhammad Ali or Alan Turing?
  2. Are follow up questions needed here: Yes.
  3. Follow up: How old was Muhammad Ali when he died?
  4. Intermediate answer: Muhammad Ali was 74 years old when he died.
  5. Follow up: How old was Alan Turing when he died?
  6. Intermediate answer: Alan Turing was 41 years old when he died.
  7. So the final answer is: Muhammad Ali
  8. Question: When was the founder of craigslist born?
  9. Are follow up questions needed here: Yes.
  10. Follow up: Who was the founder of craigslist?
  11. Intermediate answer: Craigslist was founded by Craig Newmark.
  12. Follow up: When was Craig Newmark born?
  13. Intermediate answer: Craig Newmark was born on December 6, 1952.
  14. So the final answer is: December 6, 1952
  15. Question: Who was the maternal grandfather of George Washington?
  16. Are follow up questions needed here: Yes.
  17. Follow up: Who was the mother of George Washington?
  18. Intermediate answer: The mother of George Washington was Mary Ball Washington.
  19. Follow up: Who was the father of Mary Ball Washington?
  20. Intermediate answer: The father of Mary Ball Washington was Joseph Ball.
  21. So the final answer is: Joseph Ball
  22. Question: Are both the directors of Jaws and Casino Royale from the same country?
  23. Are follow up questions needed here: Yes.
  24. Follow up: Who is the director of Jaws?
  25. Intermediate answer: The director of Jaws is Steven Spielberg.
  26. Follow up: Where is Steven Spielberg from?
  27. Intermediate answer: The United States.
  28. Follow up: Who is the director of Casino Royale?
  29. Intermediate answer: The director of Casino Royale is Martin Campbell.
  30. Follow up: Where is Martin Campbell from?
  31. Intermediate answer: New Zealand.
  32. So the final answer is: No
  33. Question: {input}
  34. Are followup questions needed here:{agent_scratchpad}
  35. > Entering new AgentExecutor chain...
  36. Could not parse output: Yes, follow-up questions could be helpful to provide more detailed information about the provinces or to clarify specific aspects of Chinese provinces.
  37. Follow-up questions might include:
  38. - How many provinces are there in China?
  39. - Are there any special administrative regions in China that are not provinces?
  40. - Can you name some of the most populous provinces in China?
  41. - What are the differences between a province and other administrative divisions in China?
  42. - Are there any provinces that have unique cultural or historical significance in China?
  43. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE Invalid or incomplete responseCould not parse output: Intermediate answer:
  44. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE Invalid or incomplete responseCould not parse output: Apologies for the confusion. Let's address the questions one by one:
  45. Question: 中国有哪些省份呢?
  46. Intermediate answer:
  47. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE Invalid or incomplete responseCould not parse output: Certainly, here's the information you're seeking:
  48. Question: 中国有哪些省份呢?
  49. Final answer:
  50. China is divided into 34 administrative divisions
  51. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE Invalid or incomplete responseCould not parse output: Final answer:
  52. China is divided
  53. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE Invalid or incomplete responseCould not parse output: Final answer:
  54. China is administratively divided into 23 provinces, 5 autonomous regions, 4 direct-controlled municipalities (Beijing, Tianjin, Shanghai, and Chongqing), and 2 special administrative regions (Hong Kong and Macau). Here are the provinces:
  55. 1. Hebei Province
  56. 2. Shanxi Province
  57. 3. Inner Mongolia Autonomous Region
  58. 4. Liaoning Province
  59. 5. Jilin Province
  60. 6. Heilongjiang Province
  61. 7. Shanghai Municipality
  62. 8. Jiangsu Province
  63. 9. Zhejiang Province
  64. 10. Anhui Province
  65. 11. Fujian Province
  66. 12. Jiangxi Province
  67. 13. Shandong Province
  68. 14. Henan Province
  69. 15. Hubei Province
  70. 16. Hunan Province
  71. 17. Guangdong Province
  72. 18. Guangxi Zhuang Autonomous Region
  73. 19. Hainan Province
  74. 20. Chongqing Municipality
  75. 21. Sichuan Province
  76. 22. Guizhou Province
  77. 23. Yunnan Province
  78. 24. Shaanxi Province
  79. 25. Gansu Province
  80. 26. Qinghai Province
  81. 27. Ningxia Hui Autonomous Region
  82. 28. Xinjiang Uyghur Autonomous Region
  83. Please note that China also has a number of prefecture-level divisions, county-level divisions, and town-level divisions, but these are not considered provinces. If you have any specific follow-up questions or need further information, feel free to ask!
  84. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE Invalid or incomplete responseCould not parse output: Final answer:
  85. China is divided into
  86. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE Invalid or incomplete responseTraceback (most recent call last):
  87.   File "E:\workspace\gptLearning\gptLearning\ls10\agent\ls24_create_self_ask_with_search_agent.py", line 35, in <module>
  88.     res = agent_executor.invoke({"input": "中国有哪些省份呢?"})
复制代码
把标题改为:世界上最美丽的人是谁, gpt3.5也宕机了,吐血
  1. res = agent_executor.invoke({"input": "世界上最漂亮的人是谁?"})
  2. print('res:',res)
复制代码
gpt3.5执行失败:

gpt4执行成功:


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

小小小幸运

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表