|
| 1 | +@echo off |
| 2 | + |
| 3 | +set "TEMP=C:\Users\%UserName%\AppData\Local\Temp" |
| 4 | +set "MODEL_PATH=%TEMP%\testwhisper" |
| 5 | + |
| 6 | +rem Check for required arguments |
| 7 | +if "%~2"=="" ( |
| 8 | + echo Usage: %~0 ^<path_to_binary^> ^<url_to_download^> |
| 9 | + exit /b 1 |
| 10 | +) |
| 11 | + |
| 12 | +set "BINARY_PATH=%~1" |
| 13 | +set "DOWNLOAD_URL=%~2" |
| 14 | + |
| 15 | +for %%i in ("%BINARY_PATH%") do set "BINARY_NAME=%%~nxi" |
| 16 | + |
| 17 | +echo BINARY_NAME=%BINARY_NAME% |
| 18 | + |
| 19 | +del %TEMP%\response1.log 2>nul |
| 20 | +del %TEMP%\response2.log 2>nul |
| 21 | +del %TEMP%\nitro.log 2>nul |
| 22 | + |
| 23 | +set /a min=9999 |
| 24 | +set /a max=11000 |
| 25 | +set /a range=max-min+1 |
| 26 | +set /a PORT=%min% + %RANDOM% %% %range% |
| 27 | + |
| 28 | +rem Start the binary file |
| 29 | +start /B "" "%BINARY_PATH%" 1 "127.0.0.1" %PORT% > %TEMP%\nitro.log 2>&1 |
| 30 | + |
| 31 | +ping -n 6 127.0.0.1 %PORT% > nul |
| 32 | + |
| 33 | +rem Capture the PID of the started process with "nitro" in its name |
| 34 | +for /f "tokens=2" %%a in ('tasklist /fi "imagename eq %BINARY_NAME%" /fo list ^| findstr /B "PID:"') do ( |
| 35 | + set "pid=%%a" |
| 36 | +) |
| 37 | + |
| 38 | +echo pid=%pid% |
| 39 | + |
| 40 | +if not defined pid ( |
| 41 | + echo nitro failed to start. Logs: |
| 42 | + type %TEMP%\nitro.log |
| 43 | + exit /b 1 |
| 44 | +) |
| 45 | + |
| 46 | +rem Wait for a few seconds to let the server start |
| 47 | + |
| 48 | +rem Check if %TEMP%\testmodel exists, if not, download it |
| 49 | +if not exist "%MODEL_PATH%" ( |
| 50 | + bitsadmin.exe /transfer "DownloadTestModel" %DOWNLOAD_URL% "%MODEL_PATH%" |
| 51 | +) |
| 52 | + |
| 53 | +rem Define JSON strings for curl data |
| 54 | +call set "MODEL_PATH_STRING=%%MODEL_PATH:\=\\%%" |
| 55 | +set "curl_data1={\"model_path\":\"%MODEL_PATH_STRING%\",\"model_id\":\"whisper.cpp\"}" |
| 56 | + |
| 57 | +rem Print the values of curl_data1 for debugging |
| 58 | +echo curl_data1=%curl_data1% |
| 59 | + |
| 60 | +rem Run the curl commands and capture the status code |
| 61 | +curl.exe -o %TEMP%\response1.log -s -w "%%{http_code}" --location "http://127.0.0.1:%PORT%/v1/audio/load_model" --header "Content-Type: application/json" --data "%curl_data1%" > %TEMP%\response1_code.log 2>&1 |
| 62 | + |
| 63 | +curl.exe -o %TEMP%\response2.log -s -w "%%{http_code}" --location "http://127.0.0.1:%PORT%/v1/audio/transcriptions" ^ |
| 64 | +--header "Access-Control-Allow-Origin: *" ^ |
| 65 | +--form 'model_id="whisper.cpp"' ^ |
| 66 | +--form 'file=@"..\whisper.cpp\samples\jfk.wav"' ^ |
| 67 | +--form 'temperature="0.0"' ^ |
| 68 | +--form 'prompt="The transcript is about OpenAI which makes technology like DALL·E, GPT-3, and ChatGPT with the hope of one day building an AGI system that benefits all of humanity. The president is trying to raly people to support the cause."' ^ |
| 69 | +> %TEMP%\response2_code.log 2>&1 |
| 70 | + |
| 71 | +set "error_occurred=0" |
| 72 | + |
| 73 | +rem Read the status codes from the log files |
| 74 | +for /f %%a in (%TEMP%\response1_code.log) do set "response1=%%a" |
| 75 | +for /f %%a in (%TEMP%\response2_code.log) do set "response2=%%a" |
| 76 | + |
| 77 | +if "%response1%" neq "200" ( |
| 78 | + echo The first curl command failed with status code: %response1% |
| 79 | + type %TEMP%\response1.log |
| 80 | + set "error_occurred=1" |
| 81 | +) |
| 82 | + |
| 83 | +if "%response2%" neq "200" ( |
| 84 | + echo The second curl command failed with status code: %response2% |
| 85 | + type %TEMP%\response2.log |
| 86 | + set "error_occurred=1" |
| 87 | +) |
| 88 | + |
| 89 | +if "%error_occurred%"=="1" ( |
| 90 | + echo Nitro test run failed!!!!!!!!!!!!!!!!!!!!!! |
| 91 | + echo Nitro Error Logs: |
| 92 | + type %TEMP%\nitro.log |
| 93 | + taskkill /f /pid %pid% |
| 94 | + exit /b 1 |
| 95 | +) |
| 96 | + |
| 97 | + |
| 98 | +echo ---------------------- |
| 99 | +echo Log load model: |
| 100 | +type %TEMP%\response1.log |
| 101 | + |
| 102 | +echo ---------------------- |
| 103 | +echo "Log run test:" |
| 104 | +type %TEMP%\response2.log |
| 105 | + |
| 106 | +echo Nitro test run successfully! |
| 107 | + |
| 108 | +rem Kill the server process |
| 109 | +taskkill /f /pid %pid% |
0 commit comments