From 6367724b69773c456772dd9e2eea71e44fe22f5f Mon Sep 17 00:00:00 2001 From: Noam Gat Date: Wed, 15 Nov 2023 09:23:04 +0200 Subject: [PATCH] 0.6.4 - Min/Max string length --- CHANGELOG.md | 3 +++ pyproject.toml | 3 +-- tests/test_jsonschemaparser.py | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ff382c..8cc5688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index dd77288..fd26b3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT" @@ -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", diff --git a/tests/test_jsonschemaparser.py b/tests/test_jsonschemaparser.py index b8bb10f..d087bcc 100644 --- a/tests/test_jsonschemaparser.py +++ b/tests/test_jsonschemaparser.py @@ -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 @@ -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) - - \ No newline at end of file