Skip to content

Commit

Permalink
0.6.4 - Min/Max string length
Browse files Browse the repository at this point in the history
  • Loading branch information
noamgat committed Nov 15, 2023
1 parent 8490345 commit 6367724
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# LM Format Enforcer Changelog

## v0.6.4
- JSON Schema : Supports string min/max length limitation

## v0.6.3
- Community PR: Fixed SequenceParser bug

Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lm-format-enforcer"
version = "0.6.3"
version = "0.6.4"
description = "Enforce the output format (JSON Schema, Regex etc) of a language model"
authors = ["Noam Gat <[email protected]>"]
license = "MIT"
Expand All @@ -14,7 +14,6 @@ classifiers = [
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
10 changes: 5 additions & 5 deletions tests/test_jsonschemaparser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from typing import Annotated, Dict, List, Optional
from pydantic import BaseModel, Field, StringConstraints
from typing import Dict, List, Optional
from pydantic import BaseModel, Field
from lmformatenforcer import JsonSchemaParser
from enum import Enum
import pytest
Expand Down Expand Up @@ -223,11 +223,11 @@ class SomeSchema(BaseModel):

def test_string_length_limitation():
class SomeSchema(BaseModel):
key: Annotated[str, StringConstraints(min_length=2, max_length=3)]
# This is the elegant way to do it, but requires python >=3.9, we want to support 3.8
# key: Annotated[str, StringConstraints(min_length=2, max_length=3)]
key: str = Field(..., min_length=2, max_length=3)

for str_length in range(10):
test_string = f'{{"key": "{str_length * "a"}"}}'
expect_sucess = 2 <= str_length <= 3
_test_json_schema_parsing_with_string(test_string, SomeSchema.schema(), expect_sucess)


0 comments on commit 6367724

Please sign in to comment.