Repository navigation
Preserve YAML layout when adding OpenAI endpoints - #1865
Conversation
Code Review Bot — PR #18650 patch(es) generated for
|
chrikrah
left a comment
There was a problem hiding this comment.
@wsj040303 From my perspective this can be merged. It matches the indent it finds, which answers the question in #1864, and the repro from that issue now loads both models:
# git archive f605dcf673 (base 39d3254), Python 3.13.5, llm.__file__ from the export
$ llm openai endpoint add http://localhost:11434/v1 -m qwen3 --id local-b && llm models
(base, list indented by 2) -> yaml.parser.ParserError: expected '<document start>', but found '<block sequence start>'
(head, list indented by 2) -> OpenAI Chat: local-a, OpenAI Chat: local-b
(base, list ending in ...) -> the same ParserError
(head, list ending in ...) -> both models, `...` still the last line
$ pytest -q tests/test_openai_endpoint_add.py
(head) -> 34 passed
(head, openai_models.py from 39d3254) -> 11 failed, 23 passed
$ pytest -q
(head) -> 1413 passed
(base) -> 1400 passed
# _append_extra_model at head, reloaded with yaml.safe_load: a comment line above the list, `---` above an
# indented list and a model_name of "a\n\nb" all come back intact
# not run: Windows
|
Thanks for this! |
Adding an endpoint to an indented block list wrote the new entry at column zero, leaving
extra-openai-models.yamlunparseable. Appending after an explicit...document end marker caused the same failure, so subsequent model-loading commands stopped working.Preserve the block list's indentation and insert new entries before its document end marker. Read indentation from the block-start token so sequence tags and anchors work too. Existing records, comments and quoting are preserved.
Regression tests cover zero/two/four-space indentation, missing final newlines, trailing comments, document end markers, tagged/anchored lists, empty explicit documents, and repeated additions followed by model loading.
Validation on Linux / Python 3.13:
pytest -q: 1,413 passed.llm modelsandendpoint list --jsonfail before the fix and succeed afterwards.tests/test-llm-load-plugins.shall passed.Fixes #1864