run-llama / create-llama

The easiest way to get started with LlamaIndex
MIT License
1.05k stars 135 forks source link

Pydantic issue with new templates crashing backend #441

Closed KenjiPcx closed 1 day ago

KenjiPcx commented 1 day ago

I tried creating a new agentic RAG app today, followed the instructions in the README, and the backend was crashing.

Here is the traceback

Traceback (most recent call last):
  File "/home/kenji/work-consultant-ai/auto-consultant/ppt-chat/main.py", line 11, in <module>
    from app.api.routers import api_router
  File "/home/kenji/work-consultant-ai/auto-consultant/ppt-chat/app/api/routers/__init__.py", line 3, in <module>
    from .chat import chat_router  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/work-consultant-ai/auto-consultant/ppt-chat/app/api/routers/chat.py", line 4, in <module>
    from llama_index.core.llms import MessageRole
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/llama_index/core/__init__.py", line 19, in <module>
    from llama_index.core.indices import (
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/llama_index/core/indices/__init__.py", line 4, in <module>
    from llama_index.core.indices.composability.graph import ComposableGraph
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/llama_index/core/indices/composability/__init__.py", line 4, in <module>
    from llama_index.core.indices.composability.graph import ComposableGraph
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/llama_index/core/indices/composability/graph.py", line 5, in <module>
    from llama_index.core.base.base_query_engine import BaseQueryEngine
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/llama_index/core/base/base_query_engine.py", line 20, in <module>
    from llama_index.core.instrumentation.events.query import (
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/llama_index/core/instrumentation/events/query.py", line 21, in <module>
    class QueryEndEvent(BaseEvent):
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 226, in __new__
    complete_model_class(
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 658, in complete_model_class
    schema = cls.__get_pydantic_core_schema__(cls, handler)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/main.py", line 697, in __get_pydantic_core_schema__
    return handler(source)
           ^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_schema_generation_shared.py", line 84, in __call__
    schema = self._handler(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 612, in generate_schema
    schema = self._generate_schema_inner(obj)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 881, in _generate_schema_inner
    return self._model_schema(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 693, in _model_schema
    {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 693, in <dictcomp>
    {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1073, in _generate_md_field_schema
    common_field = self._common_field_schema(name, field_info, decorators)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1261, in _common_field_schema
    schema = self._apply_annotations(
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 2051, in _apply_annotations
    schema = get_inner_schema(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_schema_generation_shared.py", line 84, in __call__
    schema = self._handler(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 2032, in inner_handler
    schema = self._generate_schema_inner(obj)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 886, in _generate_schema_inner
    return self.match_type(obj)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 988, in match_type
    return self._match_generic_type(obj, origin)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1016, in _match_generic_type
    return self._union_schema(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1323, in _union_schema
    choices.append(self.generate_schema(arg))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 612, in generate_schema
    schema = self._generate_schema_inner(obj)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 886, in _generate_schema_inner
    return self.match_type(obj)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 984, in match_type
    return self._dataclass_schema(obj, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1765, in _dataclass_schema
    args = sorted(
           ^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1766, in <genexpr>
    (self._generate_dc_field_schema(k, v, decorators) for k, v in fields.items()),
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1090, in _generate_dc_field_schema
    common_field = self._common_field_schema(name, field_info, decorators)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1261, in _common_field_schema
    schema = self._apply_annotations(
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 2051, in _apply_annotations
    schema = get_inner_schema(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_schema_generation_shared.py", line 84, in __call__
    schema = self._handler(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 2032, in inner_handler
    schema = self._generate_schema_inner(obj)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 886, in _generate_schema_inner
    return self.match_type(obj)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 988, in match_type
    return self._match_generic_type(obj, origin)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 1045, in _match_generic_type
    return self._unknown_type_schema(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kenji/.cache/pypoetry/virtualenvs/app-pkQJO27U-py3.11/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 515, in _unknown_type_schema
    raise PydanticSchemaGenerationError(
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for typing.AsyncGenerator[str, NoneType]. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.

For further information visit https://errors.pydantic.dev/2.10/u/schema-for-unknown-type
marcusschiesser commented 1 day ago

thanks. released 0.3.16 that pins pydantic to <2.10