Open6

Flutter ローカルLLM

hndrhndr

llama.cpp

git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp

Build

https://github.com/ggerganov/llama.cpp/blob/master/docs/build.md
https://github.com/ggerganov/llama.cpp/blob/master/.github/workflows/build.yml
https://github.com/netdur/llama_cpp_dart/blob/main/darwin/run_build.sh

Build MacOS

mkdir build
cd build
cmake ..
make

Build iOS (Metal)

mkdir build-metal
cd build-metal
cmake -G Xcode .. \
  -DGGML_METAL_USE_BF16=ON \
  -DGGML_METAL_EMBED_LIBRARY=ON \
  -DLLAMA_BUILD_EXAMPLES=OFF \
  -DLLAMA_BUILD_TESTS=OFF \
  -DLLAMA_BUILD_SERVER=OFF \
  -DCMAKE_SYSTEM_NAME=iOS \
  -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
  -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml

cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO

Build iOS Simulator

mkdir build-ios-simulator
cd build-ios-simulator

cmake -G Xcode .. \
  -DGGML_METAL_USE_BF16=ON \
  -DGGML_METAL_EMBED_LIBRARY=ON \
  -DLLAMA_BUILD_EXAMPLES=OFF \
  -DLLAMA_BUILD_TESTS=OFF \
  -DLLAMA_BUILD_SERVER=OFF \
  -DCMAKE_SYSTEM_NAME=iOS \
  -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64 \
  -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
  -DCMAKE_XCODE_ATTRIBUTE_SDKROOT=iphonesimulator

cmake --build . --config Release -j $(sysctl -n hw.logicalcpu)

Build Android

mkdir build-android
cd build-android

export NDK=$HOME/Library/Android/sdk/ndk/28.0.12674087

cmake \
 -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
 -DANDROID_ABI=arm64-v8a \
 -DANDROID_PLATFORM=android-23 \
 -DCMAKE_C_FLAGS=-march=armv8.4a+dotprod ..

make
cmake \
  -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=android-28 \
  -DCMAKE_C_FLAGS="-march=armv8.7a" \
  -DCMAKE_CXX_FLAGS="-march=armv8.7a" \
  -DGGML_OPENMP=OFF \
  -DGGML_LLAMAFILE=OFF \
  -B build-android

https://github.com/ggerganov/llama.cpp/blob/master/docs/android.md
https://medium.com/@nicosnicolaou/ndk-setup-on-android-flutter-android-project-1571d9a3f5cb

https://github.com/ggerganov/llama.cpp

flutter アプリ作成

flutter create flutter_llm_sample
cd flutter_llm_sample

ffi install

flutter pub add ffi

https://pub.dev/packages/ffi
https://qiita.com/hyshu/items/8eb71d7d36d56b2b5bb0
https://zenn.dev/turing_motors/articles/c62030a38d2eda

llama_cpp_dart install

flutter pub add llama_cpp_dart

https://pub.dev/packages/llama_cpp_dart
https://github.com/netdur/llama_cpp_dart

fcllama install

https://pub.dev/packages/fcllama
https://github.com/xuegao-tzx/Fllama

Package / repository

https://pub.dev/packages/llama_cpp
https://github.com/MidstallSoftware/flutter_llama
https://github.com/Telosnex/fllama
https://pyimagesearch.com/2024/08/26/llama-cpp-the-ultimate-guide-to-efficient-llm-inference-and-applications/
https://flutterawesome.com/a-mobile-implementation-of-llama-cpp/
https://github.com/Bip-Rep/sherpa
https://youtu.be/lDn-Qr80_Ec?si=9lqzqBEI9ICZE2un
https://github.com/Mobile-Artificial-Intelligence/maid
https://github.com/paulocoutinhox/llama-flutter
https://www.reddit.com/r/LocalLLaMA/comments/1gdzs06/anyone_using_llama_32_3b_in_a_flutter_app/

hndrhndr

https://github.com/netdur/llama_cpp_dart/issues/28

ios/.symlinks/plugins/llama_cpp_dart/ios/llama_cpp_dart.podspec

Pod::Spec.new do |s|
  s.name             = 'llama_cpp_dart'
  s.version          = '0.0.1'
  s.summary          = 'Llama Cpp Dart'
  s.homepage         = 'https://github.com/netdur/llama_cpp_dart'
  s.license          = { :type => 'MIT' }
  s.author           = { 'netdur' => 'team@myteam.com' }
  s.source           = { :git => '', :version => s.version.to_s }
  s.ios.deployment_target = '17.2'
  s.macos.deployment_target = '10.15'
  # Framework linking is handled by Flutter tooling, not CocoaPods.
  # Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
  s.vendored_frameworks = 'path/to/nothing'
end