@@ -147,7 +147,7 @@ struct server_slot {
147
147
int32_t n_prompt_tokens = 0 ;
148
148
int32_t n_prompt_tokens_processed = 0 ;
149
149
150
- std::string prompt;
150
+ json prompt; // can be either a string, array of strings or array of token ids
151
151
152
152
// when a task is submitted, we first tokenize the prompt and store it here
153
153
std::vector<llama_token> prompt_tokens;
@@ -822,8 +822,13 @@ struct server_context {
822
822
continue ;
823
823
}
824
824
825
+ // skip the slot if it does not contains prompt
826
+ if (!slot.prompt .is_string ()) {
827
+ continue ;
828
+ }
829
+
825
830
// current slot's prompt
826
- std::string slot_prompt = slot.prompt ;
831
+ std::string slot_prompt = slot.prompt . get <std::string>() ;
827
832
828
833
// length of the current slot's prompt
829
834
int slot_prompt_len = slot_prompt.size ();
@@ -957,12 +962,12 @@ struct server_context {
957
962
return false ;
958
963
}
959
964
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;
964
969
} 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);
966
971
return false ;
967
972
}
968
973
}
0 commit comments