local-ai: use cmake for whisper-cpp

This commit is contained in:
Christian Kögler 2024-03-23 12:44:52 +01:00
parent cc364c7ac9
commit d5f8aa51b9

View File

@ -9,6 +9,7 @@
# needed for audio-to-text # needed for audio-to-text
, ffmpeg , ffmpeg
, cmake , cmake
, pkg-config
, buildGoModule , buildGoModule
, makeWrapper , makeWrapper
, runCommand , runCommand
@ -185,26 +186,25 @@ let
''; '';
}; };
whisper = effectiveStdenv.mkDerivation { # try to merge with openai-whisper-cpp in future
name = "whisper"; whisper-cpp = effectiveStdenv.mkDerivation {
name = "whisper-cpp";
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "ggerganov"; owner = "ggerganov";
repo = "whisper.cpp"; repo = "whisper.cpp";
rev = "a56f435fd475afd7edf02bfbf9f8c77f527198c2"; rev = "a56f435fd475afd7edf02bfbf9f8c77f527198c2";
hash = "sha256-ozTnxEuftAQQr5v/kwg5EKHuKF21d9ETIyvXcvr0Qos="; hash = "sha256-g8ZhVB5sxpfrFzg/0seSrv0vFG0YOP56253n6/KWHfE=";
fetchSubmodules = true;
}; };
dontUseCmakeConfigure = true; nativeBuildInputs = [ cmake pkg-config ];
nativeBuildInputs = [ cmake ];
buildFlags = [ "libwhisper.a" ];
buildInputs = typedBuiltInputs; buildInputs = typedBuiltInputs;
env = lib.optionalAttrs with_cublas { WHISPER_CUBLAS = 1; } cmakeFlags = [
// lib.optionalAttrs with_clblas { WHISPER_CLBLAS = 1; } (lib.cmakeBool "WHISPER_CUBLAS" with_cublas)
// lib.optionalAttrs with_openblas { WHISPER_OPENBLAS = 1; } (lib.cmakeBool "WHISPER_CLBLAST" with_clblas)
; (lib.cmakeBool "WHISPER_OPENBLAS" with_openblas)
installPhase = '' (lib.cmakeBool "BUILD_SHARED_LIBS" false)
cp -r --no-preserve=mode $src $out ];
cp *.a $out postInstall = ''
install -Dt $out/bin bin/*
''; '';
}; };
@ -310,7 +310,7 @@ let
-e 's;git clone.*gpt4all$;${cp} ${gpt4all} sources/gpt4all;' \ -e 's;git clone.*gpt4all$;${cp} ${gpt4all} sources/gpt4all;' \
-e 's;git clone.*go-piper$;${cp} ${if with_tts then go-piper else go-piper.src} sources/go-piper;' \ -e 's;git clone.*go-piper$;${cp} ${if with_tts then go-piper else go-piper.src} sources/go-piper;' \
-e 's;git clone.*go-rwkv$;${cp} ${go-rwkv} sources/go-rwkv;' \ -e 's;git clone.*go-rwkv$;${cp} ${go-rwkv} sources/go-rwkv;' \
-e 's;git clone.*whisper\.cpp$;${cp} ${whisper} sources/whisper\.cpp;' \ -e 's;git clone.*whisper\.cpp$;${cp} ${whisper-cpp.src} sources/whisper\.cpp;' \
-e 's;git clone.*go-bert$;${cp} ${go-bert} sources/go-bert;' \ -e 's;git clone.*go-bert$;${cp} ${go-bert} sources/go-bert;' \
-e 's;git clone.*diffusion$;${cp} ${if with_stablediffusion then go-stable-diffusion else go-stable-diffusion.src} sources/go-stable-diffusion;' \ -e 's;git clone.*diffusion$;${cp} ${if with_stablediffusion then go-stable-diffusion else go-stable-diffusion.src} sources/go-stable-diffusion;' \
-e 's;git clone.*go-tiny-dream$;${cp} ${if with_tinydream then go-tiny-dream else go-tiny-dream.src} sources/go-tiny-dream;' \ -e 's;git clone.*go-tiny-dream$;${cp} ${if with_tinydream then go-tiny-dream else go-tiny-dream.src} sources/go-tiny-dream;' \
@ -355,6 +355,7 @@ let
make prepare-sources make prepare-sources
# avoid rebuild of prebuilt libraries # avoid rebuild of prebuilt libraries
touch sources/**/lib*.a touch sources/**/lib*.a
cp ${whisper-cpp}/lib/static/lib*.a sources/whisper.cpp
local flagsArray=( local flagsArray=(
''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}} ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}}
@ -393,7 +394,7 @@ let
passthru.local-packages = { passthru.local-packages = {
inherit inherit
go-tiny-dream go-rwkv go-bert go-llama-ggml gpt4all go-piper go-tiny-dream go-rwkv go-bert go-llama-ggml gpt4all go-piper
llama-cpp-grpc; llama-cpp-grpc whisper-cpp;
}; };
passthru.features = { passthru.features = {