QwenLM / Qwen-Agent

Agent framework and applications built upon Qwen>=2.0, featuring Function Calling, Code Interpreter, RAG, and Chrome extension.
https://pypi.org/project/qwen-agent/
Other
3.57k stars 355 forks source link

parallel_doc_qa.py 这个案例我的怎么没办法运行呢,直接报 #251

Open wuybo opened 4 months ago

wuybo commented 4 months ago

image

代码是直接从项目那边拷贝下来的:

from qwen_agent.agents.doc_qa import ParallelDocQA
from qwen_agent.gui import WebUI

def test():
    bot = ParallelDocQA(llm={'model': 'qwen2-72b-instruct', 'generate_cfg': {'max_retries': 10}})
    messages = [
        {
            'role': 'user',
            'content': [
                {
                    'text': '介绍实验方法'
                },
                {
                    'file': 'https://arxiv.org/pdf/2310.08560.pdf'
                },
            ]
        },
    ]
    for rsp in bot.run(messages):
        print('bot response:', rsp)

def app_gui():
    # Define the agent
    bot = ParallelDocQA(
        llm={
            'model': 'qwen2-72b-instruct',
            'generate_cfg': {
                'max_retries': 10
            }
        },
        description='并行QA后用RAG召回内容并回答。支持文件类型:PDF/Word/PPT/TXT/HTML。使用与材料相同的语言提问会更好。',
    )

    chatbot_config = {'prompt.suggestions': [{'text': '介绍实验方法'}]}

    WebUI(bot, chatbot_config=chatbot_config).run()

if __name__ == '__main__':
    # test()
    app_gui()

运行log:

D:\pytho\Qwen-Agent-main\Scripts\python.exe D:\Backup\Downloads\Qwen-Agent-main\examples\parallel_doc_qa.py 
Running on local URL:  http://127.0.0.1:7861

To create a public link, set `share=True` in `launch()`.
2024-07-04 18:19:17,209 - parallel_doc_qa.py - 180 - INFO - user_question: 你好
Traceback (most recent call last):
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\queueing.py", line 541, in process_events
    response = await route_utils.call_process_api(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\route_utils.py", line 276, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\blocks.py", line 1928, in process_api
    result = await self.call_function(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\blocks.py", line 1526, in call_function
    prediction = await utils.async_iteration(iterator)
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\utils.py", line 657, in async_iteration
    return await iterator.__anext__()
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\utils.py", line 650, in __anext__
    return await anyio.to_thread.run_sync(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\anyio\to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\anyio\_backends\_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\anyio\_backends\_asyncio.py", line 859, in run
    result = context.run(func, *args)
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\utils.py", line 633, in run_sync_iterator_async
    return next(iterator)
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\utils.py", line 816, in gen_wrapper
    response = next(iterator)
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\gui\web_ui.py", line 225, in agent_run
    for responses in agent_runner.run(_history, **self.run_kwargs):
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\agent.py", line 94, in run
    for rsp in self._run(messages=new_messages, **kwargs):
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\agents\doc_qa\parallel_doc_qa.py", line 184, in _run
    assert len(records) > 0, 'records is empty, all url parsing failed.'
AssertionError: records is empty, all url parsing failed.
wuybo commented 4 months ago

image

代码是直接从项目那边拷贝下来的:

from qwen_agent.agents.doc_qa import ParallelDocQA
from qwen_agent.gui import WebUI

def test():
    bot = ParallelDocQA(llm={'model': 'qwen2-72b-instruct', 'generate_cfg': {'max_retries': 10}})
    messages = [
        {
            'role': 'user',
            'content': [
                {
                    'text': '介绍实验方法'
                },
                {
                    'file': 'https://arxiv.org/pdf/2310.08560.pdf'
                },
            ]
        },
    ]
    for rsp in bot.run(messages):
        print('bot response:', rsp)

def app_gui():
    # Define the agent
    bot = ParallelDocQA(
        llm={
            'model': 'qwen2-72b-instruct',
            'generate_cfg': {
                'max_retries': 10
            }
        },
        description='并行QA后用RAG召回内容并回答。支持文件类型:PDF/Word/PPT/TXT/HTML。使用与材料相同的语言提问会更好。',
    )

    chatbot_config = {'prompt.suggestions': [{'text': '介绍实验方法'}]}

    WebUI(bot, chatbot_config=chatbot_config).run()

if __name__ == '__main__':
    # test()
    app_gui()

运行log:

D:\pytho\Qwen-Agent-main\Scripts\python.exe D:\Backup\Downloads\Qwen-Agent-main\examples\parallel_doc_qa.py 
Running on local URL:  http://127.0.0.1:7861

To create a public link, set `share=True` in `launch()`.
2024-07-04 18:19:17,209 - parallel_doc_qa.py - 180 - INFO - user_question: 你好
Traceback (most recent call last):
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\queueing.py", line 541, in process_events
    response = await route_utils.call_process_api(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\route_utils.py", line 276, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\blocks.py", line 1928, in process_api
    result = await self.call_function(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\blocks.py", line 1526, in call_function
    prediction = await utils.async_iteration(iterator)
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\utils.py", line 657, in async_iteration
    return await iterator.__anext__()
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\utils.py", line 650, in __anext__
    return await anyio.to_thread.run_sync(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\anyio\to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\anyio\_backends\_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\anyio\_backends\_asyncio.py", line 859, in run
    result = context.run(func, *args)
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\utils.py", line 633, in run_sync_iterator_async
    return next(iterator)
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\gradio\utils.py", line 816, in gen_wrapper
    response = next(iterator)
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\gui\web_ui.py", line 225, in agent_run
    for responses in agent_runner.run(_history, **self.run_kwargs):
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\agent.py", line 94, in run
    for rsp in self._run(messages=new_messages, **kwargs):
  File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\agents\doc_qa\parallel_doc_qa.py", line 184, in _run
    assert len(records) > 0, 'records is empty, all url parsing failed.'
AssertionError: records is empty, all url parsing failed.

场景复现: 启动后直接询问;报错; 然后 上传文件后再进行询问,可以正常

JianxinMa commented 4 months ago

这个demo没处理好“用户不上传文件,直接问问题”的情况(写得太不鲁棒了)。。。它默认了用户会上传文档

wuybo commented 4 months ago

` 2024-07-04 18:50:22,896 - utils.py - 71 - WARNING - Traceback (most recent call last): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\base.py", line 379, in retry_model_service_iterator for rsp in it_fn(): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\qwen_dashscope.py", line 134, in _full_stream_output raise ModelServiceError(code=chunk.code, message=chunk.message) qwen_agent.llm.base.ModelServiceError: Error code: Throttling.RateQuota. Error message: Requests rate limit exceeded, please try again later.

2024-07-04 18:50:24,710 - utils.py - 71 - WARNING - Traceback (most recent call last): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\base.py", line 379, in retry_model_service_iterator for rsp in it_fn(): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\qwen_dashscope.py", line 134, in _full_stream_output raise ModelServiceError(code=chunk.code, message=chunk.message) qwen_agent.llm.base.ModelServiceError: Error code: Throttling.RateQuota. Error message: Requests rate limit exceeded, please try again later.

2024-07-04 18:50:26,416 - utils.py - 71 - WARNING - Traceback (most recent call last): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\base.py", line 379, in retry_model_service_iterator for rsp in it_fn(): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\qwen_dashscope.py", line 134, in _full_stream_output raise ModelServiceError(code=chunk.code, message=chunk.message) qwen_agent.llm.base.ModelServiceError: Error code: Throttling.RateQuota. Error message: Requests rate limit exceeded, please try again later.

2024-07-04 18:50:26,540 - utils.py - 71 - WARNING - Traceback (most recent call last): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\base.py", line 379, in retry_model_service_iterator for rsp in it_fn(): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\qwen_dashscope.py", line 134, in _full_stream_output raise ModelServiceError(code=chunk.code, message=chunk.message) qwen_agent.llm.base.ModelServiceError: Error code: Throttling.RateQuota. Error message: Requests rate limit exceeded, please try again later.

2024-07-04 18:50:27,612 - utils.py - 71 - WARNING - Traceback (most recent call last): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\base.py", line 379, in retry_model_service_iterator for rsp in it_fn(): File "D:\pytho\Qwen-Agent-main\lib\site-packages\qwen_agent\llm\qwen_dashscope.py", line 134, in _full_stream_output raise ModelServiceError(code=chunk.code, message=chunk.message) qwen_agent.llm.base.ModelServiceError: Error code: Throttling.RateQuota. Error message: Requests rate limit exceeded, please try again later.`

还会有这个问题;上传的是民法典的那个文件,可能是文件大的问题,希望优化;