Skip to content

SyntaxError in message_manager.py and PydanticUserError for TypedDict on Windows #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MarcusNeufeldt opened this issue Apr 21, 2025 · 2 comments

Comments

@MarcusNeufeldt
Copy link

When attempting to run the Index agent (either via the Python API or the index run CLI) on Windows, multiple errors occur within the lmnr-index library, preventing it from running.

Environment:

Windows 11
Python version: 3.11.4
Pydantic version: 2.10.6

Steps to Reproduce:

Install lmnr-index: pip install lmnr-index
Install Playwright dependencies: playwright install chromium
Create a .env file with a valid OPENAI_API_KEY.
Attempt to run the agent (e.g., index run).

Expected Behavior:

The Index agent should initialize and run without crashing.

Actual Behavior:

Two distinct errors occur sequentially:
Error 1: SyntaxError in message_manager.py
The first error encountered is:

Traceback (most recent call last):
  # ... traceback ...
  File "C:\\Users\\marcu\\miniconda3\\Lib\\site-packages\\index\\agent\\message_manager.py", line 101
    highlighted_elements += f"{start_tag}{element.text.replace(\'\\n\', \' \')}</{element.tag_name}>\\n"
                  ^
SyntaxError: f-string expression part cannot include a backslash

Cause: Line 101 in index/agent/message_manager.py uses element.text.replace('\n', ' ') directly within an f-string expression, which is not allowed due to the backslash.
Workaround: Manually changing line 101 to perform the .replace() before the f-string resolves this specific error:

# Fix: Perform replace before the f-string
element_text_no_newlines = element.text.replace('\n', ' ')
highlighted_elements += f"{start_tag}{element_text_no_newlines}</{element.tag_name}>\n"

Error 2: PydanticUserError regarding TypedDict
After applying the workaround for Error 1, a second error occurs during Pydantic model processing:

Traceback (most recent call last):
  # ... traceback involving pydantic model construction ...
  File "C:\\Users\\marcu\\miniconda3\\Lib\\site-packages\\index\\agent\\models.py", line 38, in <module> # Or similar Pydantic model definition
    class AgentOutput(BaseModel):
  # ... more pydantic traceback ...
  File "C:\\Users\\marcu\\miniconda3\\Lib\\site-packages\\pydantic\\_internal\\_generate_schema.py", line 1406, in _typed_dict_schema
    raise PydanticUserError(
pydantic.errors.PydanticUserError: Please use `typing_extensions.TypedDict` instead of `typing.TypedDict` on Python < 3.12.

For further information visit https://errors.pydantic.dev/2.10/u/typed-dict-version

Cause: The library (likely in index/agent/models.py or other model files) appears to be using typing.TypedDict which causes compatibility issues with Pydantic on Python versions older than 3.12. Pydantic expects typing_extensions.TypedDict in these cases.
Suggested Fix: Imports of TypedDict from typing should be changed to use typing_extensions.TypedDict instead. The typing-extensions package may need to be added as a dependency if it isn't already.

@skull8888888
Copy link
Collaborator

@MarcusNeufeldt thanks for the issue! I will incorporate the line fix change and will check the TypedDict issue. Keep an eye on a new release. It also would be really helpful if you could install from the working branch to help me test it out, because I don't have the windows machine available.

@skull8888888
Copy link
Collaborator

@MarcusNeufeldt should be fixed with index 0.1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants