当前位置:   article > 正文

解决langchain-chatchat-0.3.0版本互联网搜索报错BUG_str type expected

str type expected

 本篇文章是基于langchain-chatchat-0.3.0配置好bing_key的前提下,出现下面的报错,这个位置上对源码进行修改,方可以正常使用网络搜索。

  1. {'status': 4, 'tool_name': 'search_internet', 'tool_input': {'query': {'title': '大模型最新消息', 'description': '关于大模型的最新进展和研究动态', 'type': 'string'}}, 'text': 'Thought: 我需要搜索相关信息。\nAction: search_internet\nAction Input: {"query": {"title": "大模型最新消息", "description": "关于大模型的最新进展和研究动态", "type": "string"}}'}
  2. <class 'pydantic.v1.main.search_internetSchema'>
  3. {'run_id': 'bc9ddd1b-a7a0-451f-97fb-2def62f9630b', 'status': 6, 'tool': 'search_internet', 'tool_input': "{'query': {'title': '大模型最新消息', 'description': '关于大模型的最新进展和研究动态', 'type': 'string'}}"}
  4. 2024-06-28 16:23:39,575 root 674266 ERROR 1 validation error for search_internetSchema
  5. query
  6. str type expected (type=type_error.str)
  7. Traceback (most recent call last):
  8. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/server/utils.py", line 46, in wrap_done
  9. await fn
  10. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2536, in ainvoke
  11. input = await step.ainvoke(
  12. ^^^^^^^^^^^^^^^^^^^
  13. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain/chains/base.py", line 212, in ainvoke
  14. raise e
  15. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain/chains/base.py", line 203, in ainvoke
  16. await self._acall(inputs, run_manager=run_manager)
  17. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain/agents/agent.py", line 1481, in _acall
  18. next_step_output = await self._atake_next_step(
  19. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  20. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain/agents/agent.py", line 1275, in _atake_next_step
  21. [
  22. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain/agents/agent.py", line 1275, in <listcomp>
  23. [
  24. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain/agents/agent.py", line 1359, in _aiter_next_step
  25. result = await asyncio.gather(
  26. ^^^^^^^^^^^^^^^^^^^^^
  27. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain/agents/agent.py", line 1392, in _aperform_agent_action
  28. observation = await tool.arun(
  29. ^^^^^^^^^^^^^^^^
  30. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain_core/tools.py", line 520, in arun
  31. raise e
  32. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/langchain_core/tools.py", line 497, in arun
  33. parsed_input = self._parse_input(tool_input)
  34. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  35. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/server/agent/tools_factory/tools_registry.py", line 38, in _new_parse_input
  36. result = input_args.parse_obj(tool_input)
  37. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  38. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/pydantic/v1/main.py", line 526, in parse_obj
  39. return cls(**obj)
  40. ^^^^^^^^^^
  41. File "/etc/miniconda3/envs/chatchat/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in __init__
  42. raise validation_error
  43. pydantic.v1.error_wrappers.ValidationError: 1 validation error for search_internetSchema
  44. query
  45. str type expected (type=type_error.str)
  46. 2024-06-28 16:23:39,577 root 674266 ERROR ValidationError: Caught exception: 1 validation error for search_internetSchema
  47. query
  48. str type expected (type=type_error.str)```

这个时候我们需要在/root/miniconda3/envs/chatchat_0.3.0/lib/python3.11/site-packages/chatchat/webui_pages/dialogue/dialogue.py,这个文件中的dialogue/dialogue.py在420行的位置上,将下面的代码替换掉之前的代码,就可以解决启动不了网络搜索页面报错的问题

这里个需要注意的点是,先不要勾选页面上的agent功能。 修改之后,最后成功运行如下:

最后成功运行如下:

t

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/1009600
推荐阅读
相关标签
  

闽ICP备14008679号