@@ -819,26 +819,26 @@ json oaicompat_chat_params_parse(
819819 auto schema_wrapper = json_value (response_format, " json_schema" , json::object ());
820820 json_schema = json_value (schema_wrapper, " schema" , json::object ());
821821 } else if (!response_type.empty () && response_type != " text" ) {
822- throw std::runtime_error (" response_format type must be one of \" text\" or \" json_object\" , but got: " + response_type);
822+ throw std::invalid_argument (" response_format type must be one of \" text\" or \" json_object\" , but got: " + response_type);
823823 }
824824 }
825825
826826 // get input files
827827 if (!body.contains (" messages" )) {
828- throw std::runtime_error (" 'messages' is required" );
828+ throw std::invalid_argument (" 'messages' is required" );
829829 }
830830 json & messages = body.at (" messages" );
831831 if (!messages.is_array ()) {
832- throw std::runtime_error (" Expected 'messages' to be an array" );
832+ throw std::invalid_argument (" Expected 'messages' to be an array" );
833833 }
834834 for (auto & msg : messages) {
835835 std::string role = json_value (msg, " role" , std::string ());
836836 if (role != " assistant" && !msg.contains (" content" )) {
837- throw std::runtime_error (" All non-assistant messages must contain 'content'" );
837+ throw std::invalid_argument (" All non-assistant messages must contain 'content'" );
838838 }
839839 if (role == " assistant" ) {
840840 if (!msg.contains (" content" ) && !msg.contains (" tool_calls" )) {
841- throw std::runtime_error (" Assistant message must contain either 'content' or 'tool_calls'!" );
841+ throw std::invalid_argument (" Assistant message must contain either 'content' or 'tool_calls'!" );
842842 }
843843 if (!msg.contains (" content" )) {
844844 continue ; // avoid errors with no content
@@ -850,7 +850,7 @@ json oaicompat_chat_params_parse(
850850 }
851851
852852 if (!content.is_array ()) {
853- throw std::runtime_error (" Expected 'content' to be a string or an array" );
853+ throw std::invalid_argument (" Expected 'content' to be a string or an array" );
854854 }
855855
856856 for (auto & p : content) {
@@ -884,11 +884,11 @@ json oaicompat_chat_params_parse(
884884 // try to decode base64 image
885885 std::vector<std::string> parts = string_split<std::string>(url, /* separator*/ ' ,' );
886886 if (parts.size () != 2 ) {
887- throw std::runtime_error (" Invalid image_url.url value" );
887+ throw std::invalid_argument (" Invalid image_url.url value" );
888888 } else if (!string_starts_with (parts[0 ], " data:image/" )) {
889- throw std::runtime_error (" Invalid image_url.url format: " + parts[0 ]);
889+ throw std::invalid_argument (" Invalid image_url.url format: " + parts[0 ]);
890890 } else if (!string_ends_with (parts[0 ], " base64" )) {
891- throw std::runtime_error (" image_url.url must be base64 encoded" );
891+ throw std::invalid_argument (" image_url.url must be base64 encoded" );
892892 } else {
893893 auto base64_data = parts[1 ];
894894 auto decoded_data = base64_decode (base64_data);
@@ -911,7 +911,7 @@ json oaicompat_chat_params_parse(
911911 std::string format = json_value (input_audio, " format" , std::string ());
912912 // while we also support flac, we don't allow it here so we matches the OAI spec
913913 if (format != " wav" && format != " mp3" ) {
914- throw std::runtime_error (" input_audio.format must be either 'wav' or 'mp3'" );
914+ throw std::invalid_argument (" input_audio.format must be either 'wav' or 'mp3'" );
915915 }
916916 auto decoded_data = base64_decode (data); // expected to be base64 encoded
917917 out_files.push_back (decoded_data);
@@ -922,7 +922,7 @@ json oaicompat_chat_params_parse(
922922 p.erase (" input_audio" );
923923
924924 } else if (type != " text" ) {
925- throw std::runtime_error (" unsupported content[].type" );
925+ throw std::invalid_argument (" unsupported content[].type" );
926926 }
927927 }
928928 }
@@ -940,7 +940,7 @@ json oaicompat_chat_params_parse(
940940 inputs.enable_thinking = opt.enable_thinking ;
941941 if (!inputs.tools .empty () && inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_NONE) {
942942 if (body.contains (" grammar" )) {
943- throw std::runtime_error (" Cannot use custom grammar constraints with tools." );
943+ throw std::invalid_argument (" Cannot use custom grammar constraints with tools." );
944944 }
945945 llama_params[" parse_tool_calls" ] = true ;
946946 }
@@ -959,7 +959,7 @@ json oaicompat_chat_params_parse(
959959 } else if (enable_thinking_kwarg == " false" ) {
960960 inputs.enable_thinking = false ;
961961 } else if (!enable_thinking_kwarg.empty () && enable_thinking_kwarg[0 ] == ' "' ) {
962- throw std::runtime_error (" invalid type for \" enable_thinking\" (expected boolean, got string)" );
962+ throw std::invalid_argument (" invalid type for \" enable_thinking\" (expected boolean, got string)" );
963963 }
964964
965965 // if the assistant message appears at the end of list, we do not add end-of-turn token
@@ -972,14 +972,14 @@ json oaicompat_chat_params_parse(
972972
973973 /* sanity check, max one assistant message at the end of the list */
974974 if (!inputs.messages .empty () && inputs.messages .back ().role == " assistant" ){
975- throw std::runtime_error (" Cannot have 2 or more assistant messages at the end of the list." );
975+ throw std::invalid_argument (" Cannot have 2 or more assistant messages at the end of the list." );
976976 }
977977
978978 /* TODO: test this properly */
979979 inputs.reasoning_format = COMMON_REASONING_FORMAT_NONE;
980980
981981 if ( inputs.enable_thinking ) {
982- throw std::runtime_error (" Assistant response prefill is incompatible with enable_thinking." );
982+ throw std::invalid_argument (" Assistant response prefill is incompatible with enable_thinking." );
983983 }
984984
985985 inputs.add_generation_prompt = true ;
@@ -1020,18 +1020,18 @@ json oaicompat_chat_params_parse(
10201020 // Handle "n" field
10211021 int n_choices = json_value (body, " n" , 1 );
10221022 if (n_choices != 1 ) {
1023- throw std::runtime_error (" Only one completion choice is allowed" );
1023+ throw std::invalid_argument (" Only one completion choice is allowed" );
10241024 }
10251025
10261026 // Handle "logprobs" field
10271027 // TODO: The response format of this option is not yet OAI-compatible, but seems like no one really using it; We may need to fix it in the future
10281028 if (json_value (body, " logprobs" , false )) {
10291029 if (has_tools && stream) {
1030- throw std::runtime_error (" logprobs is not supported with tools + stream" );
1030+ throw std::invalid_argument (" logprobs is not supported with tools + stream" );
10311031 }
10321032 llama_params[" n_probs" ] = json_value (body, " top_logprobs" , 20 );
10331033 } else if (body.contains (" top_logprobs" ) && !body.at (" top_logprobs" ).is_null ()) {
1034- throw std::runtime_error (" top_logprobs requires logprobs to be set to true" );
1034+ throw std::invalid_argument (" top_logprobs requires logprobs to be set to true" );
10351035 }
10361036
10371037 // Copy remaining properties to llama_params
0 commit comments