[Bugfix][Structured Output] Decode choice specs as JSON in outlines and LMFE (#60748)
Signed-off-by: hpdkhoa <hpdkhoa2311@gmail.com> Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import ast
|
||||
import json
|
||||
from dataclasses import dataclass, field
|
||||
from functools import lru_cache
|
||||
@@ -117,7 +116,7 @@ class LMFormatEnforcerBackend(StructuredOutputBackend):
|
||||
grammar_spec,
|
||||
)
|
||||
elif request_type == StructuredOutputOptions.CHOICE:
|
||||
choices = ast.literal_eval(grammar_spec)
|
||||
choices = json.loads(grammar_spec)
|
||||
character_level_parser = lmformatenforcer.UnionParser(
|
||||
[lmformatenforcer.StringParser(choice) for choice in choices]
|
||||
)
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import json
|
||||
from dataclasses import dataclass, field
|
||||
from re import _constants, _parser # type: ignore[attr-defined]
|
||||
@@ -68,7 +67,7 @@ class OutlinesBackend(StructuredOutputBackend):
|
||||
elif request_type == StructuredOutputOptions.REGEX:
|
||||
regex = grammar_spec
|
||||
elif request_type == StructuredOutputOptions.CHOICE:
|
||||
choices = ast.literal_eval(grammar_spec)
|
||||
choices = json.loads(grammar_spec)
|
||||
choices = [regex_escape(c) for c in choices]
|
||||
regex = "(" + "|".join(choices) + ")"
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user