Skip to content

Commit

Permalink
Allow json integers to be negative (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
posionus authored Apr 1, 2024
1 parent 1d20896 commit ce06900
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions outlines/fsm/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

STRING_INNER = r'(?:[^"\\\x00-\x1f\x7f-\x9f]|\\.)'
STRING = f'"{STRING_INNER}*"'
INTEGER = r"(0|[1-9][0-9]*)"
NUMBER = rf"(-)?({INTEGER})(\.[0-9]+)?([eE][+-][0-9]+)?"
INTEGER = r"(-)?(0|[1-9][0-9]*)"
NUMBER = rf"({INTEGER})(\.[0-9]+)?([eE][+-][0-9]+)?"
BOOLEAN = r"(true|false)"
NULL = r"null"
WHITESPACE = r"[\n ]*"
Expand Down
4 changes: 2 additions & 2 deletions tests/fsm/test_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class User(BaseModel):
[
({"integer": "0"}, True),
({"integer": "1"}, True),
({"integer": "-1"}, False),
({"integer": "-1"}, True),
({"integer": "01"}, False),
({"integer": "1.3"}, False),
({"integer": "t"}, False),
Expand Down Expand Up @@ -207,7 +207,7 @@ def test_match_number(pattern, does_match):
"properties": {"count": {"title": "Count", "type": "integer"}},
"required": ["count"],
},
'\\{[\\n ]*"count"[\\n ]*:[\\n ]*(0|[1-9][0-9]*)[\\n ]*\\}',
'\\{[\\n ]*"count"[\\n ]*:[\\n ]*(-)?(0|[1-9][0-9]*)[\\n ]*\\}',
[('{\n "count": 100\n}', True)],
),
# array
Expand Down

0 comments on commit ce06900

Please sign in to comment.