@@ -147,7 +147,7 @@ struct server_slot {
147147 int32_t n_prompt_tokens = 0 ;
148148 int32_t n_prompt_tokens_processed = 0 ;
149149
150- std::string prompt;
150+ json prompt; // can be either a string, array of strings or array of token ids
151151
152152 // when a task is submitted, we first tokenize the prompt and store it here
153153 std::vector<llama_token> prompt_tokens;
@@ -822,8 +822,13 @@ struct server_context {
822822 continue ;
823823 }
824824
825+ // skip the slot if it does not contains prompt
826+ if (!slot.prompt .is_string ()) {
827+ continue ;
828+ }
829+
825830 // current slot's prompt
826- std::string slot_prompt = slot.prompt ;
831+ std::string slot_prompt = slot.prompt . get <std::string>() ;
827832
828833 // length of the current slot's prompt
829834 int slot_prompt_len = slot_prompt.size ();
@@ -957,12 +962,12 @@ struct server_context {
957962 return false ;
958963 }
959964
960- if (prompt->is_string ()) {
961- slot. prompt = prompt->get <std::string>();
962- } else if (prompt->is_array () && prompt->size () == 1 && prompt->at (0 ).is_string ( )) {
963- slot.prompt = prompt-> at ( 0 ). get <std::string>() ;
965+ if (( prompt->is_string ()) ||
966+ ( prompt-> is_array () && prompt-> size () == 1 && prompt->at ( 0 ). is_string ()) ||
967+ (prompt->is_array () && ! prompt->empty () && prompt->at (0 ).is_number_integer () )) {
968+ slot.prompt = * prompt;
964969 } else {
965- send_error (task, " \" prompt\" must be a string or an array of strings " , ERROR_TYPE_INVALID_REQUEST);
970+ send_error (task, " \" prompt\" must be a string or an array of integers " , ERROR_TYPE_INVALID_REQUEST);
966971 return false ;
967972 }
968973 }
0 commit comments