1515from  vllm  import  LLM , SamplingParams 
1616from  vllm .sampling_params  import  GuidedDecodingParams 
1717
18+ MAX_TOKENS  =  50 
19+ 
1820# Guided decoding by Choice (list of possible options) 
1921guided_decoding_params_choice  =  GuidedDecodingParams (choice = ["Positive" , "Negative" ])
2022sampling_params_choice  =  SamplingParams (guided_decoding = guided_decoding_params_choice )
2325# Guided decoding by Regex 
2426guided_decoding_params_regex  =  GuidedDecodingParams (regex = r"\w+@\w+\.com\n" )
2527sampling_params_regex  =  SamplingParams (
26-     guided_decoding = guided_decoding_params_regex , stop = ["\n " ]
28+     guided_decoding = guided_decoding_params_regex ,
29+     stop = ["\n " ],
30+     max_tokens = MAX_TOKENS ,
2731)
2832prompt_regex  =  (
2933    "Generate an email address for Alan Turing, who works in Enigma." 
@@ -48,7 +52,10 @@ class CarDescription(BaseModel):
4852
4953json_schema  =  CarDescription .model_json_schema ()
5054guided_decoding_params_json  =  GuidedDecodingParams (json = json_schema )
51- sampling_params_json  =  SamplingParams (guided_decoding = guided_decoding_params_json )
55+ sampling_params_json  =  SamplingParams (
56+     guided_decoding = guided_decoding_params_json ,
57+     max_tokens = MAX_TOKENS ,
58+ )
5259prompt_json  =  (
5360    "Generate a JSON with the brand, model and car_type of" 
5461    "the most iconic car from the 90's" 
@@ -64,7 +71,10 @@ class CarDescription(BaseModel):
6471number ::= "1 " | "2 " 
6572""" 
6673guided_decoding_params_grammar  =  GuidedDecodingParams (grammar = simplified_sql_grammar )
67- sampling_params_grammar  =  SamplingParams (guided_decoding = guided_decoding_params_grammar )
74+ sampling_params_grammar  =  SamplingParams (
75+     guided_decoding = guided_decoding_params_grammar ,
76+     max_tokens = MAX_TOKENS ,
77+ )
6878prompt_grammar  =  (
6979    "Generate an SQL query to show the 'username' and 'email'from the 'users' table." 
7080)
0 commit comments