aorwall / moatless-tools

MIT License
216 stars 20 forks source link

ValueError: 'Module' is not a valid CodeBlockType #4

Closed zkx06111 closed 2 months ago

zkx06111 commented 2 months ago

Hi, thank you for the great project!

I was trying to run the swebench notebook after using poetry install for the environment.

The second cell gave me this error.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 6
      3 import time
      4 import traceback
----> 6 from moatless.benchmark.swebench import setup_swebench_repo, get_repo_dir_name
      7 from moatless.benchmark.utils import setup_langfuse_tracing, get_total_cost, get_missing_spans
      8 from moatless.loop import CodeLoop, SearchLoop

File ~/moatless-tools/moatless/__init__.py:1
----> 1 from moatless.repository import FileRepository
      2 from moatless.workspace import Workspace
      3 from moatless.settings import Settings

File ~/moatless-tools/moatless/repository.py:10
      6 from typing import List, Optional, Tuple
      8 from pydantic import BaseModel
---> 10 from moatless.codeblocks.codeblocks import CodeBlockTypeGroup, CodeBlockType
     11 from moatless.codeblocks.module import Module
     12 from moatless.codeblocks.parser.python import PythonParser

File ~/moatless-tools/moatless/codeblocks/__init__.py:2
      1 from moatless.codeblocks.codeblocks import CodeBlock, CodeBlockType
----> 2 from moatless.codeblocks.parser.create import create_parser
      3 from moatless.codeblocks.parser.parser import CodeParser

File ~/moatless-tools/moatless/codeblocks/parser/create.py:3
      1 from typing import Optional
----> 3 from moatless.codeblocks.parser.parser import CodeParser
      4 from moatless.codeblocks.parser.python import PythonParser
      7 def is_supported(language: str) -> bool:

File ~/moatless-tools/moatless/codeblocks/parser/parser.py:22
      9 from tree_sitter import Node, Language, Parser
     11 from moatless.codeblocks.codeblocks import (
     12     CodeBlock,
     13     CodeBlockType,
   (...)
     20     SpanType,
     21 )
---> 22 from moatless.codeblocks.module import Module
     23 from moatless.codeblocks.parser.comment import get_comment_symbol
     25 commented_out_keywords = ["rest of the code", "existing code", "other code"]

File ~/moatless-tools/moatless/codeblocks/module.py:15
     10 from moatless.codeblocks.codeblocks import BlockSpan, SpanType
     12 logger = logging.getLogger(__name__)
---> 15 class Module(CodeBlock):
     16     model_config = ConfigDict(arbitrary_types_allowed=True)
     18     file_path: Optional[str] = None

File ~/miniforge3/envs/mt/lib/python3.10/site-packages/pydantic/main.py:198, in pydantic.main.ModelMetaclass.__new__()

File ~/miniforge3/envs/mt/lib/python3.10/site-packages/pydantic/fields.py:506, in pydantic.fields.ModelField.infer()

File ~/miniforge3/envs/mt/lib/python3.10/site-packages/pydantic/fields.py:436, in pydantic.fields.ModelField.__init__()

File ~/miniforge3/envs/mt/lib/python3.10/site-packages/pydantic/fields.py:546, in pydantic.fields.ModelField.prepare()

File ~/miniforge3/envs/mt/lib/python3.10/site-packages/pydantic/fields.py:570, in pydantic.fields.ModelField._set_default_and_type()

File ~/miniforge3/envs/mt/lib/python3.10/site-packages/pydantic/fields.py:439, in pydantic.fields.ModelField.get_default()

File ~/miniforge3/envs/mt/lib/python3.10/site-packages/pydantic/utils.py:695, in pydantic.utils.smart_deepcopy()

File ~/miniforge3/envs/mt/lib/python3.10/copy.py:172, in deepcopy(x, memo, _nil)
    170                 y = x
    171             else:
--> 172                 y = _reconstruct(x, memo, *rv)
    174 # If is its own copy, don't memoize.
    175 if y is not x:

File ~/miniforge3/envs/mt/lib/python3.10/copy.py:265, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    263 if deep and args:
    264     args = (deepcopy(arg, memo) for arg in args)
--> 265 y = func(*args)
    266 if deep:
    267     memo[id(x)] = y

File ~/miniforge3/envs/mt/lib/python3.10/enum.py:385, in EnumMeta.__call__(cls, value, names, module, qualname, type, start)
    360 """
    361 Either returns an existing member, or creates a new enum class.
    362 
   (...)
    382 `type`, if set, will be mixed in as the first base class.
    383 """
    384 if names is None:  # simple value lookup
--> 385     return cls.__new__(cls, value)
    386 # otherwise, functional API: we're creating a new Enum type
    387 return cls._create_(
    388         value,
    389         names,
   (...)
    393         start=start,
    394         )

File ~/miniforge3/envs/mt/lib/python3.10/enum.py:710, in Enum.__new__(cls, value)
    708 ve_exc = ValueError("%r is not a valid %s" % (value, cls.__qualname__))
    709 if result is None and exc is None:
--> 710     raise ve_exc
    711 elif exc is None:
    712     exc = TypeError(
    713             'error in %s._missing_: returned %r instead of None or a valid member'
    714             % (cls.__name__, result)
    715             )

ValueError: 'Module' is not a valid CodeBlockType

After downgrading pydantic to 1.9.0, this error was gone and I got another error:

ImportError: cannot import name 'ConfigDict' from 'pydantic' (/Users/kexun.zhang/miniforge3/envs/mt/lib/python3.10/site-packages/pydantic/__init__.cpython-310-darwin.so)

which I think is due to the version of pydantic.

Is there something I'm doing wrong with the dependencies?

zkx06111 commented 2 months ago

I switched to linux and it works. Not sure why

aorwall commented 2 months ago

Ok. Thanks for reporting it. I only use Linux. Did you test this on a Mac or?

ryanhoangt commented 2 months ago

I was trying on a Lighting studio and got the same error.

zkx06111 commented 2 months ago

Ok. Thanks for reporting it. I only use Linux. Did you test this on a Mac or?

Yes I tested this on a mac.

aorwall commented 2 months ago

I got the same error when running in Google Colab. Should be fixed now.