File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -636,7 +636,29 @@ static json oaicompat_chat_params_parse(
636636 throw std::runtime_error (" Failed to download image" );
637637 }
638638
639- } else {
639+ } else if (string_starts_with (url, " file://" )) {
640+ // Strip off the leading "file://"
641+ std::string fname = url.substr (7 );
642+ // load local file path
643+ raw_buffer buf;
644+ FILE * f = fopen (fname.c_str (), " rb" );
645+ if (!f) {
646+ LOG_ERR (" Unable to open file %s: %s\n " , fname.c_str (), strerror (errno));
647+ throw std::runtime_error (" Unable to open image file" );
648+ }
649+ fseek (f, 0 , SEEK_END);
650+ long file_size = ftell (f);
651+ fseek (f, 0 , SEEK_SET);
652+ buf.resize (file_size);
653+ size_t n_read = fread (buf.data (), 1 , file_size, f);
654+ fclose (f);
655+ if (n_read != (size_t )file_size) {
656+ LOG_ERR (" Failed to read entire file %s" , fname.c_str ());
657+ throw std::runtime_error (" Failed to read entire image file" );
658+ }
659+ out_files.push_back (buf);
660+
661+ } else {
640662 // try to decode base64 image
641663 std::vector<std::string> parts = string_split<std::string>(url, /* separator*/ ' ,' );
642664 if (parts.size () != 2 ) {
You can’t perform that action at this time.
0 commit comments