Fixed decimal prompt weights without leading digit (#1182)

The regex was not accounting properly for prompt weights that didn't begin with a leading number such as .5 or .1 and was instead splitting those off into their own prompt which got everything all screwed up.

For example, the prompt string of "Fruit:1 grapes:-.5" should parse as
[('Fruit', 1.0), ('grapes', -.5)]
but was being incorrectly parsed as
[('Fruit', 1.0), ('grapes', 1.0), ('-.5', 1.0)]

This fixes that by making the regex properly catch decimals.
This commit is contained in:
bryanlyon 2022-09-16 12:42:41 -07:00 committed by GitHub
parent 4ae7a5805c
commit b5462536f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1519,7 +1519,7 @@ prompt_parser = re.compile("""
(?: # non-capture group
:+ # match one or more ':' characters
(?P<weight> # capture group for 'weight'
-?\d+(?:\.\d+)? # match positive or negative integer or decimal number
-?\d*\.{0,1}\d+ # match positive or negative integer or decimal number
)? # end weight capture group, make optional
\s* # strip spaces after weight
| # OR