Skip to content

Bug: pydantic_models_to_grammar_examples.py is broken #8471

@maruel

Description

@maruel

What happened?

3fd62a6 by @compilade broke pydantic_models_to_grammar.py

@jaime-m-p FYI

Name and Version

Reproduced on:

  • python 3.10.12 on Ubuntu 22.04.4 LTS
  • python 3.12.2 on macOS 14.5

The regression occurred in 3fd62a6

What operating system are you seeing the problem on?

Linux, Mac

Relevant log output

# Start a server
./llama-server --model ./models/Mistral-7B-Instruct-v0.3.fp16.gguf -ngl 9999 --port 8080

# Commands
python3 -m venv venv
source venv/bin/activate
pip install docstring_parser pydantic requests
cd examples
python3 pydantic_models_to_grammar_examples.py

# Outputs
Traceback (most recent call last):
  File "$HOME/llama.cpp/examples/pydantic_models_to_grammar_examples.py", line 75, in <module>
    gbnf_grammar, documentation = generate_gbnf_grammar_and_documentation(
  File "$HOME/llama.cpp/examples/pydantic_models_to_grammar.py", line 1080, in generate_gbnf_grammar_and_documentation
    documentation = generate_markdown_documentation(
  File "/$HOME/llama.cpp/examples/pydantic_models_to_grammar.py", line 721, in generate_markdown_documentation
    documentation += generate_field_markdown(
  File "$HOME/llama.cpp/examples/pydantic_models_to_grammar.py", line 775, in generate_field_markdown
    field_text = f"{indent}{field_name} ({format_model_and_field_name(field_type.__name__)})"
AttributeError: 'str' object has no attribute '__name__'. Did you mean: '__ne__'?

# Trying previous version:
git checkout 3fd62a6b1c9ca7b7c0093e984cc9c133c6f2726d~1
python3 pydantic_models_to_grammar_examples.py

# (Success on python3.12, different error on python3.10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug-unconfirmedlow severityUsed to report low severity bugs in llama.cpp (e.g. cosmetic issues, non critical UI glitches)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions