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.76k stars 1.97k forks source link

ImportError: Unable to import langchain-google-genai #969

Open virologist opened 5 days ago

virologist commented 5 days ago

Describe the bug error and log are below

To Reproduce Steps to reproduce the behavior:

  1. See error
    gpt-researcher-1  | ⚠️ Error in reading JSON, attempting to repair JSON
    gpt-researcher-1  | Error using json_repair: the JSON object must be str, bytes or bytearray, not NoneType
    gpt-researcher-1  | ERROR:    Exception in ASGI application
    gpt-researcher-1  | Traceback (most recent call last):
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/actions/agent_creator.py", line 27, in choose_agent
    gpt-researcher-1  |     response = await create_chat_completion(
    gpt-researcher-1  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/utils/llm.py", line 54, in create_chat_completion
    gpt-researcher-1  |     provider = get_llm(llm_provider, model=model, temperature=temperature,
    gpt-researcher-1  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/utils/llm.py", line 19, in get_llm
    gpt-researcher-1  |     return GenericLLMProvider.from_provider(llm_provider, **kwargs)
    gpt-researcher-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/llm_provider/generic/base.py", line 60, in from_provider
    gpt-researcher-1  |     _check_pkg("langchain_google_genai")
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/llm_provider/generic/base.py", line 155, in _check_pkg
    gpt-researcher-1  |     raise ImportError(
    gpt-researcher-1  | ImportError: Unable to import langchain-google-genai. Please install with `pip install -U langchain-google-genai`
    gpt-researcher-1  |
    gpt-researcher-1  | During handling of the above exception, another exception occurred:
    gpt-researcher-1  |
    gpt-researcher-1  | Traceback (most recent call last):
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 242, in run_asgi
    gpt-researcher-1  |     result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
    gpt-researcher-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    gpt-researcher-1  |     return await self.app(scope, receive, send)
    gpt-researcher-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    gpt-researcher-1  |     await super().__call__(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 113, in __call__
    gpt-researcher-1  |     await self.middleware_stack(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 152, in __call__
    gpt-researcher-1  |     await self.app(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 77, in __call__
    gpt-researcher-1  |     await self.app(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    gpt-researcher-1  |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    gpt-researcher-1  |     raise exc
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    gpt-researcher-1  |     await app(scope, receive, sender)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 715, in __call__
    gpt-researcher-1  |     await self.middleware_stack(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 735, in app
    gpt-researcher-1  |     await route.handle(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 362, in handle
    gpt-researcher-1  |     await self.app(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 95, in app
    gpt-researcher-1  |     await wrap_app_handling_exceptions(app, session)(scope, receive, send)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    gpt-researcher-1  |     raise exc
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    gpt-researcher-1  |     await app(scope, receive, sender)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 93, in app
    gpt-researcher-1  |     await func(session)
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 383, in app
    gpt-researcher-1  |     await dependant.call(**solved_result.values)
    gpt-researcher-1  |   File "/usr/src/app/backend/server/server.py", line 136, in websocket_endpoint
    gpt-researcher-1  |     await handle_websocket_communication(websocket, manager)
    gpt-researcher-1  |   File "/usr/src/app/backend/server/server_utils.py", line 117, in handle_websocket_communication
    gpt-researcher-1  |     await handle_start_command(websocket, data, manager)
    gpt-researcher-1  |   File "/usr/src/app/backend/server/server_utils.py", line 28, in handle_start_command
    gpt-researcher-1  |     report = await manager.start_streaming(
    gpt-researcher-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/backend/server/websocket_manager.py", line 61, in start_streaming
    gpt-researcher-1  |     report = await run_agent(task, report_type, report_source, source_urls, tone, websocket, headers)
    gpt-researcher-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/backend/server/websocket_manager.py", line 95, in run_agent
    gpt-researcher-1  |     report = await researcher.run()
    gpt-researcher-1  |              ^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/backend/report_type/basic_report/basic_report.py", line 41, in run
    gpt-researcher-1  |     await researcher.conduct_research()
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/agent.py", line 88, in conduct_research
    gpt-researcher-1  |     self.agent, self.role = await choose_agent(
    gpt-researcher-1  |                             ^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/actions/agent_creator.py", line 44, in choose_agent
    gpt-researcher-1  |     return await handle_json_error(response)
    gpt-researcher-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/actions/agent_creator.py", line 55, in handle_json_error
    gpt-researcher-1  |     json_string = extract_json_with_regex(response)
    gpt-researcher-1  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/src/app/gpt_researcher/actions/agent_creator.py", line 71, in extract_json_with_regex
    gpt-researcher-1  |     json_match = re.search(r"{.*?}", response, re.DOTALL)
    gpt-researcher-1  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  |   File "/usr/local/lib/python3.11/re/__init__.py", line 176, in search
    gpt-researcher-1  |     return _compile(pattern, flags).search(string)
    gpt-researcher-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    gpt-researcher-1  | TypeError: expected string or bytes-like object, got 'NoneType'
    gpt-researcher-1  | INFO:     connection closed

Expected behavior should run properly

Screenshots If applicable, add screenshots to help explain your problem.

image

Desktop (please complete the following information): **- OS: Mac M1 latest

kesamet commented 3 days ago

Hi @virologist, please install with pip install -U langchain-google-genai

virologist commented 3 days ago

Thanks for your response. I still get this error below. This error is looks like related to the compatibility of the Pydantic V2 version.

/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'allow_population_by_field_name' has been renamed to 'populate_by_name'
  warnings.warn(message, UserWarning)
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/nn/miniconda3/lib/python3.12/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 "/Users/nn/miniconda3/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/middleware/errors.py", line 151, in __call__
    await self.app(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/middleware/cors.py", line 77, in __call__
    await self.app(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/routing.py", line 754, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/routing.py", line 774, in app
    await route.handle(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/routing.py", line 371, in handle
    await self.app(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/routing.py", line 96, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/starlette/routing.py", line 94, in app
    await func(session)
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/fastapi/routing.py", line 367, in app
    await dependant.call(**values)
  File "/Users/nn/Library/gpt-researcher/backend/server/server.py", line 136, in websocket_endpoint
    await handle_websocket_communication(websocket, manager)
  File "/Users/nn/Library/gpt-researcher/backend/server/server_utils.py", line 117, in handle_websocket_communication
    await handle_start_command(websocket, data, manager)
  File "/Users/nn/Library/gpt-researcher/backend/server/server_utils.py", line 28, in handle_start_command
    report = await manager.start_streaming(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/Library/gpt-researcher/backend/server/websocket_manager.py", line 61, in start_streaming
    report = await run_agent(task, report_type, report_source, source_urls, tone, websocket, headers)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/Library/gpt-researcher/backend/server/websocket_manager.py", line 95, in run_agent
    report = await researcher.run()
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/Library/gpt-researcher/backend/report_type/basic_report/basic_report.py", line 30, in run
    researcher = GPTResearcher(
                 ^^^^^^^^^^^^^^
  File "/Users/nn/Library/gpt-researcher/gpt_researcher/agent.py", line 76, in __init__
    self.memory = Memory(
                  ^^^^^^^
  File "/Users/nn/Library/gpt-researcher/gpt_researcher/memory/embeddings.py", line 40, in __init__
    from langchain_openai import OpenAIEmbeddings
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/langchain_openai/__init__.py", line 1, in <module>
    from langchain_openai.chat_models import AzureChatOpenAI, ChatOpenAI
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/langchain_openai/chat_models/__init__.py", line 1, in <module>
    from langchain_openai.chat_models.azure import AzureChatOpenAI
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/langchain_openai/chat_models/azure.py", line 41, in <module>
    from langchain_openai.chat_models.base import BaseChatOpenAI
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/langchain_openai/chat_models/base.py", line 353, in <module>
    class BaseChatOpenAI(BaseChatModel):
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 224, in __new__
    complete_model_class(
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 577, in complete_model_class
    schema = cls.__get_pydantic_core_schema__(cls, handler)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/main.py", line 671, in __get_pydantic_core_schema__
    return handler(source)
           ^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in __call__
    schema = self._handler(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 655, in generate_schema
    schema = self._generate_schema_inner(obj)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 924, in _generate_schema_inner
    return self._model_schema(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 739, in _model_schema
    {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1115, in _generate_md_field_schema
    common_field = self._common_field_schema(name, field_info, decorators)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1308, in _common_field_schema
    schema = self._apply_annotations(
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 2107, in _apply_annotations
    schema = get_inner_schema(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in __call__
    schema = self._handler(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 2088, in inner_handler
    schema = self._generate_schema_inner(obj)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 929, in _generate_schema_inner
    return self.match_type(obj)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1029, in match_type
    return self._match_generic_type(obj, origin)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1058, in _match_generic_type
    return self._union_schema(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1378, in _union_schema
    choices.append(self.generate_schema(arg))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 657, in generate_schema
    metadata_js_function = _extract_get_pydantic_json_schema(obj, schema)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nn/miniconda3/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 2447, in _extract_get_pydantic_json_schema
    raise PydanticUserError(
pydantic.errors.PydanticUserError: The `__modify_schema__` method is not supported in Pydantic v2. Use `__get_pydantic_json_schema__` instead in class `SecretStr`.

For further information visit https://errors.pydantic.dev/2.9/u/custom-json-schema
kesamet commented 3 days ago

I guess you are using OpenAI embedding? You probably need to update langchain-openai to the latest version