forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Frontend] Add backend-specific options for guided decoding (vllm-pro…
…ject#13505) Signed-off-by: Joe Runde <[email protected]>
- Loading branch information
Showing
8 changed files
with
123 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
from enum import Enum | ||
|
||
from openai import OpenAI | ||
from openai import BadRequestError, OpenAI | ||
from pydantic import BaseModel | ||
|
||
client = OpenAI( | ||
|
@@ -94,3 +94,26 @@ class CarDescription(BaseModel): | |
extra_body={"guided_grammar": simplified_sql_grammar}, | ||
) | ||
print(completion.choices[0].message.content) | ||
|
||
# Extra backend options | ||
prompt = ("Generate an email address for Alan Turing, who works in Enigma." | ||
"End in .com and new line. Example result:" | ||
"[email protected]\n") | ||
|
||
try: | ||
# The no-fallback option forces vLLM to use xgrammar, so when it fails | ||
# you get a 400 with the reason why | ||
completion = client.chat.completions.create( | ||
model="Qwen/Qwen2.5-3B-Instruct", | ||
messages=[{ | ||
"role": "user", | ||
"content": prompt, | ||
}], | ||
extra_body={ | ||
"guided_regex": "\w+@\w+\.com\n", | ||
"stop": ["\n"], | ||
"guided_decoding_backend": "xgrammar:no-fallback" | ||
}, | ||
) | ||
except BadRequestError as e: | ||
print("This error is expected:", e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters