@@ -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
- json prompt;
150
+ std::string prompt;
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,13 +822,8 @@ 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
-
830
825
// current slot's prompt
831
- std::string slot_prompt = slot.prompt . get <std::string>() ;
826
+ std::string slot_prompt = slot.prompt ;
832
827
833
828
// length of the current slot's prompt
834
829
int slot_prompt_len = slot_prompt.size ();
@@ -958,13 +953,16 @@ struct server_context {
958
953
if (!task.infill ) {
959
954
const auto & prompt = data.find (" prompt" );
960
955
if (prompt == data.end ()) {
961
- send_error (task, " Either \" prompt\" or \" messages \" must be provided" , ERROR_TYPE_INVALID_REQUEST);
956
+ send_error (task, " \" prompt\" must be provided" , ERROR_TYPE_INVALID_REQUEST);
962
957
return false ;
963
- } else {
964
- slot.prompt = *prompt;
965
958
}
966
- if (slot.prompt .is_array () && slot.prompt .size () == 0 ) {
967
- send_error (task, " \" prompt\" cannot be an empty array" , ERROR_TYPE_INVALID_REQUEST);
959
+
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>();
964
+ } else {
965
+ send_error (task, " \" prompt\" must be a string or an array of strings" , ERROR_TYPE_INVALID_REQUEST);
968
966
return false ;
969
967
}
970
968
}
@@ -1582,14 +1580,18 @@ struct server_context {
1582
1580
switch (task.type ) {
1583
1581
case SERVER_TASK_TYPE_COMPLETION:
1584
1582
{
1585
- int id_slot = json_value (task.data , " id_slot" , -1 );
1586
- std::string prompt = json_value (task.data , " prompt" , std::string ());
1583
+ const int id_slot = json_value (task.data , " id_slot" , -1 );
1587
1584
1588
1585
server_slot * slot;
1589
1586
1590
1587
if (id_slot != -1 ) {
1591
1588
slot = get_slot_by_id (id_slot);
1592
1589
} else {
1590
+ std::string prompt;
1591
+ if (task.data .contains (" prompt" ) && task.data .at (" prompt" ).is_string ()) {
1592
+ json_value (task.data , " prompt" , std::string ());
1593
+ }
1594
+
1593
1595
slot = get_available_slot (prompt);
1594
1596
}
1595
1597
0 commit comments