@@ -183,6 +183,7 @@ struct server_task {
183183
184184    static  slot_params params_from_json_cmpl (
185185            const  llama_model * model,
186+             const  llama_context * ctx,
186187            const  common_params & params_base,
187188            const  json & data) {
188189        slot_params params;
@@ -237,8 +238,27 @@ struct server_task {
237238        params.speculative .n_min  = std::max (params.speculative .n_min , 2 );
238239        params.speculative .n_max  = std::max (params.speculative .n_max , 0 );
239240
241+         //  TODO: add more sanity checks for the input parameters
242+ 
243+         if  (params.sampling .penalty_last_n  < -1 ) {
244+             throw  std::runtime_error (" Error: repeat_last_n must be >= -1"  );
245+         }
246+ 
247+         if  (params.sampling .dry_penalty_last_n  < -1 ) {
248+             throw  std::runtime_error (" Error: dry_penalty_last_n must be >= -1"  );
249+         }
250+ 
251+         if  (params.sampling .penalty_last_n  == -1 ) {
252+             //  note: should be the slot's context and not the full context, but it's ok
253+             params.sampling .penalty_last_n  = llama_n_ctx (ctx);
254+         }
255+ 
256+         if  (params.sampling .dry_penalty_last_n  == -1 ) {
257+             params.sampling .dry_penalty_last_n  = llama_n_ctx (ctx);
258+         }
259+ 
240260        if  (params.sampling .dry_base  < 1 .0f ) {
241-            params.sampling .dry_base  = defaults.sampling .dry_base ;
261+              params.sampling .dry_base  = defaults.sampling .dry_base ;
242262        }
243263
244264        //  sequence breakers for DRY
@@ -3379,7 +3399,7 @@ int main(int argc, char ** argv) {
33793399                task.index  = i;
33803400
33813401                task.prompt_tokens     = std::move (tokenized_prompts[i]);
3382-                 task.params            = server_task::params_from_json_cmpl (ctx_server.model , ctx_server.params_base , data);
3402+                 task.params            = server_task::params_from_json_cmpl (ctx_server.model , ctx_server.ctx , ctx_server. params_base , data);
33833403                task.id_selected_slot  = json_value (data, " id_slot"  , -1 );
33843404
33853405                //  OAI-compat
0 commit comments