Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: JSON schema for guided generation now optionally respects field order #264

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/python/lorax/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
from pydantic import BaseModel, validator, Field, ConfigDict
from typing import Optional, List, Dict, Any
from typing import Optional, List, Dict, Any, OrderedDict, Union

from lorax.errors import ValidationError

Expand Down Expand Up @@ -64,7 +64,7 @@ class ResponseFormat(BaseModel):
model_config = ConfigDict(use_enum_values=True)

type: ResponseFormatType
schema_spec: Dict[str, Any] = Field(alias="schema")
schema_spec: Union[Dict[str, Any], OrderedDict] = Field(alias="schema")


class Parameters(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion launcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ clap = { version = "4.1.4", features = ["derive", "env"] }
ctrlc = { version = "3.2.5", features = ["termination"] }
nix = "0.26.2"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
serde_json = { version = "1.0.93", features = ["preserve_order"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = ["json", "env-filter"] }

Expand Down
2 changes: 1 addition & 1 deletion router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ opentelemetry-otlp = "0.12.0"
rand = "0.8.5"
reqwest = { version = "0.11.14", features = [] }
serde = "1.0.152"
serde_json = "1.0.93"
serde_json = { version = "1.0.93", features = ["preserve_order"] }
thiserror = "1.0.38"
tokenizers = "0.13.4"
tokio = { version = "1.25.0", features = ["rt", "rt-multi-thread", "parking_lot", "signal", "sync"] }
Expand Down
1 change: 1 addition & 0 deletions server/lorax_server/utils/logits_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def __init__(self, schema: str, tokenizer: PreTrainedTokenizerBase):
self.tokenizer = self.adapt_tokenizer(tokenizer)

regex_string = build_regex_from_object(schema)
regex_string = '[\\n ]*' + regex_string # Hack to allow preceding whitespace
self.fsm = RegexFSM(regex_string, tokenizer)

self.fsm_state = FSMState(0)
Expand Down
2 changes: 1 addition & 1 deletion server/tests/models/test_causal_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_causal_lm_batch_type(default_causal_lm):

@pytest.mark.parametrize("causal_lm_batch, generated_token_id", [
("default_causal_lm_batch", 13),
("schema_constrained_causal_lm_batch", 90),
("schema_constrained_causal_lm_batch", 198),
])
def test_causal_lm_generate_token(default_causal_lm, causal_lm_batch, generated_token_id, request):
causal_lm_batch = request.getfixturevalue(causal_lm_batch)
Expand Down
Loading