• Devon Rifkin's avatar
    parsers: fix `&`s in qwen3coder parameter values · 242df70a
    Devon Rifkin authored
    In <https://github.com/ollama/ollama/issues/12357> we that the model
    will output tool calls such as
    
    ```
    <function=shell>
    <parameter=command>
    pwd && ls -la
    </parameter>
    </function>
    ```
    
    We parse this using the approach of transforming into valid xml and then
    using an xml parser. While we do transform the function and parameter
    names, we weren't escaping the parameter values (which in this example
    are invalid since `pwd && ls -la` contains unescaped ampersands).
    
    This has been fixed by first transforming the tags in the same way, and
    then walking the transformed string and escaping the text in between the
    tags. This also fixes a case where `<` in the middle of a parameter
    value would cause an xml parse failure.
    
    Fixes: #12357
    242df70a
qwen3coder_test.go 21.2 KB