assafelovic / gpt-researcher

LLM based autonomous agent that conducts local and web research on any topic and generates a comprehensive report with citations.
https://gptr.dev
Apache License 2.0
14.69k stars 1.96k forks source link

BUG: Crash due to inconsistent arguments passed to GPTResearcher() constructor #644

Closed trackrx closed 3 months ago

trackrx commented 3 months ago

Hi

Bug description: Inconsistent arguments passed to GPTResearcher() constructor.

The bug is found in this commit (latest master):

commit 861e3d853a00eeb30c9471f0eedbfc22eaf3ac69 (HEAD -> master, origin/master, origin/HEAD)

Expected behavior

research should be conducted.

Actual behavior

Crash:

$ python -m uvicorn main:app --reload
INFO:     Will watch for changes in these directories: ['/home/user/Devel/gpt-researcher']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [966878] using WatchFiles
USER_AGENT environment variable not set, consider setting it to identify your requests.
INFO:     Started server process [966880]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     ('127.0.0.1', 47402) - "WebSocket /ws" [accepted]
INFO:     connection open
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 151, in __call__
    await self.app(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/routing.py", line 373, in handle
    await self.app(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/routing.py", line 96, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/starlette/routing.py", line 94, in app
    await func(session)
  File "/home/user/Devel/gpt-researcher/venv/lib/python3.10/site-packages/fastapi/routing.py", line 348, in app
    await dependant.call(**values)
  File "/home/user/Devel/gpt-researcher/backend/server.py", line 58, in websocket_endpoint
    report = await manager.start_streaming(task, report_type, report_source, websocket)
  File "/home/user/Devel/gpt-researcher/backend/websocket_manager.py", line 57, in start_streaming
    report = await run_agent(task, report_type, report_source, websocket)
  File "/home/user/Devel/gpt-researcher/backend/websocket_manager.py", line 75, in run_agent
    report = await researcher.run()
  File "/home/user/Devel/gpt-researcher/backend/report_type/basic_report/basic_report.py", line 15, in run
    researcher = GPTResearcher(self.query, self.report_type, self.report_source, self.source_urls, self.config_path, self.websocket)
  File "/home/user/Devel/gpt-researcher/gpt_researcher/master/agent.py", line 58, in __init__
    self.cfg = Config(config_path)
  File "/home/user/Devel/gpt-researcher/gpt_researcher/config/config.py", line 11, in __init__
    self.config_file = os.path.expanduser(config_file) if config_file else os.getenv('CONFIG_FILE')
  File "/usr/lib/python3.10/posixpath.py", line 232, in expanduser
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not WebSocket
INFO:     connection closed

Additional info

In basic_report.py line 15: (https://github.com/assafelovic/gpt-researcher/blob/861e3d853a00eeb30c9471f0eedbfc22eaf3ac69/backend/report_type/basic_report/basic_report.py#L15)

The order of arguments sent to GPTResearcher() constructor is:

  1. query
  2. report_type
  3. report_source
  4. source_urls
  5. config_path
  6. websocket

However, the GPTResearcher() class constructor (https://github.com/assafelovic/gpt-researcher/blob/861e3d853a00eeb30c9471f0eedbfc22eaf3ac69/gpt_researcher/master/agent.py#L20) expects parameters in this order:

  1. query
  2. report_type
  3. report_source
  4. source_urls
  5. documents <--- this is a new call argument that is not sent in the above call!
  6. config_path
  7. websocket
  8. ...

The problem

Arguments sent in a call do not match the expected argument order. The new "documents" argument is not sent, instead:

The direct cause of a crash dump above is that config_path receives value of websocket due to the mismatch.

Hope this helps!

assafelovic commented 3 months ago

Great catch @trackrx ! Thank you and fixed in latest push.