Skip to content

Commit

Permalink
Env var rename
Browse files Browse the repository at this point in the history
  • Loading branch information
noamgat committed May 4, 2024
1 parent 4167131 commit 32b50cb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ There are two ways to control these heuristics:
There are several environment variables that can be set, that affect the operation of the library. This method is useful when you don't want to modify the code, for example when using the library through the vLLM OpenAI server.

- `LMFE_MAX_CONSECUTIVE_WHITESPACES` - How many consecutive whitespaces are allowed when parsing JsonSchemaObjects. Default: 12.
- `LMFE_FORCE_JSON_FIELD_ORDER` - Should the JsonSchemaParser force the properties to appear in the same order as they appear in the 'required' list of the JsonSchema? (Note: this is consistent with the order of declaration in Pydantic models). Default: False.
- `LMFE_STRICT_JSON_FIELD_ORDER ` - Should the JsonSchemaParser force the properties to appear in the same order as they appear in the 'required' list of the JsonSchema? (Note: this is consistent with the order of declaration in Pydantic models). Default: False.

### Option 2: via the CharacterLevelParserConfig class
When using the library through code, any `CharacterLevelParser` (`JsonSchemaParser`, `RegexParser` etc) constructor receives an optional `CharacterLevelParserConfig` object.
Expand Down
4 changes: 2 additions & 2 deletions lmformatenforcer/characterlevelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Hashable, List, Optional, TypeVar
from .consts import (COMPLETE_ALPHABET, WHITESPACE_CHARACTERS, DEFAULT_MAX_CONSECUTIVE_WHITESPACES,
DEFAULT_FORCE_JSON_FIELD_ORDER, CONFIG_ENV_VAR_MAX_CONSECUTIVE_WHITESPACES,
CONFIG_ENV_VAR_LMFE_FORCE_JSON_FIELD_ORDER)
CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER )


def _parse_bool(s: str) -> bool:
Expand All @@ -25,7 +25,7 @@ class CharacterLevelParserConfig:
max_consecutive_whitespaces: int = _env_or_default_field(CONFIG_ENV_VAR_MAX_CONSECUTIVE_WHITESPACES,
DEFAULT_MAX_CONSECUTIVE_WHITESPACES)
"""How many consective whitespaces the JsonSchemaParser will allow"""
force_json_field_order: bool = _env_or_default_field(CONFIG_ENV_VAR_LMFE_FORCE_JSON_FIELD_ORDER,
force_json_field_order: bool = _env_or_default_field(CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER ,
DEFAULT_FORCE_JSON_FIELD_ORDER)
"""Whether the JsonSchemaParser will force fields to appear in the
order of the 'required' field in the schema"""
Expand Down
2 changes: 1 addition & 1 deletion lmformatenforcer/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"""Environment variable for externally controlling how many consective whitespaces the
JsonSchemaParser will allow. Default: 12"""

CONFIG_ENV_VAR_LMFE_FORCE_JSON_FIELD_ORDER = 'LMFE_FORCE_JSON_FIELD_ORDER'
CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER = 'LMFE_STRICT_JSON_FIELD_ORDER '
"""Environment variable for externally controlling whether the JsonSchemaParser will force
fields to appear in the order of the 'required' field in the schema. Default: false"""
4 changes: 2 additions & 2 deletions tests/test_jsonschemaparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lmformatenforcer import JsonSchemaParser
from enum import Enum
import pytest
from lmformatenforcer.consts import BACKSLASH, BACKSLASH_ESCAPING_CHARACTERS, CONFIG_ENV_VAR_LMFE_FORCE_JSON_FIELD_ORDER, CONFIG_ENV_VAR_MAX_CONSECUTIVE_WHITESPACES
from lmformatenforcer.consts import BACKSLASH, BACKSLASH_ESCAPING_CHARACTERS, CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER , CONFIG_ENV_VAR_MAX_CONSECUTIVE_WHITESPACES

from .common import assert_parser_with_string, CharacterNotAllowedException

Expand Down Expand Up @@ -525,7 +525,7 @@ class TwoRequiredModel(BaseModel):
b: str
c: int = 1
schema = TwoRequiredModel.model_json_schema()
env_var_name = CONFIG_ENV_VAR_LMFE_FORCE_JSON_FIELD_ORDER
env_var_name = CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER
with _temp_replace_env_var(env_var_name, None):
# Check that the default is false
_test_json_schema_parsing_with_string('{"b": "X", "a": 1}', schema, True)
Expand Down

0 comments on commit 32b50cb

Please sign in to comment.