[V1] Update structured output (#16812)

Signed-off-by: reidliu41 <reid201711@gmail.com>
Co-authored-by: reidliu41 <reid201711@gmail.com>
This commit is contained in:
Reid
2025-04-24 14:57:17 +08:00
committed by GitHub
parent 6167c0e5d2
commit db2f8d915c
4 changed files with 27 additions and 27 deletions

View File

@@ -33,7 +33,7 @@ completion = client.chat.completions.create(
"content": prompt,
}],
extra_body={
"guided_regex": "\w+@\w+\.com\n",
"guided_regex": r"\w+@\w+\.com\n",
"stop": ["\n"]
},
)
@@ -70,17 +70,17 @@ print(completion.choices[0].message.content)
# Guided decoding by Grammar
simplified_sql_grammar = """
?start: select_statement
root ::= select_statement
?select_statement: "SELECT " column_list " FROM " table_name
select_statement ::= "SELECT " column " from " table " where " condition
?column_list: column_name ("," column_name)*
column ::= "col_1 " | "col_2 "
?table_name: identifier
table ::= "table_1 " | "table_2 "
?column_name: identifier
condition ::= column "= " number
?identifier: /[a-zA-Z_][a-zA-Z0-9_]*/
number ::= "1 " | "2 "
"""
prompt = ("Generate an SQL query to show the 'username' and 'email'"
@@ -110,7 +110,7 @@ try:
"content": prompt,
}],
extra_body={
"guided_regex": "\w+@\w+\.com\n",
"guided_regex": r"\w+@\w+\.com\n",
"stop": ["\n"],
"guided_decoding_backend": "xgrammar:no-fallback"
},