-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
/v1/audio/transcriptions
and /v1/audio/translations
wit…
…h whisper.cpp (#276)
- Loading branch information
Showing
18 changed files
with
8,135 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.github/scripts/e2e-test-windows.bat → .github/scripts/e2e-test-llama-windows.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
|
||
## Example run command | ||
# ./linux-and-mac.sh './jan/plugins/@janhq/inference-plugin/dist/nitro/nitro_mac_arm64' https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v0.3-GGUF/resolve/main/tinyllama-1.1b-chat-v0.3.Q2_K.gguf | ||
|
||
# Check for required arguments | ||
if [[ $# -ne 2 ]]; then | ||
echo "Usage: $0 <path_to_binary> <url_to_download>" | ||
exit 1 | ||
fi | ||
|
||
rm /tmp/response1.log /tmp/response2.log /tmp/nitro.log | ||
|
||
BINARY_PATH=$1 | ||
DOWNLOAD_URL=$2 | ||
|
||
# Random port to ensure it's not used | ||
min=10000 | ||
max=11000 | ||
range=$((max - min + 1)) | ||
PORT=$((RANDOM % range + min)) | ||
|
||
# Start the binary file | ||
"$BINARY_PATH" 1 127.0.0.1 $PORT >/tmp/nitro.log 2>&1 & | ||
|
||
# Get the process id of the binary file | ||
pid=$! | ||
|
||
if ! ps -p $pid >/dev/null; then | ||
echo "nitro failed to start. Logs:" | ||
cat /tmp/nitro.log | ||
exit 1 | ||
fi | ||
|
||
# Wait for a few seconds to let the server start | ||
sleep 5 | ||
|
||
# Check if /tmp/testwhisper exists, if not, download it | ||
if [[ ! -f "/tmp/testwhisper" ]]; then | ||
wget $DOWNLOAD_URL -O /tmp/testwhisper | ||
fi | ||
|
||
# Run the curl commands | ||
response1=$(curl -o /tmp/response1.log -s -w "%{http_code}" --location "http://127.0.0.1:$PORT/v1/audio/load_model" \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"model_path": "/tmp/testwhisper", | ||
"model_id": "whisper.cpp" | ||
}' 2>&1) | ||
|
||
response2=$( | ||
curl -o /tmp/response2.log -s -w "%{http_code}" --location "http://127.0.0.1:$PORT/v1/audio/transcriptions" \ | ||
--header 'Access-Control-Allow-Origin: *' \ | ||
--form 'file=@"../whisper.cpp/samples/jfk.wav"' \ | ||
--form 'model_id="whisper.cpp"' \ | ||
--form 'temperature="0.0"' \ | ||
--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."' \ | ||
2>&1 | ||
) | ||
|
||
error_occurred=0 | ||
if [[ "$response1" -ne 200 ]]; then | ||
echo "The first curl command failed with status code: $response1" | ||
cat /tmp/response1.log | ||
error_occurred=1 | ||
fi | ||
|
||
if [[ "$response2" -ne 200 ]]; then | ||
echo "The second curl command failed with status code: $response2" | ||
cat /tmp/response2.log | ||
error_occurred=1 | ||
fi | ||
|
||
if [[ "$error_occurred" -eq 1 ]]; then | ||
echo "Nitro test run failed!!!!!!!!!!!!!!!!!!!!!!" | ||
echo "Nitro Error Logs:" | ||
cat /tmp/nitro.log | ||
kill $pid | ||
exit 1 | ||
fi | ||
|
||
echo "----------------------" | ||
echo "Log load model:" | ||
cat /tmp/response1.log | ||
|
||
echo "----------------------" | ||
echo "Log run test:" | ||
cat /tmp/response2.log | ||
|
||
echo "Nitro test run successfully!" | ||
|
||
# Kill the server process | ||
kill $pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
@echo off | ||
|
||
set "TEMP=C:\Users\%UserName%\AppData\Local\Temp" | ||
set "MODEL_PATH=%TEMP%\testwhisper" | ||
|
||
rem Check for required arguments | ||
if "%~2"=="" ( | ||
echo Usage: %~0 ^<path_to_binary^> ^<url_to_download^> | ||
exit /b 1 | ||
) | ||
|
||
set "BINARY_PATH=%~1" | ||
set "DOWNLOAD_URL=%~2" | ||
|
||
for %%i in ("%BINARY_PATH%") do set "BINARY_NAME=%%~nxi" | ||
|
||
echo BINARY_NAME=%BINARY_NAME% | ||
|
||
del %TEMP%\response1.log 2>nul | ||
del %TEMP%\response2.log 2>nul | ||
del %TEMP%\nitro.log 2>nul | ||
|
||
set /a min=9999 | ||
set /a max=11000 | ||
set /a range=max-min+1 | ||
set /a PORT=%min% + %RANDOM% %% %range% | ||
|
||
rem Start the binary file | ||
start /B "" "%BINARY_PATH%" 1 "127.0.0.1" %PORT% > %TEMP%\nitro.log 2>&1 | ||
|
||
ping -n 6 127.0.0.1 %PORT% > nul | ||
|
||
rem Capture the PID of the started process with "nitro" in its name | ||
for /f "tokens=2" %%a in ('tasklist /fi "imagename eq %BINARY_NAME%" /fo list ^| findstr /B "PID:"') do ( | ||
set "pid=%%a" | ||
) | ||
|
||
echo pid=%pid% | ||
|
||
if not defined pid ( | ||
echo nitro failed to start. Logs: | ||
type %TEMP%\nitro.log | ||
exit /b 1 | ||
) | ||
|
||
rem Wait for a few seconds to let the server start | ||
|
||
rem Check if %TEMP%\testmodel exists, if not, download it | ||
if not exist "%MODEL_PATH%" ( | ||
bitsadmin.exe /transfer "DownloadTestModel" %DOWNLOAD_URL% "%MODEL_PATH%" | ||
) | ||
|
||
rem Define JSON strings for curl data | ||
call set "MODEL_PATH_STRING=%%MODEL_PATH:\=\\%%" | ||
set "curl_data1={\"model_path\":\"%MODEL_PATH_STRING%\",\"model_id\":\"whisper.cpp\"}" | ||
|
||
rem Print the values of curl_data1 for debugging | ||
echo curl_data1=%curl_data1% | ||
|
||
rem Run the curl commands and capture the status code | ||
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 | ||
|
||
curl.exe -o %TEMP%\response2.log -s -w "%%{http_code}" --location "http://127.0.0.1:%PORT%/v1/audio/transcriptions" ^ | ||
--header "Access-Control-Allow-Origin: *" ^ | ||
--form 'model_id="whisper.cpp"' ^ | ||
--form 'file=@"..\whisper.cpp\samples\jfk.wav"' ^ | ||
--form 'temperature="0.0"' ^ | ||
--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."' ^ | ||
> %TEMP%\response2_code.log 2>&1 | ||
|
||
set "error_occurred=0" | ||
|
||
rem Read the status codes from the log files | ||
for /f %%a in (%TEMP%\response1_code.log) do set "response1=%%a" | ||
for /f %%a in (%TEMP%\response2_code.log) do set "response2=%%a" | ||
|
||
if "%response1%" neq "200" ( | ||
echo The first curl command failed with status code: %response1% | ||
type %TEMP%\response1.log | ||
set "error_occurred=1" | ||
) | ||
|
||
if "%response2%" neq "200" ( | ||
echo The second curl command failed with status code: %response2% | ||
type %TEMP%\response2.log | ||
set "error_occurred=1" | ||
) | ||
|
||
if "%error_occurred%"=="1" ( | ||
echo Nitro test run failed!!!!!!!!!!!!!!!!!!!!!! | ||
echo Nitro Error Logs: | ||
type %TEMP%\nitro.log | ||
taskkill /f /pid %pid% | ||
exit /b 1 | ||
) | ||
|
||
|
||
echo ---------------------- | ||
echo Log load model: | ||
type %TEMP%\response1.log | ||
|
||
echo ---------------------- | ||
echo "Log run test:" | ||
type %TEMP%\response2.log | ||
|
||
echo Nitro test run successfully! | ||
|
||
rem Kill the server process | ||
taskkill /f /pid %pid% |
Oops, something went wrong.