microsoft / gpt-review

MIT License
249 stars 48 forks source link

[Bug Report]: ImportError: cannot import name 'BaseCache' from 'langchain' #231

Open syed-farazahmed opened 5 months ago

syed-farazahmed commented 5 months ago

Module path

gpt github review

review-gpt CLI version

v0.9.5

Describe the bug

The package is broken as it runs into ImportError when we invoke gpt github review command on CLI. ImportError: cannot import name 'BaseCache' from 'langchain' (/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/__init__.py)

A suggestion was made to install specific version of some packages as described in Issue # 208


         python -m pip install langchain==0.0.301
          python -m pip install pydantic==1.10.13
          python -m pip install gpt-review==v0.9.5

However, after this we run into new error:

Traceback (most recent call last):
  File "/home/emumba/Documents/emumba/gpt-review/.env/bin/gpt", line 5, in <module>
    from gpt_review.main import __main__
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/gpt_review/main.py", line 6, in <module>
    from gpt_review._gpt_cli import cli
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/gpt_review/_gpt_cli.py", line 9, in <module>
    from gpt_review._ask import AskCommandGroup
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/gpt_review/_ask.py", line 13, in <module>
    from gpt_review._openai import _call_gpt
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/gpt_review/_openai.py", line 6, in <module>
    from openai.error import RateLimitError
ModuleNotFoundError: No module named 'openai.error'

I want to run it with AzureOpenAI. It would be great if we can get a running example of a GitHub Action with Azure OpenAI.

To reproduce

Simply follow the commands provided in the workflow.

            sudo apt-get update
            python3 -m venv .env
            source .env/bin/activate
            python -m pip install --upgrade pip
            python -m pip install gpt-review 
            gpt github review 

Code snippet

name: 'code-review' 
on: [pull_request]
jobs:
    add_pr_comment:
      permissions: write-all
      runs-on: ubuntu-latest
      name: OpenAI PR Comment
      env:
        GIT_COMMIT_HASH: ${{ github.event.pull_request.head.sha }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        PR_NUMBER: ${{ github.event.pull_request.number }}
        PR_TITLE: ${{ github.event.pull_request.title }}
        REPOSITORY_NAME: ${{ github.repository }}
        AZURE_OPENAI_API: ${{ secrets.AZURE_OPENAI_API }}
        AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
        LINK: "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
        FILE_SUMMARY: false
        TEST_SUMMARY: false
        BUG_SUMMARY: false
        RISK_SUMMARY: false
        RISK_BREAKING: false
        CONTEXT_FILE: "../code-reviewer/azure.yaml"
      steps:
        - uses: actions/checkout@v3
          with:
            ref: ${{ github.event.pull_request.head.sha }}
        - name: Set up Python 3.11
          uses: actions/setup-python@v4
          with:
            python-version: 3.11
        - run: |
            sudo apt-get update
            python3 -m venv .env
            source .env/bin/activate
            python -m pip install --upgrade pip
            python -m pip install gpt-review\
        - run: |
            source .env/bin/activate
            gpt github review \
                --access-token $GITHUB_TOKEN \
                --pull-request $PR_NUMBER \
                --repository $REPOSITORY_NAME
            continue-on-error: true
        - run: |
            source .env/bin/activate
            pip install -e .
            gpt github review \
                --access-token $GITHUB_TOKEN \
                --pull-request $PR_NUMBER \

Relevant log output

$ gpt github review
/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/chat_models/__init__.py:31: LangChainDeprecationWarning: Importing chat models from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:

`from langchain_community.chat_models import AzureChatOpenAI`.

To install langchain-community run `pip install -U langchain-community`.
  warnings.warn(
/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/chat_models/__init__.py:31: LangChainDeprecationWarning: Importing chat models from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:

`from langchain_community.chat_models import ChatOpenAI`.

To install langchain-community run `pip install -U langchain-community`.
  warnings.warn(
/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/embeddings/__init__.py:29: LangChainDeprecationWarning: Importing embeddings from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:

`from langchain_community.embeddings import OpenAIEmbeddings`.

To install langchain-community run `pip install -U langchain-community`.
  warnings.warn(
/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/llms/__init__.py:548: LangChainDeprecationWarning: Importing LLMs from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:

`from langchain_community.llms import AzureOpenAI`.

To install langchain-community run `pip install -U langchain-community`.
  warnings.warn(
/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/__init__.py:29: UserWarning: Importing Cohere from langchain root module is no longer supported. Please use langchain_community.llms.Cohere instead.
  warnings.warn(
/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/__init__.py:29: UserWarning: Importing LLMChain from langchain root module is no longer supported. Please use langchain.chains.LLMChain instead.
  warnings.warn(
/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/__init__.py:29: UserWarning: Importing OpenAI from langchain root module is no longer supported. Please use langchain_community.llms.OpenAI instead.
  warnings.warn(
Traceback (most recent call last):
  File "/home/emumba/Documents/emumba/gpt-review/.env/bin/gpt", line 5, in <module>
    from gpt_review.main import __main__
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/gpt_review/main.py", line 6, in <module>
    from gpt_review._gpt_cli import cli
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/gpt_review/_gpt_cli.py", line 9, in <module>
    from gpt_review._ask import AskCommandGroup
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/gpt_review/_ask.py", line 12, in <module>
    from gpt_review._llama_index import _query_index
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/gpt_review/_llama_index.py", line 10, in <module>
    from llama_index import (
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/__init__.py", line 19, in <module>
    from llama_index.indices.common.struct_store.base import SQLDocumentContextBuilder
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/indices/__init__.py", line 4, in <module>
    from llama_index.indices.keyword_table.base import GPTKeywordTableIndex
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/indices/keyword_table/__init__.py", line 4, in <module>
    from llama_index.indices.keyword_table.base import GPTKeywordTableIndex
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/indices/keyword_table/base.py", line 18, in <module>
    from llama_index.indices.base import BaseGPTIndex
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/indices/base.py", line 6, in <module>
    from llama_index.chat_engine.types import BaseChatEngine, ChatMode
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/chat_engine/__init__.py", line 1, in <module>
    from llama_index.chat_engine.condense_question import CondenseQuestionChatEngine
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/chat_engine/condense_question.py", line 5, in <module>
    from llama_index.chat_engine.utils import to_chat_buffer
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/chat_engine/utils.py", line 6, in <module>
    from llama_index.indices.service_context import ServiceContext
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/indices/service_context.py", line 9, in <module>
    from llama_index.indices.prompt_helper import PromptHelper
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/indices/prompt_helper.py", line 13, in <module>
    from llama_index.llm_predictor.base import BaseLLMPredictor
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/llm_predictor/__init__.py", line 4, in <module>
    from llama_index.llm_predictor.base import LLMPredictor
  File "/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/llama_index/llm_predictor/base.py", line 11, in <module>
    from langchain import BaseCache, Cohere, LLMChain, OpenAI
ImportError: cannot import name 'BaseCache' from 'langchain' (/home/emumba/Documents/emumba/gpt-review/.env/lib/python3.8/site-packages/langchain/__init__.py)