├── data └── locale │ └── en-US.ini ├── .github ├── scripts │ ├── build-linux │ ├── build-macos │ ├── package-linux │ ├── package-macos │ ├── utils.zsh │ │ ├── mkcd │ │ ├── log_error │ │ ├── log_warning │ │ ├── log_debug │ │ ├── log_output │ │ ├── log_status │ │ ├── log_info │ │ ├── read_codesign_user │ │ ├── read_codesign_team │ │ ├── read_codesign_installer │ │ ├── read_codesign │ │ ├── log_group │ │ ├── set_loglevel │ │ ├── check_macos │ │ ├── setup_ccache │ │ ├── read_codesign_pass │ │ ├── setup_linux │ │ └── check_linux │ ├── .Brewfile │ ├── .Wingetfile │ ├── .Aptfile │ ├── utils.pwsh │ │ ├── Ensure-Location.ps1 │ │ ├── Invoke-External.ps1 │ │ ├── Install-BuildDependencies.ps1 │ │ ├── Expand-ArchiveExt.ps1 │ │ └── Logger.ps1 │ ├── Package-Windows.ps1 │ ├── Build-Windows.ps1 │ └── .package.zsh ├── workflows │ ├── dispatch.yaml │ ├── check-format.yaml │ ├── pr-pull.yaml │ └── push.yaml └── actions │ ├── run-cmake-format │ └── action.yaml │ ├── run-clang-format │ └── action.yaml │ ├── build-plugin │ └── action.yaml │ ├── package-plugin │ └── action.yaml │ └── setup-macos-codesigning │ └── action.yaml ├── src ├── llm-dock │ ├── llm-dock.h │ ├── CMakeLists.txt │ ├── Workflows.hpp │ ├── llama-inference.h │ ├── LLMSettingsDialog.hpp │ ├── llm-dock-ui.hpp │ ├── llm-config-data.h │ ├── LLMSettingsDialog.cpp │ ├── ui │ │ ├── workflows.ui │ │ ├── dockwidget.ui │ │ └── settingsdialog.ui │ ├── Workflows.cpp │ ├── llm-config-data.cpp │ ├── llm-dock-ui.cpp │ └── llama-inference.cpp ├── plugin-support.h ├── plugin-main.c └── plugin-support.c.in ├── cmake ├── windows │ ├── defaults.cmake │ ├── buildspec.cmake │ ├── resources │ │ ├── resource.rc.in │ │ └── installer-Windows.iss.in │ ├── compilerconfig.cmake │ └── helpers.cmake ├── macos │ ├── resources │ │ ├── ccache-launcher-c.in │ │ ├── ccache-launcher-cxx.in │ │ ├── distribution.in │ │ └── create-package.cmake.in │ ├── buildspec.cmake │ ├── defaults.cmake │ ├── compilerconfig.cmake │ ├── helpers.cmake │ └── xcode.cmake ├── common │ ├── ccache.cmake │ ├── buildnumber.cmake │ ├── osconfig.cmake │ ├── compiler_common.cmake │ ├── bootstrap.cmake │ ├── helpers_common.cmake │ └── buildspec_common.cmake ├── linux │ ├── toolchains │ │ ├── x86_64-linux-gcc.cmake │ │ ├── aarch64-linux-gcc.cmake │ │ ├── x86_64-linux-clang.cmake │ │ └── aarch64-linux-clang.cmake │ ├── helpers.cmake │ ├── defaults.cmake │ └── compilerconfig.cmake └── BuildLlamacpp.cmake ├── patch_libobs.diff ├── .gitignore ├── .cmake-format.json ├── CMakeLists.txt ├── .clang-format ├── README.md └── CMakePresets.json /data/locale/en-US.ini: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/scripts/build-linux: -------------------------------------------------------------------------------- 1 | .build.zsh -------------------------------------------------------------------------------- /.github/scripts/build-macos: -------------------------------------------------------------------------------- 1 | .build.zsh -------------------------------------------------------------------------------- /.github/scripts/package-linux: -------------------------------------------------------------------------------- 1 | .package.zsh -------------------------------------------------------------------------------- /.github/scripts/package-macos: -------------------------------------------------------------------------------- 1 | .package.zsh -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/mkcd: -------------------------------------------------------------------------------- 1 | [[ -n ${1} ]] && mkdir -p ${1} && builtin cd ${1} 2 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/log_error: -------------------------------------------------------------------------------- 1 | local icon=' ✖︎ ' 2 | 3 | print -u2 -PR "${CI:+::error::}%F{1} ${icon} %f ${@}" 4 | -------------------------------------------------------------------------------- /.github/scripts/.Brewfile: -------------------------------------------------------------------------------- 1 | brew "ccache" 2 | brew "coreutils" 3 | brew "cmake" 4 | brew "git" 5 | brew "jq" 6 | brew "xcbeautify" 7 | -------------------------------------------------------------------------------- /.github/scripts/.Wingetfile: -------------------------------------------------------------------------------- 1 | package 'cmake', path: 'Cmake\bin', bin: 'cmake' 2 | package 'innosetup', path: 'Inno Setup 6', bin: 'iscc' 3 | -------------------------------------------------------------------------------- /.github/scripts/.Aptfile: -------------------------------------------------------------------------------- 1 | package 'cmake' 2 | package 'ccache' 3 | package 'git' 4 | package 'jq' 5 | package 'ninja-build', bin: 'ninja' 6 | package 'pkg-config' 7 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/log_warning: -------------------------------------------------------------------------------- 1 | if (( _loglevel > 0 )) { 2 | local icon=' =>' 3 | 4 | print -PR "${CI:+::warning::}%F{3} ${(r:5:)icon} ${@}%f" 5 | } 6 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/log_debug: -------------------------------------------------------------------------------- 1 | if (( ! ${+_loglevel} )) typeset -g _loglevel=1 2 | 3 | if (( _loglevel > 2 )) print -PR -e -- "${CI:+::debug::}%F{220}DEBUG: ${@}%f" 4 | -------------------------------------------------------------------------------- /src/llm-dock/llm-dock.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | void register_llm_dock(void); 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif 12 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/log_output: -------------------------------------------------------------------------------- 1 | if (( ! ${+_loglevel} )) typeset -g _loglevel=1 2 | 3 | if (( _loglevel > 0 )) { 4 | local icon='' 5 | 6 | print -PR " ${(r:5:)icon} ${@}" 7 | } 8 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/log_status: -------------------------------------------------------------------------------- 1 | if (( ! ${+_loglevel} )) typeset -g _loglevel=1 2 | 3 | if (( _loglevel > 0 )) { 4 | local icon=' >' 5 | 6 | print -PR "%F{2} ${(r:5:)icon}%f ${@}" 7 | } 8 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/log_info: -------------------------------------------------------------------------------- 1 | if (( ! ${+_loglevel} )) typeset -g _loglevel=1 2 | 3 | if (( _loglevel > 0 )) { 4 | local icon=' =>' 5 | 6 | print -PR "%F{4} ${(r:5:)icon}%f %B${@}%b" 7 | } 8 | -------------------------------------------------------------------------------- /cmake/windows/defaults.cmake: -------------------------------------------------------------------------------- 1 | # CMake Windows defaults module 2 | 3 | include_guard(GLOBAL) 4 | 5 | # Enable find_package targets to become globally available targets 6 | set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE) 7 | 8 | include(buildspec) 9 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/read_codesign_user: -------------------------------------------------------------------------------- 1 | autoload -Uz log_info 2 | 3 | if (( ! ${+CODESIGN_IDENT_USER} )) { 4 | typeset -g CODESIGN_IDENT_USER 5 | log_info 'Setting up Apple ID for notarization...' 6 | read CODESIGN_IDENT_USER'?Apple ID: ' 7 | } 8 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/read_codesign_team: -------------------------------------------------------------------------------- 1 | autoload -Uz log_info 2 | 3 | if (( ! ${+CODESIGN_TEAM} )) { 4 | typeset -g CODESIGN_TEAM 5 | log_info 'Setting up Apple Developer Team ID for codesigning...' 6 | read CODESIGN_TEAM'?Apple Developer Team ID (leave empty to use Apple Developer ID instead): ' 7 | } 8 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/read_codesign_installer: -------------------------------------------------------------------------------- 1 | autoload -Uz log_info 2 | 3 | if (( ! ${+CODESIGN_IDENT_INSTALLER} )) { 4 | typeset -g CODESIGN_IDENT_INSTALLER 5 | log_info 'Setting up Apple Developer Installer ID for installer package codesigning...' 6 | read CODESIGN_IDENT_INSTALLER'?Apple Developer Installer ID: ' 7 | } 8 | -------------------------------------------------------------------------------- /src/llm-dock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources( 2 | ${CMAKE_PROJECT_NAME} 3 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/llm-dock-ui.cpp ${CMAKE_CURRENT_SOURCE_DIR}/llama-inference.cpp 4 | ${CMAKE_CURRENT_SOURCE_DIR}/LLMSettingsDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/llm-config-data.cpp 5 | ${CMAKE_CURRENT_SOURCE_DIR}/Workflows.cpp) 6 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/read_codesign: -------------------------------------------------------------------------------- 1 | autoload -Uz log_info 2 | 3 | if (( ! ${+CODESIGN_IDENT} )) { 4 | typeset -g CODESIGN_IDENT 5 | log_info 'Setting up Apple Developer ID for application codesigning...' 6 | read CODESIGN_IDENT'?Apple Developer Application ID: ' 7 | } 8 | 9 | typeset -g CODESIGN_TEAM=$(print "${CODESIGN_IDENT}" | /usr/bin/sed -En 's/.+\((.+)\)/\1/p') 10 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/log_group: -------------------------------------------------------------------------------- 1 | autoload -Uz log_info 2 | 3 | if (( ! ${+_log_group} )) typeset -g _log_group=0 4 | 5 | if (( ${+CI} )) { 6 | if (( _log_group )) { 7 | print "::endgroup::" 8 | typeset -g _log_group=0 9 | } 10 | if (( # )) { 11 | print "::group::${@}" 12 | typeset -g _log_group=1 13 | } 14 | } else { 15 | if (( # )) log_info ${@} 16 | } 17 | -------------------------------------------------------------------------------- /patch_libobs.diff: -------------------------------------------------------------------------------- 1 | diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt 2 | index d2e2671..d7797c6 100644 3 | --- a/libobs/CMakeLists.txt 4 | +++ b/libobs/CMakeLists.txt 5 | @@ -287,6 +287,7 @@ set(public_headers 6 | util/base.h 7 | util/bmem.h 8 | util/c99defs.h 9 | + util/config-file.h 10 | util/darray.h 11 | util/profiler.h 12 | util/sse-intrin.h 13 | -------------------------------------------------------------------------------- /src/llm-dock/Workflows.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WORKFLOWS_H 2 | #define WORKFLOWS_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class Workflows; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class Workflows : public QDialog { 13 | Q_OBJECT 14 | 15 | public: 16 | Workflows(QWidget *parent = nullptr); 17 | ~Workflows(); 18 | 19 | private: 20 | Ui::Workflows *ui; 21 | }; 22 | #endif // WORKFLOWS_H 23 | -------------------------------------------------------------------------------- /src/llm-dock/llama-inference.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | struct llama_context *llama_init_context(const std::string &model_file_path); 7 | 8 | std::string llama_inference(const std::string &prompt, struct llama_context *ctx, 9 | std::function partial_generation_callback, 10 | std::function should_stop_callback); 11 | -------------------------------------------------------------------------------- /.github/workflows/dispatch.yaml: -------------------------------------------------------------------------------- 1 | name: Dispatch 2 | run-name: Dispatched Repository Actions - ${{ inputs.job }} ⌛️ 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | job: 7 | description: Dispatch job to run 8 | required: true 9 | type: choice 10 | options: 11 | - build 12 | permissions: 13 | contents: write 14 | jobs: 15 | check-and-build: 16 | if: inputs.job == 'build' 17 | uses: ./.github/workflows/build-project.yaml 18 | secrets: inherit 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Exclude everything 2 | /* 3 | 4 | # Except for default project files 5 | !/.github 6 | !/build-aux 7 | !/cmake 8 | !/data 9 | !/src 10 | !.clang-format 11 | !.cmake-format.json 12 | !.gitignore 13 | !buildspec.json 14 | !CMakeLists.txt 15 | !CMakePresets.json 16 | !LICENSE 17 | !README.md 18 | !patch_libobs.diff 19 | !vendor 20 | 21 | # Exclude lock files 22 | *.lock.json 23 | 24 | # Exclude macOS legacy resource forks 25 | .DS_Store 26 | 27 | # Exclude CMake build number cache 28 | /cmake/.CMakeBuildNumber 29 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/set_loglevel: -------------------------------------------------------------------------------- 1 | autoload -Uz log_debug log_error 2 | 3 | local -r _usage="Usage: %B${0}%b 4 | 5 | Set log level, following levels are supported: 0 (quiet), 1 (normal), 2 (verbose), 3 (debug)" 6 | 7 | if (( ! # )); then 8 | log_error 'Called without arguments.' 9 | log_output ${_usage} 10 | return 2 11 | elif (( ${1} >= 4 )); then 12 | log_error 'Called with loglevel > 3.' 13 | log_output ${_usage} 14 | fi 15 | 16 | typeset -g -i -r _loglevel=${1} 17 | log_debug "Log level set to '${1}'" 18 | -------------------------------------------------------------------------------- /cmake/macos/resources/ccache-launcher-c.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [[ "$1" == "${CMAKE_C_COMPILER}" ]] ; then 4 | shift 5 | fi 6 | 7 | export CCACHE_CPP2=true 8 | export CCACHE_DEPEND=true 9 | export CCACHE_DIRECT=true 10 | export CCACHE_FILECLONE=true 11 | export CCACHE_INODECACHE=true 12 | export CCACHE_NOCOMPILERCHECK='content' 13 | export CCACHE_SLOPPINESS='include_file_mtime,include_file_ctime,clang_index_store,system_headers' 14 | if [[ "${CI}" ]]; then 15 | export CCACHE_NOHASHDIR=true 16 | fi 17 | exec "${CMAKE_C_COMPILER_LAUNCHER}" "${CMAKE_C_COMPILER}" "$@" 18 | -------------------------------------------------------------------------------- /cmake/macos/resources/ccache-launcher-cxx.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [[ "$1" == "${CMAKE_CXX_COMPILER}" ]] ; then 4 | shift 5 | fi 6 | 7 | export CCACHE_CPP2=true 8 | export CCACHE_NODEPEND=true 9 | export CCACHE_DIRECT=true 10 | export CCACHE_FILECLONE=true 11 | export CCACHE_INODECACHE=true 12 | export CCACHE_NOCOMPILERCHECK='content' 13 | export CCACHE_SLOPPINESS='include_file_mtime,include_file_ctime,clang_index_store,system_headers' 14 | if [[ "${CI}" ]]; then 15 | export CCACHE_NOHASHDIR=true 16 | fi 17 | exec "${CMAKE_CXX_COMPILER_LAUNCHER}" "${CMAKE_CXX_COMPILER}" "$@" 18 | -------------------------------------------------------------------------------- /src/llm-dock/LLMSettingsDialog.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LLMSETTINGSDIALOG_HPP 2 | #define LLMSETTINGSDIALOG_HPP 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class SettingsDialog; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | /** 13 | * @brief The LLMSettingsDialog class 14 | * This class is used to create a settings dialog for the LLM dock. 15 | * The settings dialog is opened by clicking the settings button in the LLM dock. 16 | */ 17 | class LLMSettingsDialog : public QDialog { 18 | Q_OBJECT 19 | public: 20 | explicit LLMSettingsDialog(QWidget *parent); 21 | ~LLMSettingsDialog(); 22 | 23 | private: 24 | Ui::SettingsDialog *ui; 25 | }; 26 | 27 | #endif // LLMSETTINGSDIALOG_HPP 28 | -------------------------------------------------------------------------------- /src/llm-dock/llm-dock-ui.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LLMDOCKWIDGETUI_HPP 2 | #define LLMDOCKWIDGETUI_HPP 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class BrainDock; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class LLMDockWidgetUI : public QDockWidget { 13 | Q_OBJECT 14 | public: 15 | explicit LLMDockWidgetUI(QWidget *parent); 16 | ~LLMDockWidgetUI(); 17 | 18 | public slots: 19 | void generate(); 20 | void clear(); 21 | void stop(); 22 | void update_text(const QString &text, bool partial_generation); 23 | 24 | signals: 25 | void update_text_signal(const QString &text, bool partial_generation); 26 | 27 | private: 28 | Ui::BrainDock *ui; 29 | bool stop_flag = false; 30 | }; 31 | 32 | #endif // LLMDOCKWIDGETUI_HPP 33 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/check_macos: -------------------------------------------------------------------------------- 1 | autoload -Uz is-at-least log_group log_info log_error log_status read_codesign 2 | 3 | local macos_version=$(sw_vers -productVersion) 4 | 5 | log_group 'Install macOS build requirements' 6 | log_info 'Checking macOS version...' 7 | if ! is-at-least 11.0 ${macos_version}; then 8 | log_error "Minimum required macOS version is 11.0, but running on macOS ${macos_version}" 9 | return 2 10 | else 11 | log_status "macOS ${macos_version} is recent" 12 | fi 13 | 14 | log_info 'Checking for Homebrew...' 15 | if (( ! ${+commands[brew]} )) { 16 | log_error 'No Homebrew command found. Please install Homebrew (https://brew.sh)' 17 | return 2 18 | } 19 | 20 | brew bundle --file ${SCRIPT_HOME}/.Brewfile 21 | rehash 22 | log_group 23 | -------------------------------------------------------------------------------- /.github/workflows/check-format.yaml: -------------------------------------------------------------------------------- 1 | name: Check Code Formatting 🛠️ 2 | on: 3 | workflow_call: 4 | jobs: 5 | clang-format: 6 | runs-on: ubuntu-22.04 7 | steps: 8 | - uses: actions/checkout@v3 9 | with: 10 | fetch-depth: 0 11 | - name: clang-format check 🐉 12 | id: clang-format 13 | uses: ./.github/actions/run-clang-format 14 | with: 15 | failCondition: error 16 | 17 | cmake-format: 18 | runs-on: ubuntu-22.04 19 | steps: 20 | - uses: actions/checkout@v3 21 | with: 22 | fetch-depth: 0 23 | - name: cmake-format check 🎛️ 24 | id: cmake-format 25 | uses: ./.github/actions/run-cmake-format 26 | with: 27 | failCondition: error 28 | -------------------------------------------------------------------------------- /cmake/common/ccache.cmake: -------------------------------------------------------------------------------- 1 | # CMake ccache module 2 | 3 | include_guard(GLOBAL) 4 | 5 | if(NOT DEFINED CCACHE_PROGRAM) 6 | message(DEBUG "Trying to find ccache on build host...") 7 | find_program(CCACHE_PROGRAM "ccache") 8 | mark_as_advanced(CCACHE_PROGRAM) 9 | endif() 10 | 11 | if(CCACHE_PROGRAM) 12 | message(DEBUG "Ccache found as ${CCACHE_PROGRAM}...") 13 | option(ENABLE_CCACHE "Enable compiler acceleration with ccache" ON) 14 | 15 | if(ENABLE_CCACHE) 16 | set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") 17 | set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") 18 | set(CMAKE_OBJC_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") 19 | set(CMAKE_OBJCXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") 20 | set(CMAKE_CUDA_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") 21 | endif() 22 | endif() 23 | -------------------------------------------------------------------------------- /cmake/linux/toolchains/x86_64-linux-gcc.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 3 | set(CMAKE_CROSSCOMPILING TRUE) 4 | 5 | set(CMAKE_C_COMPILER /usr/bin/x86_64-linux-gnu-gcc) 6 | set(CMAKE_CXX_COMPILER /usr/bin/x86_64-linux-gnu-g++) 7 | 8 | set(CMAKE_FIND_ROOT_PATH /usr/x86_64-linux-gnu) 9 | 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | 12 | set(PKG_CONFIG_EXECUTABLE 13 | /usr/bin/x86_64-linux-gnu-pkg-config 14 | CACHE FILEPATH "pkg-config executable") 15 | 16 | set(CPACK_READELF_EXECUTABLE /usr/bin/x86_64-linux-gnu-readelf) 17 | set(CPACK_OBJCOPY_EXECUTABLE /usr/bin/x86_64-linux-gnu-objcopy) 18 | set(CPACK_OBJDUMP_EXECUTABLE /usr/bin/x86_64-linux-gnu-objdump) 19 | set(CPACK_PACKAGE_ARCHITECTURE x86_64) 20 | set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE x86_64) 21 | -------------------------------------------------------------------------------- /cmake/linux/toolchains/aarch64-linux-gcc.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 3 | set(CMAKE_CROSSCOMPILING TRUE) 4 | 5 | set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc) 6 | set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++) 7 | 8 | set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) 9 | 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | 12 | set(PKG_CONFIG_EXECUTABLE 13 | /usr/bin/aarch64-linux-gnu-pkg-config 14 | CACHE FILEPATH "pkg-config executable") 15 | 16 | set(CPACK_READELF_EXECUTABLE /usr/bin/aarch64-linux-gnu-readelf) 17 | set(CPACK_OBJCOPY_EXECUTABLE /usr/bin/aarch64-linux-gnu-objcopy) 18 | set(CPACK_OBJDUMP_EXECUTABLE /usr/bin/aarch64-linux-gnu-objdump) 19 | set(CPACK_PACKAGE_ARCHITECTURE arm64) 20 | set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE arm64) 21 | -------------------------------------------------------------------------------- /cmake/common/buildnumber.cmake: -------------------------------------------------------------------------------- 1 | # CMake build number module 2 | 3 | include_guard(GLOBAL) 4 | 5 | # Define build number cache file 6 | set(_BUILD_NUMBER_CACHE 7 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/.CMakeBuildNumber" 8 | CACHE INTERNAL "OBS build number cache file") 9 | 10 | # Read build number from cache file or manual override 11 | if(NOT DEFINED PLUGIN_BUILD_NUMBER AND EXISTS "${_BUILD_NUMBER_CACHE}") 12 | file(READ "${_BUILD_NUMBER_CACHE}" PLUGIN_BUILD_NUMBER) 13 | math(EXPR PLUGIN_BUILD_NUMBER "${PLUGIN_BUILD_NUMBER}+1") 14 | elseif(NOT DEFINED PLUGIN_BUILD_NUMBER) 15 | if($ENV{CI} AND $ENV{GITHUB_RUN_ID}) 16 | set(PLUGIN_BUILD_NUMBER "$ENV{GITHUB_RUN_ID}") 17 | else() 18 | set(PLUGIN_BUILD_NUMBER "1") 19 | endif() 20 | endif() 21 | file(WRITE "${_BUILD_NUMBER_CACHE}" "${PLUGIN_BUILD_NUMBER}") 22 | -------------------------------------------------------------------------------- /.github/workflows/pr-pull.yaml: -------------------------------------------------------------------------------- 1 | name: Pull Request 2 | run-name: ${{ github.event.pull_request.title }} pull request run 🚀 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | paths-ignore: 7 | - '**.md' 8 | branches: [master, main] 9 | types: [ opened, synchronize, reopened ] 10 | permissions: 11 | contents: read 12 | concurrency: 13 | group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' 14 | cancel-in-progress: true 15 | jobs: 16 | check-format: 17 | name: Check Formatting 🔍 18 | uses: ./.github/workflows/check-format.yaml 19 | permissions: 20 | contents: read 21 | 22 | build-project: 23 | name: Build Project 🧱 24 | uses: ./.github/workflows/build-project.yaml 25 | secrets: inherit 26 | permissions: 27 | contents: read 28 | -------------------------------------------------------------------------------- /.github/scripts/utils.pwsh/Ensure-Location.ps1: -------------------------------------------------------------------------------- 1 | function Ensure-Location { 2 | <# 3 | .SYNOPSIS 4 | Ensures current location to be set to specified directory. 5 | .DESCRIPTION 6 | If specified directory exists, switch to it. Otherwise create it, 7 | then switch. 8 | .EXAMPLE 9 | Ensure-Location "My-Directory" 10 | Ensure-Location -Path "Path-To-My-Directory" 11 | #> 12 | 13 | param( 14 | [Parameter(Mandatory)] 15 | [string] $Path 16 | ) 17 | 18 | if ( ! ( Test-Path $Path ) ) { 19 | $_Params = @{ 20 | ItemType = "Directory" 21 | Path = ${Path} 22 | ErrorAction = "SilentlyContinue" 23 | } 24 | 25 | New-Item @_Params | Set-Location 26 | } else { 27 | Set-Location -Path ${Path} 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cmake/windows/buildspec.cmake: -------------------------------------------------------------------------------- 1 | # CMake Windows build dependencies module 2 | 3 | include_guard(GLOBAL) 4 | 5 | include(buildspec_common) 6 | 7 | # _check_dependencies_windows: Set up Windows slice for _check_dependencies 8 | function(_check_dependencies_windows) 9 | set(arch ${CMAKE_GENERATOR_PLATFORM}) 10 | set(platform windows-${arch}) 11 | 12 | set(dependencies_dir "${CMAKE_CURRENT_SOURCE_DIR}/.deps") 13 | set(prebuilt_filename "windows-deps-VERSION-ARCH-REVISION.zip") 14 | set(prebuilt_destination "obs-deps-VERSION-ARCH") 15 | set(qt6_filename "windows-deps-qt6-VERSION-ARCH-REVISION.zip") 16 | set(qt6_destination "obs-deps-qt6-VERSION-ARCH") 17 | set(obs-studio_filename "VERSION.zip") 18 | set(obs-studio_destination "obs-studio-VERSION") 19 | set(dependencies_list prebuilt qt6 obs-studio) 20 | 21 | _check_dependencies() 22 | endfunction() 23 | 24 | _check_dependencies_windows() 25 | -------------------------------------------------------------------------------- /.cmake-format.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": { 3 | "line_width": 120, 4 | "tab_size": 2, 5 | "enable_sort": true, 6 | "autosort": true 7 | }, 8 | "additional_commands": { 9 | "find_qt": { 10 | "flags": [], 11 | "kwargs": { 12 | "COMPONENTS": "+", 13 | "COMPONENTS_WIN": "+", 14 | "COMPONENTS_MACOS": "+", 15 | "COMPONENTS_LINUX": "+" 16 | } 17 | }, 18 | "set_target_properties_obs": { 19 | "pargs": 1, 20 | "flags": [], 21 | "kwargs": { 22 | "PROPERTIES": { 23 | "kwargs": { 24 | "PREFIX": 1, 25 | "OUTPUT_NAME": 1, 26 | "FOLDER": 1, 27 | "VERSION": 1, 28 | "SOVERSION": 1, 29 | "AUTOMOC": 1, 30 | "AUTOUIC": 1, 31 | "AUTORCC": 1, 32 | "AUTOUIC_SEARCH_PATHS": 1, 33 | "BUILD_RPATH": 1, 34 | "INSTALL_RPATH": 1 35 | } 36 | } 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /cmake/common/osconfig.cmake: -------------------------------------------------------------------------------- 1 | # CMake operating system bootstrap module 2 | 3 | include_guard(GLOBAL) 4 | 5 | # Set minimum CMake version specific to host operating system, add OS-specific module directory to default search paths, 6 | # and set helper variables for OS detection in other CMake list files. 7 | if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") 8 | set(CMAKE_C_EXTENSIONS FALSE) 9 | set(CMAKE_CXX_EXTENSIONS FALSE) 10 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows") 11 | set(OS_WINDOWS TRUE) 12 | elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") 13 | set(CMAKE_C_EXTENSIONS FALSE) 14 | set(CMAKE_CXX_EXTENSIONS FALSE) 15 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos") 16 | set(OS_MACOS TRUE) 17 | elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD|OpenBSD") 18 | set(CMAKE_CXX_EXTENSIONS FALSE) 19 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux") 20 | string(TOUPPER "${CMAKE_HOST_SYSTEM_NAME}" _SYSTEM_NAME_U) 21 | set(OS_${_SYSTEM_NAME_U} TRUE) 22 | endif() 23 | -------------------------------------------------------------------------------- /cmake/windows/resources/resource.rc.in: -------------------------------------------------------------------------------- 1 | 1 VERSIONINFO 2 | FILEVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0 3 | PRODUCTVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0 4 | FILEFLAGSMASK 0x0L 5 | #ifdef _DEBUG 6 | FILEFLAGS 0x1L 7 | #else 8 | FILEFLAGS 0x0L 9 | #endif 10 | FILEOS 0x0L 11 | FILETYPE 0x2L 12 | FILESUBTYPE 0x0L 13 | BEGIN 14 | BLOCK "StringFileInfo" 15 | BEGIN 16 | BLOCK "040904b0" 17 | BEGIN 18 | VALUE "CompanyName", "${PLUGIN_AUTHOR}" 19 | VALUE "FileDescription", "${PROJECT_NAME}" 20 | VALUE "FileVersion", "${PROJECT_VERSION}" 21 | VALUE "InternalName", "${PROJECT_NAME}" 22 | VALUE "LegalCopyright", "(C) ${CURRENT_YEAR} ${PLUGIN_AUTHOR}" 23 | VALUE "OriginalFilename", "${PROJECT_NAME}" 24 | VALUE "ProductName", "${PROJECT_NAME}" 25 | VALUE "ProductVersion", "${PROJECT_VERSION}" 26 | END 27 | END 28 | BLOCK "VarFileInfo" 29 | BEGIN 30 | VALUE "Translation", 0x409, 1200 31 | END 32 | END 33 | -------------------------------------------------------------------------------- /src/plugin-support.h: -------------------------------------------------------------------------------- 1 | /* 2 | obs-brAIn 3 | Copyright (C) 2023 Roy Shilkrot roy.shil@gmail.com 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program. If not, see 17 | */ 18 | 19 | #pragma once 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | extern const char *PLUGIN_NAME; 31 | extern const char *PLUGIN_VERSION; 32 | 33 | void obs_log(int log_level, const char *format, ...); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /.github/scripts/utils.pwsh/Invoke-External.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-External { 2 | <# 3 | .SYNOPSIS 4 | Invokes a non-PowerShell command. 5 | .DESCRIPTION 6 | Runs a non-PowerShell command, and captures its return code. 7 | Throws an exception if the command returns non-zero. 8 | .EXAMPLE 9 | Invoke-External 7z x $MyArchive 10 | #> 11 | 12 | if ( $args.Count -eq 0 ) { 13 | throw 'Invoke-External called without arguments.' 14 | } 15 | 16 | if ( ! ( Test-Path function:Log-Information ) ) { 17 | . $PSScriptRoot/Logger.ps1 18 | } 19 | 20 | $Command = $args[0] 21 | $CommandArgs = @() 22 | 23 | if ( $args.Count -gt 1) { 24 | $CommandArgs = $args[1..($args.Count - 1)] 25 | } 26 | 27 | $_EAP = $ErrorActionPreference 28 | $ErrorActionPreference = "Continue" 29 | 30 | Log-Debug "Invoke-External: ${Command} ${CommandArgs}" 31 | 32 | & $command $commandArgs 33 | $Result = $LASTEXITCODE 34 | 35 | $ErrorActionPreference = $_EAP 36 | 37 | if ( $Result -ne 0 ) { 38 | throw "${Command} ${CommandArgs} exited with non-zero code ${Result}." 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/setup_ccache: -------------------------------------------------------------------------------- 1 | autoload -Uz log_debug log_warning 2 | 3 | if (( ! ${+project_root} )) { 4 | log_error "'project_root' not set. Please set before running ${0}." 5 | return 2 6 | } 7 | 8 | if (( ${+commands[ccache]} )) { 9 | log_debug "Found ccache at ${commands[ccache]}" 10 | 11 | typeset -gx CCACHE_CONFIGPATH="${project_root}/.ccache.conf" 12 | 13 | ccache --set-config=run_second_cpp=true 14 | ccache --set-config=direct_mode=true 15 | ccache --set-config=inode_cache=true 16 | ccache --set-config=compiler_check=content 17 | ccache --set-config=file_clone=true 18 | 19 | local -a sloppiness=( 20 | include_file_mtime 21 | include_file_ctime 22 | file_stat_matches 23 | system_headers 24 | ) 25 | 26 | if [[ ${host_os} == macos ]] { 27 | sloppiness+=( 28 | modules 29 | clang_index_store 30 | ) 31 | 32 | ccache --set-config=sloppiness=${(j:,:)sloppiness} 33 | } 34 | 35 | if (( ${+CI} )) { 36 | ccache --set-config=cache_dir="${GITHUB_WORKSPACE:-${HOME}}/.ccache" 37 | ccache --set-config=max_size="${CCACHE_SIZE:-1G}" 38 | ccache -z > /dev/null 39 | } 40 | } else { 41 | log_warning "No ccache found on the system" 42 | } 43 | -------------------------------------------------------------------------------- /src/plugin-main.c: -------------------------------------------------------------------------------- 1 | /* 2 | obs-brAIn 3 | Copyright (C) 2023 Roy Shilkrot roy.shil@gmail.com 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program. If not, see 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include "llm-dock/llm-dock.h" 23 | 24 | OBS_DECLARE_MODULE() 25 | OBS_MODULE_USE_DEFAULT_LOCALE(PLUGIN_NAME, "en-US") 26 | 27 | bool obs_module_load(void) 28 | { 29 | obs_log(LOG_INFO, "plugin loaded successfully (version %s)", PLUGIN_VERSION); 30 | register_llm_dock(); 31 | return true; 32 | } 33 | 34 | void obs_module_unload(void) 35 | { 36 | obs_log(LOG_INFO, "plugin unloaded"); 37 | } 38 | -------------------------------------------------------------------------------- /cmake/macos/buildspec.cmake: -------------------------------------------------------------------------------- 1 | # CMake macOS build dependencies module 2 | 3 | include_guard(GLOBAL) 4 | 5 | include(buildspec_common) 6 | 7 | # _check_dependencies_macos: Set up macOS slice for _check_dependencies 8 | function(_check_dependencies_macos) 9 | set(arch universal) 10 | set(platform macos) 11 | 12 | file(READ "${CMAKE_CURRENT_SOURCE_DIR}/buildspec.json" buildspec) 13 | 14 | set(dependencies_dir "${CMAKE_CURRENT_SOURCE_DIR}/.deps") 15 | set(prebuilt_filename "macos-deps-VERSION-ARCH_REVISION.tar.xz") 16 | set(prebuilt_destination "obs-deps-VERSION-ARCH") 17 | set(qt6_filename "macos-deps-qt6-VERSION-ARCH-REVISION.tar.xz") 18 | set(qt6_destination "obs-deps-qt6-VERSION-ARCH") 19 | set(obs-studio_filename "VERSION.tar.gz") 20 | set(obs-studio_destination "obs-studio-VERSION") 21 | set(dependencies_list prebuilt qt6 obs-studio) 22 | 23 | _check_dependencies() 24 | 25 | execute_process(COMMAND "xattr" -r -d com.apple.quarantine "${dependencies_dir}" 26 | RESULT_VARIABLE result COMMAND_ERROR_IS_FATAL ANY) 27 | 28 | list(APPEND CMAKE_FRAMEWORK_PATH "${dependencies_dir}/Frameworks") 29 | set(CMAKE_FRAMEWORK_PATH 30 | ${CMAKE_FRAMEWORK_PATH} 31 | PARENT_SCOPE) 32 | endfunction() 33 | 34 | _check_dependencies_macos() 35 | -------------------------------------------------------------------------------- /src/llm-dock/llm-config-data.h: -------------------------------------------------------------------------------- 1 | #ifndef LLM_CONFIG_DATA_H 2 | #define LLM_CONFIG_DATA_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | struct llm_config_data { 10 | // local or cloud 11 | bool local; 12 | 13 | // local model path 14 | std::string local_model_path; 15 | 16 | // cloud model name 17 | std::string cloud_model_name; 18 | 19 | // cloud API key 20 | std::string cloud_api_key; 21 | 22 | // temperature 23 | float temperature; 24 | 25 | // max output tokens 26 | uint16_t max_output_tokens; 27 | 28 | // system prompt 29 | std::string system_prompt; 30 | 31 | // end sequence 32 | std::string end_sequence; 33 | 34 | // workflows 35 | std::vector workflows; 36 | }; 37 | 38 | // forward declaration 39 | struct llama_context; 40 | 41 | struct llm_global_context { 42 | // error message 43 | std::string error_message; 44 | // llama context 45 | struct llama_context *ctx_llama; 46 | }; 47 | 48 | extern llm_config_data global_llm_config; 49 | extern llm_global_context global_llm_context; 50 | 51 | #define OBS_BRAIN_CONFIG_FAIL -1 52 | #define OBS_BRAIN_CONFIG_SUCCESS 0 53 | 54 | int saveConfig(bool create_if_not_exist = false); 55 | int loadConfig(); 56 | 57 | #endif // LLM_CONFIG_DATA_H 58 | -------------------------------------------------------------------------------- /src/plugin-support.c.in: -------------------------------------------------------------------------------- 1 | /* 2 | obs-brAIn 3 | Copyright (C) 2023 Roy Shilkrot roy.shil@gmail.com 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program. If not, see 17 | */ 18 | 19 | #include 20 | 21 | const char *PLUGIN_NAME = "@CMAKE_PROJECT_NAME@"; 22 | const char *PLUGIN_VERSION = "@CMAKE_PROJECT_VERSION@"; 23 | 24 | extern void blogva(int log_level, const char *format, va_list args); 25 | 26 | void obs_log(int log_level, const char *format, ...) 27 | { 28 | size_t length = 4 + strlen(PLUGIN_NAME) + strlen(format); 29 | 30 | char *template = malloc(length + 1); 31 | 32 | snprintf(template, length, "[%s] %s", PLUGIN_NAME, format); 33 | 34 | va_list(args); 35 | 36 | va_start(args, format); 37 | blogva(log_level, template, args); 38 | va_end(args); 39 | 40 | free(template); 41 | } 42 | -------------------------------------------------------------------------------- /cmake/macos/resources/distribution.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | @CMAKE_PROJECT_NAME@ 10 | 11 | 12 | 13 | 14 | 15 | 16 | #@CMAKE_PROJECT_NAME@.pkg 17 | 18 | 33 | 34 | -------------------------------------------------------------------------------- /cmake/windows/compilerconfig.cmake: -------------------------------------------------------------------------------- 1 | # CMake Windows compiler configuration module 2 | 3 | include_guard(GLOBAL) 4 | 5 | include(compiler_common) 6 | 7 | # CMake 3.24 introduces a bug mistakenly interpreting MSVC as supporting the '-pthread' compiler flag 8 | if(CMAKE_VERSION VERSION_EQUAL 3.24.0) 9 | set(THREADS_HAVE_PTHREAD_ARG FALSE) 10 | endif() 11 | 12 | message(DEBUG "Current Windows API version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") 13 | if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM) 14 | message(DEBUG "Maximum Windows API version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM}") 15 | endif() 16 | 17 | if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS 10.0.20348) 18 | message(FATAL_ERROR "OBS requires Windows 10 SDK version 10.0.20348.0 or more recent.\n" 19 | "Please download and install the most recent Windows platform SDK.") 20 | endif() 21 | 22 | add_compile_options( 23 | /W3 /utf-8 "$<$:/MP>" "$<$:/MP>" 24 | "$<$:${_obs_clang_c_options}>" 25 | "$<$:${_obs_clang_cxx_options}>") 26 | 27 | add_compile_definitions(UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS $<$:DEBUG> 28 | $<$:_DEBUG>) 29 | 30 | add_link_options("$<$>:/OPT:REF>" "$<$:/INCREMENTAL:NO>" 31 | "$<$:/INCREMENTAL:NO>" "$<$:/OPT:ICF>") 32 | 33 | if(CMAKE_COMPILE_WARNING_AS_ERROR) 34 | add_link_options(/WX) 35 | endif() 36 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16...3.26) 2 | 3 | include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake" NO_POLICY_SCOPE) 4 | 5 | project(${_name} VERSION ${_version}) 6 | 7 | option(ENABLE_FRONTEND_API "Use obs-frontend-api for UI functionality" OFF) 8 | option(ENABLE_QT "Use Qt functionality" OFF) 9 | 10 | include(compilerconfig) 11 | include(defaults) 12 | include(helpers) 13 | 14 | add_library(${CMAKE_PROJECT_NAME} MODULE) 15 | 16 | find_package(libobs REQUIRED) 17 | target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::libobs) 18 | 19 | if(ENABLE_FRONTEND_API) 20 | find_package(obs-frontend-api REQUIRED) 21 | target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::obs-frontend-api) 22 | endif() 23 | 24 | if(ENABLE_QT) 25 | find_qt(COMPONENTS Widgets Core) 26 | target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt::Core Qt::Widgets) 27 | target_compile_options( 28 | ${CMAKE_PROJECT_NAME} PRIVATE $<$:-Wno-quoted-include-in-framework-header 29 | -Wno-comma>) 30 | set_target_properties( 31 | ${CMAKE_PROJECT_NAME} 32 | PROPERTIES AUTOMOC ON 33 | AUTOUIC ON 34 | AUTORCC ON) 35 | endif() 36 | 37 | include(cmake/BuildLlamacpp.cmake) 38 | target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Llamacpp) 39 | 40 | target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/plugin-main.c) 41 | 42 | target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE vendor/nlohmann-json) 43 | 44 | add_subdirectory(src/llm-dock) 45 | 46 | set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name}) 47 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/read_codesign_pass: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Apple Developer credentials necessary: 3 | # 4 | # + Signing for distribution and notarization require an active Apple 5 | # Developer membership 6 | # + An Apple Development identity is needed for code signing 7 | # (i.e. 'Apple Development: YOUR APPLE ID (PROVIDER)') 8 | # + Your Apple developer ID is needed for notarization 9 | # + An app-specific password is necessary for notarization from CLI 10 | # + This password will be stored in your macOS keychain under the identifier 11 | # 'OBS-Codesign-Password'with access Apple's 'altool' only. 12 | ############################################################################## 13 | 14 | autoload -Uz read_codesign read_codesign_user log_info log_warning 15 | 16 | if (( ! ${+CODESIGN_IDENT} )) { 17 | read_codesign 18 | } 19 | 20 | if (( ! ${+CODESIGN_IDENT_USER} )) { 21 | read_codesign_user 22 | } 23 | 24 | log_info 'Setting up password for notarization keychain...' 25 | if (( ! ${+CODESIGN_IDENT_PASS} )) { 26 | read -s CODESIGN_IDENT_PASS'?Apple Developer ID password: ' 27 | } 28 | 29 | print '' 30 | log_info 'Setting up notarization keychain...' 31 | log_warning " 32 | + Your Apple ID and an app-specific password is necessary for notarization from CLI 33 | + This password will be stored in your macOS keychain under the identifier 34 | 'OBS-Codesign-Password' with access Apple's 'altool' only. 35 | 36 | " 37 | xcrun notarytool store-credentials 'OBS-Codesign-Password' --apple-id "${CODESIGN_IDENT_USER}" --team-id "${CODESIGN_TEAM}" --password "${CODESIGN_IDENT_PASS}" 38 | 39 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/setup_linux: -------------------------------------------------------------------------------- 1 | autoload -Uz log_error log_status log_info mkcd 2 | 3 | if (( ! ${+project_root} )) { 4 | log_error "'project_root' not set. Please set before running ${0}." 5 | return 2 6 | } 7 | 8 | if (( ! ${+target} )) { 9 | log_error "'target' not set. Please set before running ${0}." 10 | return 2 11 | } 12 | 13 | pushd ${project_root} 14 | 15 | typeset -g QT_VERSION 16 | 17 | local -a apt_args=( 18 | ${CI:+-y} 19 | --no-install-recommends 20 | ) 21 | if (( _loglevel == 0 )) apt_args+=(--quiet) 22 | 23 | if (( ! (${skips[(Ie)all]} + ${skips[(Ie)deps]}) )) { 24 | log_group 'Installing obs-studio build dependencies...' 25 | 26 | local suffix 27 | if [[ ${CPUTYPE} != "${target##*-}" ]] { 28 | local -A arch_mappings=( 29 | aarch64 arm64 30 | x86_64 amd64 31 | ) 32 | 33 | suffix=":${arch_mappings[${target##*-}]}" 34 | 35 | sudo apt-get install ${apt_args} gcc-${${target##*-}//_/-}-linux-gnu g++-${${target##*-}//_/-}-linux-gnu 36 | } 37 | 38 | sudo add-apt-repository --yes ppa:obsproject/obs-studio 39 | sudo apt update 40 | 41 | sudo apt-get install ${apt_args} \ 42 | build-essential \ 43 | libgles2-mesa-dev \ 44 | obs-studio 45 | 46 | local -a _qt_packages=() 47 | 48 | if (( QT_VERSION == 5 )) { 49 | _qt_packages+=( 50 | qtbase5-dev${suffix} 51 | libqt5svg5-dev${suffix} 52 | qtbase5-private-dev${suffix} 53 | libqt5x11extras5-dev${suffix} 54 | ) 55 | } else { 56 | _qt_packages+=( 57 | qt6-base-dev${suffix} 58 | libqt6svg6-dev${suffix} 59 | qt6-base-private-dev${suffix} 60 | ) 61 | } 62 | 63 | sudo apt-get install ${apt_args} ${_qt_packages} 64 | log_group 65 | } 66 | -------------------------------------------------------------------------------- /cmake/macos/defaults.cmake: -------------------------------------------------------------------------------- 1 | # CMake macOS defaults module 2 | 3 | include_guard(GLOBAL) 4 | 5 | # Set empty codesigning team if not specified as cache variable 6 | if(NOT CODESIGN_TEAM) 7 | set(CODESIGN_TEAM 8 | "" 9 | CACHE STRING "OBS code signing team for macOS" FORCE) 10 | 11 | # Set ad-hoc codesigning identity if not specified as cache variable 12 | if(NOT CODESIGN_IDENTITY) 13 | set(CODESIGN_IDENTITY 14 | "-" 15 | CACHE STRING "OBS code signing identity for macOS" FORCE) 16 | endif() 17 | endif() 18 | 19 | if(XCODE) 20 | include(xcode) 21 | endif() 22 | 23 | include(buildspec) 24 | 25 | # Set default deployment target to 11.0 if not set and enable selection in GUI up to 13.0 26 | if(NOT CMAKE_OSX_DEPLOYMENT_TARGET) 27 | set(CMAKE_OSX_DEPLOYMENT_TARGET 28 | 11.0 29 | CACHE STRING "Minimum macOS version to target for deployment (at runtime). Newer APIs will be weak-linked." FORCE) 30 | endif() 31 | set_property(CACHE CMAKE_OSX_DEPLOYMENT_TARGET PROPERTY STRINGS 13.0 12.0 11.0) 32 | 33 | # Use Applications directory as default install destination 34 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 35 | set(CMAKE_INSTALL_PREFIX 36 | "$ENV{HOME}/Library/Application Support/obs-studio/plugins" 37 | CACHE STRING "Directory to install OBS after building" FORCE) 38 | endif() 39 | 40 | # Enable find_package targets to become globally available targets 41 | set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE) 42 | # Enable RPATH support for generated binaries 43 | set(CMAKE_MACOSX_RPATH TRUE) 44 | # Use RPATHs from build tree _in_ the build tree 45 | set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 46 | # Do not add default linker search paths to RPATH 47 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) 48 | # Use common bundle-relative RPATH for installed targets 49 | set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks") 50 | -------------------------------------------------------------------------------- /.github/scripts/utils.zsh/check_linux: -------------------------------------------------------------------------------- 1 | autoload -Uz log_info log_status log_error log_debug log_warning log_group 2 | 3 | log_group 'Check Linux build requirements' 4 | log_debug 'Checking Linux distribution name and version...' 5 | 6 | # Check for Ubuntu version 22.10 or later, which have srt and librist available via apt-get 7 | typeset -g -i UBUNTU_2210_OR_LATER=0 8 | if [[ -f /etc/os_release ]] { 9 | local dist_name 10 | local dist_version 11 | read -r dist_name dist_version <<< "$(source /etc/os_release; print "${NAME} ${VERSION_ID}")" 12 | 13 | autoload -Uz is-at-least 14 | if [[ ${dist_name} == Ubuntu ]] && is-at-least 22.10 ${dist_version}; then 15 | typeset -g -i UBUNTU_2210_OR_LATER=1 16 | fi 17 | } 18 | 19 | log_debug 'Checking for apt-get...' 20 | if (( ! ${+commands[apt-get]} )) { 21 | log_error 'No apt-get command found. Please install apt' 22 | return 2 23 | } else { 24 | log_debug "Apt-get located at ${commands[apt-get]}" 25 | } 26 | 27 | local -a dependencies=("${(fA)$(<${SCRIPT_HOME}/.Aptfile)}") 28 | local -a install_list 29 | local binary 30 | 31 | sudo apt-get update -qq 32 | 33 | for dependency (${dependencies}) { 34 | local -a tokens=(${=dependency//(,|:|\')/}) 35 | 36 | if [[ ! ${tokens[1]} == 'package' ]] continue 37 | 38 | if [[ ${#tokens} -gt 2 && ${tokens[3]} == 'bin' ]] { 39 | binary=${tokens[4]} 40 | } else { 41 | binary=${tokens[2]} 42 | } 43 | 44 | if (( ! ${+commands[${binary}]} )) install_list+=(${tokens[2]}) 45 | } 46 | 47 | log_debug "List of dependencies to install: ${install_list}" 48 | if (( ${#install_list} )) { 49 | if (( ! ${+CI} )) log_warning 'Dependency installation via apt may require elevated privileges' 50 | 51 | local -a apt_args=( 52 | ${CI:+-y} 53 | --no-install-recommends 54 | ) 55 | if (( _loglevel == 0 )) apt_args+=(--quiet) 56 | 57 | sudo apt-get ${apt_args} install ${install_list} 58 | } 59 | 60 | rehash 61 | log_group 62 | -------------------------------------------------------------------------------- /cmake/linux/toolchains/x86_64-linux-clang.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 3 | set(CMAKE_CROSSCOMPILING TRUE) 4 | 5 | set(CMAKE_C_COMPILER /usr/bin/clang) 6 | set(CMAKE_CXX_COMPILER /usr/bin/clang++) 7 | 8 | set(CMAKE_C_COMPILER_TARGET x86_64-linux-gnu) 9 | set(CMAKE_CXX_COMPILER_TARGET x86_64-linux-gnu) 10 | 11 | set(CMAKE_FIND_ROOT_PATH /usr/x86_64-linux-gnu) 12 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 13 | set(PKG_CONFIG_EXECUTABLE 14 | /usr/bin/x86_64-linux-gnu-pkg-config 15 | CACHE FILEPATH "pkg-config executable") 16 | 17 | execute_process( 18 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-ranlib 19 | OUTPUT_VARIABLE CMAKE_RANLIB 20 | OUTPUT_STRIP_TRAILING_WHITESPACE) 21 | 22 | execute_process( 23 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-ar 24 | OUTPUT_VARIABLE CMAKE_LLVM_AR 25 | OUTPUT_STRIP_TRAILING_WHITESPACE) 26 | 27 | execute_process( 28 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-readelf 29 | OUTPUT_VARIABLE READELF 30 | OUTPUT_STRIP_TRAILING_WHITESPACE) 31 | 32 | execute_process( 33 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-objcopy 34 | OUTPUT_VARIABLE CMAKE_LLVM_OBJCOPY 35 | OUTPUT_STRIP_TRAILING_WHITESPACE) 36 | 37 | execute_process( 38 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-objdump 39 | OUTPUT_VARIABLE CMAKE_LLVM_OBJDUMP 40 | OUTPUT_STRIP_TRAILING_WHITESPACE) 41 | 42 | set(CMAKE_AR 43 | "${CMAKE_LLVM_AR}" 44 | CACHE INTERNAL "${CMAKE_SYSTEM_NAME} ar" FORCE) 45 | set(CMAKE_OBJCOPY 46 | "${CMAKE_LLVM_OBJCOPY}" 47 | CACHE INTERNAL "${CMAKE_SYSTEM_NAME} objcopy" FORCE) 48 | set(CMAKE_OBJDUMP 49 | "${CMAKE_LLVM_OBJDUMP}" 50 | CACHE INTERNAL "${CMAKE_SYSTEM_NAME} objdump" FORCE) 51 | 52 | set(CPACK_READELF_EXECUTABLE "${READELF}") 53 | set(CPACK_OBJCOPY_EXECUTABLE "${CMAKE_LLVM_OBJCOPY}") 54 | set(CPACK_OBJDUMP_EXECUTABLE "${CMAKE_LLVM_OBJDUMP}") 55 | set(CPACK_PACKAGE_ARCHITECTURE x86_64) 56 | set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE x86_64) 57 | -------------------------------------------------------------------------------- /cmake/linux/toolchains/aarch64-linux-clang.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 3 | set(CMAKE_CROSSCOMPILING TRUE) 4 | 5 | set(CMAKE_C_COMPILER /usr/bin/clang) 6 | set(CMAKE_CXX_COMPILER /usr/bin/clang++) 7 | 8 | set(CMAKE_C_COMPILER_TARGET aarch64-linux-gnu) 9 | set(CMAKE_CXX_COMPILER_TARGET aarch64-linux-gnu) 10 | 11 | set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) 12 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 13 | set(PKG_CONFIG_EXECUTABLE 14 | /usr/bin/aarch64-linux-gnu-pkg-config 15 | CACHE FILEPATH "pkg-config executable") 16 | 17 | execute_process( 18 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-ranlib 19 | OUTPUT_VARIABLE CMAKE_RANLIB 20 | OUTPUT_STRIP_TRAILING_WHITESPACE) 21 | 22 | execute_process( 23 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-ar 24 | OUTPUT_VARIABLE CMAKE_LLVM_AR 25 | OUTPUT_STRIP_TRAILING_WHITESPACE) 26 | 27 | execute_process( 28 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-readelf 29 | OUTPUT_VARIABLE READELF 30 | OUTPUT_STRIP_TRAILING_WHITESPACE) 31 | 32 | execute_process( 33 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-objcopy 34 | OUTPUT_VARIABLE CMAKE_LLVM_OBJCOPY 35 | OUTPUT_STRIP_TRAILING_WHITESPACE) 36 | 37 | execute_process( 38 | COMMAND ${CMAKE_C_COMPILER} -print-prog-name=llvm-objdump 39 | OUTPUT_VARIABLE CMAKE_LLVM_OBJDUMP 40 | OUTPUT_STRIP_TRAILING_WHITESPACE) 41 | 42 | set(CMAKE_AR 43 | "${CMAKE_LLVM_AR}" 44 | CACHE INTERNAL "${CMAKE_SYSTEM_NAME} ar" FORCE) 45 | set(CMAKE_OBJCOPY 46 | "${CMAKE_LLVM_OBJCOPY}" 47 | CACHE INTERNAL "${CMAKE_SYSTEM_NAME} objcopy" FORCE) 48 | set(CMAKE_OBJDUMP 49 | "${CMAKE_LLVM_OBJDUMP}" 50 | CACHE INTERNAL "${CMAKE_SYSTEM_NAME} objdump" FORCE) 51 | 52 | set(CPACK_READELF_EXECUTABLE "${READELF}") 53 | set(CPACK_OBJCOPY_EXECUTABLE "${CMAKE_LLVM_OBJCOPY}") 54 | set(CPACK_OBJDUMP_EXECUTABLE "${CMAKE_LLVM_OBJDUMP}") 55 | set(CPACK_PACKAGE_ARCHITECTURE arm64) 56 | set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE arm64) 57 | -------------------------------------------------------------------------------- /cmake/macos/resources/create-package.cmake.in: -------------------------------------------------------------------------------- 1 | make_directory("$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/package/Library/Application Support/obs-studio/plugins") 2 | 3 | if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@CMAKE_PROJECT_NAME@.plugin" AND NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@CMAKE_PROJECT_NAME@.plugin") 4 | file(INSTALL DESTINATION "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/package/Library/Application Support/obs-studio/plugins" 5 | TYPE DIRECTORY FILES "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@CMAKE_PROJECT_NAME@.plugin" USE_SOURCE_PERMISSIONS) 6 | 7 | if(CMAKE_INSTALL_CONFIG_NAME MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$" OR CMAKE_INSTALL_CONFIG_NAME MATCHES "^([Mm][Ii][Nn][Ss][Ii][Zz][Ee][Rr][Ee][Ll])$") 8 | if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@CMAKE_PROJECT_NAME@.plugin.dSYM" AND NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@CMAKE_PROJECT_NAME@.plugin.dSYM") 9 | file(INSTALL DESTINATION "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/package/Library/Application Support/obs-studio/plugins" TYPE DIRECTORY FILES "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@CMAKE_PROJECT_NAME@.plugin.dSYM" USE_SOURCE_PERMISSIONS) 10 | endif() 11 | endif() 12 | endif() 13 | 14 | make_directory("$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/temp") 15 | 16 | execute_process( 17 | COMMAND /usr/bin/pkgbuild 18 | --identifier '@MACOS_BUNDLEID@' 19 | --version '@CMAKE_PROJECT_VERSION@' 20 | --root "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/package" 21 | "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/temp/@CMAKE_PROJECT_NAME@.pkg" 22 | COMMAND_ERROR_IS_FATAL ANY 23 | ) 24 | 25 | execute_process( 26 | COMMAND /usr/bin/productbuild 27 | --distribution "@CMAKE_CURRENT_BINARY_DIR@/distribution" 28 | --package-path "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/temp" 29 | "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@CMAKE_PROJECT_NAME@.pkg" 30 | COMMAND_ERROR_IS_FATAL ANY) 31 | 32 | if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@CMAKE_PROJECT_NAME@.pkg") 33 | file(REMOVE_RECURSE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/temp") 34 | file(REMOVE_RECURSE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/package") 35 | endif() 36 | -------------------------------------------------------------------------------- /.github/actions/run-cmake-format/action.yaml: -------------------------------------------------------------------------------- 1 | name: Run cmake-format 2 | description: Runs cmake-format and checks for any changes introduced by it 3 | inputs: 4 | failCondition: 5 | description: Controls whether failed checks also fail the workflow run 6 | required: false 7 | default: 'never' 8 | workingDirectory: 9 | description: Working directory for checks 10 | required: false 11 | default: ${{ github.workspace }} 12 | runs: 13 | using: composite 14 | steps: 15 | - name: Check Runner Operating System 🏃‍♂️ 16 | if: runner.os == 'Windows' 17 | shell: bash 18 | run: | 19 | : Check Runner Operating System 🏃‍♂️ 20 | echo "::notice::run-cmake-format action requires a macOS-based or Linux-based runner." 21 | exit 2 22 | 23 | - name: Install Dependencies 🛍️ 24 | if: runner.os == 'Linux' 25 | shell: bash 26 | run: | 27 | : Install Dependencies 🛍️ 28 | echo ::group::Install Dependencies 29 | eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" 30 | echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH 31 | brew install --quiet zsh 32 | echo ::endgroup:: 33 | 34 | - name: Run cmake-format 🎛️ 35 | id: result 36 | shell: zsh --no-rcs --errexit --pipefail {0} 37 | working-directory: ${{ github.workspace }} 38 | env: 39 | GITHUB_EVENT_FORCED: ${{ github.event.forced }} 40 | GITHUB_REF_BEFORE: ${{ github.event.before }} 41 | run: | 42 | : Run cmake-format 🎛️ 43 | if (( ${+RUNNER_DEBUG} )) setopt XTRACE 44 | 45 | local -a changes=($(git diff --name-only HEAD~1 HEAD)) 46 | case ${GITHUB_EVENT_NAME} { 47 | pull_request) changes=($(git diff --name-only origin/${GITHUB_BASE_REF} HEAD)) ;; 48 | push) if [[ ${GITHUB_EVENT_FORCED} != true ]] changes=($(git diff --name-only ${GITHUB_REF_BEFORE} HEAD)) ;; 49 | *) ;; 50 | } 51 | 52 | if (( ${changes[(I)*.cmake|*CMakeLists.txt]} )) { 53 | echo ::group::Install cmakelang 54 | pip3 install cmakelang 55 | echo ::endgroup:: 56 | echo ::group::Run cmake-format 57 | ./build-aux/run-cmake-format --fail-${{ inputs.failCondition }} --check 58 | echo ::endgroup:: 59 | } 60 | -------------------------------------------------------------------------------- /cmake/macos/compilerconfig.cmake: -------------------------------------------------------------------------------- 1 | # CMake macOS compiler configuration module 2 | 3 | include_guard(GLOBAL) 4 | 5 | include(ccache) 6 | include(compiler_common) 7 | 8 | add_compile_options(-fopenmp-simd) 9 | 10 | if(XCODE) 11 | # Use Xcode's standard architecture selection 12 | set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)") 13 | # Enable dSYM generation for Release builds 14 | string(APPEND CMAKE_C_FLAGS_RELEASE " -g") 15 | string(APPEND CMAKE_CXX_FLAGS_RELEASE " -g") 16 | else() 17 | option(ENABLE_COMPILER_TRACE "Enable clang time-trace (requires Ninja)" OFF) 18 | mark_as_advanced(ENABLE_COMPILER_TRACE) 19 | 20 | # clang options for ObjC 21 | set(_obs_clang_objc_options 22 | # cmake-format: sortable 23 | -Werror=block-capture-autoreleasing -Wno-selector -Wno-strict-selector-match -Wnon-virtual-dtor -Wprotocol 24 | -Wundeclared-selector) 25 | 26 | # clang options for ObjC++ 27 | set(_obs_clang_objcxx_options 28 | # cmake-format: sortable 29 | ${_obs_clang_objc_options} -Warc-repeated-use-of-weak -Wno-arc-maybe-repeated-use-of-weak) 30 | 31 | add_compile_options( 32 | "$<$:${_obs_clang_c_options}>" "$<$:${_obs_clang_cxx_options}>" 33 | "$<$:${_obs_clang_objc_options}>" 34 | "$<$:${_obs_clang_objcxx_options}>") 35 | 36 | # Enable stripping of dead symbols when not building for Debug configuration 37 | set(_release_configs RelWithDebInfo Release MinSizeRel) 38 | if(CMAKE_BUILD_TYPE IN_LIST _release_configs) 39 | add_link_options(LINKER:-dead_strip) 40 | endif() 41 | 42 | # Enable color diagnostics for AppleClang 43 | set(CMAKE_COLOR_DIAGNOSTICS ON) 44 | # Set universal architectures via CMake flag for non-Xcode generators 45 | set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64") 46 | 47 | # Enable compiler and build tracing (requires Ninja generator) 48 | if(ENABLE_COMPILER_TRACE AND CMAKE_GENERATOR STREQUAL "Ninja") 49 | add_compile_options($<$:-ftime-trace> $<$:-ftime-trace>) 50 | else() 51 | set(ENABLE_COMPILER_TRACE 52 | OFF 53 | CACHE STRING "Enable clang time-trace (requires Ninja)" FORCE) 54 | endif() 55 | endif() 56 | 57 | add_compile_definitions($<$:DEBUG> $<$:_DEBUG> SIMDE_ENABLE_OPENMP) 58 | -------------------------------------------------------------------------------- /.github/actions/run-clang-format/action.yaml: -------------------------------------------------------------------------------- 1 | name: Run clang-format 2 | description: Runs clang-format and checks for any changes introduced by it 3 | inputs: 4 | failCondition: 5 | description: Controls whether failed checks also fail the workflow run 6 | required: false 7 | default: 'never' 8 | workingDirectory: 9 | description: Working directory for checks 10 | required: false 11 | default: ${{ github.workspace }} 12 | runs: 13 | using: composite 14 | steps: 15 | - name: Check Runner Operating System 🏃‍♂️ 16 | if: runner.os == 'Windows' 17 | shell: bash 18 | run: | 19 | : Check Runner Operating System 🏃‍♂️ 20 | echo "::notice::run-clang-format action requires a macOS-based or Linux-based runner." 21 | exit 2 22 | 23 | - name: Install Dependencies 🛍️ 24 | if: runner.os == 'Linux' 25 | shell: bash 26 | run: | 27 | : Install Dependencies 🛍️ 28 | echo ::group::Install Dependencies 29 | eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" 30 | echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH 31 | echo "/home/linuxbrew/.linuxbrew/opt/clang-format@13/bin" >> $GITHUB_PATH 32 | brew install --quiet zsh 33 | echo ::endgroup:: 34 | 35 | - name: Run clang-format 🐉 36 | id: result 37 | shell: zsh --no-rcs --errexit --pipefail {0} 38 | working-directory: ${{ inputs.workingDirectory }} 39 | env: 40 | GITHUB_EVENT_FORCED: ${{ github.event.forced }} 41 | GITHUB_REF_BEFORE: ${{ github.event.before }} 42 | run: | 43 | : Run clang-format 🐉 44 | if (( ${+RUNNER_DEBUG} )) setopt XTRACE 45 | 46 | local -a changes=($(git diff --name-only HEAD~1 HEAD)) 47 | case ${GITHUB_EVENT_NAME} { 48 | pull_request) changes=($(git diff --name-only origin/${GITHUB_BASE_REF} HEAD)) ;; 49 | push) if [[ ${GITHUB_EVENT_FORCED} != true ]] changes=($(git diff --name-only ${GITHUB_REF_BEFORE} HEAD)) ;; 50 | *) ;; 51 | } 52 | 53 | if (( ${changes[(I)(*.c|*.h|*.cpp|*.hpp|*.m|*.mm)]} )) { 54 | echo ::group::Install clang-format-13 55 | brew install --quiet obsproject/tools/clang-format@13 56 | echo ::endgroup:: 57 | 58 | echo ::group::Run clang-format-13 59 | ./build-aux/run-clang-format --fail-${{ inputs.failCondition }} --check 60 | echo ::endgroup:: 61 | } 62 | -------------------------------------------------------------------------------- /cmake/common/compiler_common.cmake: -------------------------------------------------------------------------------- 1 | # CMake common compiler options module 2 | 3 | include_guard(GLOBAL) 4 | 5 | # Set C and C++ language standards to C17 and C++17 6 | if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21) 7 | set(CMAKE_C_STANDARD 17) 8 | else() 9 | set(CMAKE_C_STANDARD 11) 10 | endif() 11 | set(CMAKE_C_STANDARD_REQUIRED TRUE) 12 | set(CMAKE_CXX_STANDARD 17) 13 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 14 | 15 | # Set symbols to be hidden by default for C and C++ 16 | set(CMAKE_C_VISIBILITY_PRESET hidden) 17 | set(CMAKE_CXX_VISIBILITY_PRESET hidden) 18 | set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) 19 | 20 | # clang options for C 21 | set(_obs_clang_c_options 22 | # cmake-format: sortable 23 | -fno-strict-aliasing 24 | -Wbool-conversion 25 | -Wcomma 26 | -Wconstant-conversion 27 | -Wdeprecated-declarations 28 | -Wempty-body 29 | -Wenum-conversion 30 | -Werror=return-type 31 | -Wextra 32 | -Wformat 33 | -Wformat-security 34 | -Wfour-char-constants 35 | -Winfinite-recursion 36 | -Wint-conversion 37 | -Wnewline-eof 38 | -Wno-conversion 39 | -Wno-float-conversion 40 | -Wno-implicit-fallthrough 41 | -Wno-missing-braces 42 | -Wno-missing-field-initializers 43 | -Wno-missing-prototypes 44 | -Wno-semicolon-before-method-body 45 | -Wno-shadow 46 | -Wno-sign-conversion 47 | -Wno-strict-prototypes 48 | -Wno-trigraphs 49 | -Wno-unknown-pragmas 50 | -Wno-unused-function 51 | -Wno-unused-label 52 | -Wnon-literal-null-conversion 53 | -Wobjc-literal-conversion 54 | -Wparentheses 55 | -Wpointer-sign 56 | -Wquoted-include-in-framework-header 57 | -Wshadow 58 | -Wshorten-64-to-32 59 | -Wuninitialized 60 | -Wunreachable-code 61 | -Wunused-parameter 62 | -Wunused-value 63 | -Wunused-variable 64 | -Wvla) 65 | 66 | # clang options for C++ 67 | set(_obs_clang_cxx_options 68 | # cmake-format: sortable 69 | ${_obs_clang_c_options} 70 | -Wconversion 71 | -Wdeprecated-implementations 72 | -Wduplicate-method-match 73 | -Wfloat-conversion 74 | -Wfour-char-constants 75 | -Wimplicit-retain-self 76 | -Winvalid-offsetof 77 | -Wmove 78 | -Wno-c++11-extensions 79 | -Wno-exit-time-destructors 80 | -Wno-implicit-atomic-properties 81 | -Wno-objc-interface-ivars 82 | -Wno-overloaded-virtual 83 | -Wrange-loop-analysis) 84 | 85 | if(NOT DEFINED CMAKE_COMPILE_WARNING_AS_ERROR) 86 | set(CMAKE_COMPILE_WARNING_AS_ERROR ON) 87 | endif() 88 | -------------------------------------------------------------------------------- /src/llm-dock/LLMSettingsDialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "llama-inference.h" 4 | #include "llm-config-data.h" 5 | #include "plugin-support.h" 6 | 7 | #include "LLMSettingsDialog.hpp" 8 | #include "ui/ui_settingsdialog.h" 9 | 10 | #include 11 | 12 | LLMSettingsDialog::LLMSettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) 13 | { 14 | ui->setupUi(this); 15 | // load settings from config 16 | ui->sysPrompt->setPlainText(QString::fromStdString(global_llm_config.system_prompt)); 17 | ui->maxTokens->setText(QString::number(global_llm_config.max_output_tokens)); 18 | ui->temperature->setText(QString::number(global_llm_config.temperature)); 19 | ui->apiKey->setText(QString::fromStdString(global_llm_config.cloud_api_key)); 20 | ui->apiModel->setText(QString::fromStdString(global_llm_config.cloud_model_name)); 21 | ui->localLlmPath->setText(QString::fromStdString(global_llm_config.local_model_path)); 22 | ui->dockLLM->setCurrentIndex(global_llm_config.local ? 0 : 1); 23 | 24 | // File dialog 25 | connect(this->ui->localLlmPathButton, &QPushButton::clicked, this, [=]() { 26 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", 27 | tr("Model Files (*.gguf)")); 28 | if (fileName != "") { 29 | this->ui->localLlmPath->setText(fileName); 30 | } 31 | }); 32 | 33 | // connect to the dialog Save action to save the settings 34 | this->connect(this->ui->buttonBox, &QDialogButtonBox::accepted, this, [=]() { 35 | // get settings from UI into config struct 36 | global_llm_config.local = this->ui->dockLLM->currentIndex() == 0; 37 | global_llm_config.local_model_path = this->ui->localLlmPath->text().toStdString(); 38 | global_llm_config.cloud_api_key = this->ui->apiKey->text().toStdString(); 39 | global_llm_config.cloud_model_name = this->ui->apiModel->text().toStdString(); 40 | global_llm_config.system_prompt = this->ui->sysPrompt->toPlainText().toStdString(); 41 | global_llm_config.end_sequence = this->ui->endSeq->text().toStdString(); 42 | global_llm_config.max_output_tokens = this->ui->maxTokens->text().toUShort(); 43 | global_llm_config.temperature = this->ui->temperature->text().toFloat(); 44 | 45 | // serialize to json and save to the OBS module settings 46 | if (saveConfig() == OBS_BRAIN_CONFIG_SUCCESS) { 47 | obs_log(LOG_INFO, "Saved LLM settings"); 48 | } else { 49 | obs_log(LOG_ERROR, "Failed to save LLM settings"); 50 | } 51 | 52 | // close the dialog 53 | this->close(); 54 | }); 55 | } 56 | 57 | LLMSettingsDialog::~LLMSettingsDialog() {} 58 | -------------------------------------------------------------------------------- /cmake/windows/resources/installer-Windows.iss.in: -------------------------------------------------------------------------------- 1 | #define MyAppName "@CMAKE_PROJECT_NAME@" 2 | #define MyAppVersion "@CMAKE_PROJECT_VERSION@" 3 | #define MyAppPublisher "@PLUGIN_AUTHOR@" 4 | #define MyAppURL "@PLUGIN_WEBSITE@" 5 | 6 | [Setup] 7 | ; NOTE: The value of AppId uniquely identifies this application. 8 | ; Do not use the same AppId value in installers for other applications. 9 | ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) 10 | AppId={{@UUID_APP@} 11 | AppName={#MyAppName} 12 | AppVersion={#MyAppVersion} 13 | AppPublisher={#MyAppPublisher} 14 | AppPublisherURL={#MyAppURL} 15 | AppSupportURL={#MyAppURL} 16 | AppUpdatesURL={#MyAppURL} 17 | DefaultDirName={code:GetDirName} 18 | DefaultGroupName={#MyAppName} 19 | OutputBaseFilename={#MyAppName}-{#MyAppVersion}-Windows-Installer 20 | Compression=lzma 21 | SolidCompression=yes 22 | DirExistsWarning=no 23 | 24 | [Languages] 25 | Name: "english"; MessagesFile: "compiler:Default.isl" 26 | 27 | [Files] 28 | Source: "..\release\Package\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs 29 | Source: "..\LICENSE"; Flags: dontcopy 30 | ; NOTE: Don't use "Flags: ignoreversion" on any shared system files 31 | 32 | [Icons] 33 | Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}" 34 | Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" 35 | 36 | [Code] 37 | procedure InitializeWizard(); 38 | var 39 | GPLText: AnsiString; 40 | Page: TOutputMsgMemoWizardPage; 41 | begin 42 | ExtractTemporaryFile('LICENSE'); 43 | LoadStringFromFile(ExpandConstant('{tmp}\LICENSE'), GPLText); 44 | Page := CreateOutputMsgMemoPage(wpWelcome, 45 | 'License Information', 'Please review the license terms before installing {#MyAppName}', 46 | 'Press Page Down to see the rest of the agreement. Once you are aware of your rights, click Next to continue.', 47 | String(GPLText) 48 | ); 49 | end; 50 | 51 | // credit where it's due : 52 | // following function come from https://github.com/Xaymar/obs-studio_amf-encoder-plugin/blob/master/%23Resources/Installer.in.iss#L45 53 | function GetDirName(Value: string): string; 54 | var 55 | InstallPath: string; 56 | begin 57 | // initialize default path, which will be returned when the following registry 58 | // key queries fail due to missing keys or for some different reason 59 | Result := '{autopf}\obs-studio'; 60 | // query the first registry value; if this succeeds, return the obtained value 61 | if RegQueryStringValue(HKLM32, 'SOFTWARE\OBS Studio', '', InstallPath) then 62 | Result := InstallPath 63 | end; 64 | 65 | -------------------------------------------------------------------------------- /.github/scripts/utils.pwsh/Install-BuildDependencies.ps1: -------------------------------------------------------------------------------- 1 | function Install-BuildDependencies { 2 | <# 3 | .SYNOPSIS 4 | Installs required build dependencies. 5 | .DESCRIPTION 6 | Additional packages might be needed for successful builds. This module contains additional 7 | dependencies available for installation via winget and, if possible, adds their locations 8 | to the environment path for future invocation. 9 | .EXAMPLE 10 | Install-BuildDependencies 11 | #> 12 | 13 | param( 14 | [string] $WingetFile = "$PSScriptRoot/.Wingetfile" 15 | ) 16 | 17 | if ( ! ( Test-Path function:Log-Warning ) ) { 18 | . $PSScriptRoot/Logger.ps1 19 | } 20 | 21 | $Prefixes = @{ 22 | 'x64' = ${Env:ProgramFiles} 23 | 'x86' = ${Env:ProgramFiles(x86)} 24 | 'arm64' = ${Env:ProgramFiles(arm)} 25 | } 26 | 27 | $Paths = $Env:Path -split [System.IO.Path]::PathSeparator 28 | 29 | $WingetOptions = @('install', '--accept-package-agreements', '--accept-source-agreements') 30 | 31 | if ( $script:Quiet ) { 32 | $WingetOptions += '--silent' 33 | } 34 | 35 | Log-Group 'Check Windows build requirements' 36 | Get-Content $WingetFile | ForEach-Object { 37 | $_, $Package, $_, $Path, $_, $Binary, $_, $Version = $_ -replace ',','' -split " +(?=(?:[^\']*\'[^\']*\')*[^\']*$)" -replace "'",'' 38 | 39 | $Prefixes.GetEnumerator() | ForEach-Object { 40 | $Prefix = $_.value 41 | $FullPath = "${Prefix}\${Path}" 42 | if ( ( Test-Path $FullPath ) -and ! ( $Paths -contains $FullPath ) ) { 43 | $Paths = @($FullPath) + $Paths 44 | $Env:Path = $Paths -join [System.IO.Path]::PathSeparator 45 | } 46 | } 47 | 48 | Log-Debug "Checking for command ${Binary}" 49 | $Found = Get-Command -ErrorAction SilentlyContinue $Binary 50 | 51 | if ( $Found ) { 52 | Log-Status "Found dependency ${Binary} as $($Found.Source)" 53 | } else { 54 | Log-Status "Installing package ${Package} $(if ( $Version -ne $null ) { "Version: ${Version}" } )" 55 | 56 | if ( $Version -ne $null ) { 57 | $WingetOptions += @('--version', ${Version}) 58 | } 59 | 60 | try { 61 | $Params = $WingetOptions + $Package 62 | 63 | winget @Params 64 | } catch { 65 | throw "Error while installing winget package ${Package}: $_" 66 | } 67 | } 68 | } 69 | Log-Group 70 | } 71 | -------------------------------------------------------------------------------- /.github/scripts/utils.pwsh/Expand-ArchiveExt.ps1: -------------------------------------------------------------------------------- 1 | function Expand-ArchiveExt { 2 | <# 3 | .SYNOPSIS 4 | Expands archive files. 5 | .DESCRIPTION 6 | Allows extraction of zip, 7z, gz, and xz archives. 7 | Requires tar and 7-zip to be available on the system. 8 | Archives ending with .zip but created using LZMA compression are 9 | expanded using 7-zip as a fallback. 10 | .EXAMPLE 11 | Expand-ArchiveExt -Path 12 | Expand-ArchiveExt -Path -DestinationPath 13 | #> 14 | 15 | param( 16 | [Parameter(Mandatory)] 17 | [string] $Path, 18 | [string] $DestinationPath = [System.IO.Path]::GetFileNameWithoutExtension($Path), 19 | [switch] $Force 20 | ) 21 | 22 | switch ( [System.IO.Path]::GetExtension($Path) ) { 23 | .zip { 24 | try { 25 | Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force:$Force 26 | } catch { 27 | if ( Get-Command 7z ) { 28 | Invoke-External 7z x -y $Path "-o${DestinationPath}" 29 | } else { 30 | throw "Fallback utility 7-zip not found. Please install 7-zip first." 31 | } 32 | } 33 | break 34 | } 35 | { ( $_ -eq ".7z" ) -or ( $_ -eq ".exe" ) } { 36 | if ( Get-Command 7z ) { 37 | Invoke-External 7z x -y $Path "-o${DestinationPath}" 38 | } else { 39 | throw "Extraction utility 7-zip not found. Please install 7-zip first." 40 | } 41 | break 42 | } 43 | .gz { 44 | try { 45 | Invoke-External tar -x -o $DestinationPath -f $Path 46 | } catch { 47 | if ( Get-Command 7z ) { 48 | Invoke-External 7z x -y $Path "-o${DestinationPath}" 49 | } else { 50 | throw "Fallback utility 7-zip not found. Please install 7-zip first." 51 | } 52 | } 53 | break 54 | } 55 | .xz { 56 | try { 57 | Invoke-External tar -x -o $DestinationPath -f $Path 58 | } catch { 59 | if ( Get-Command 7z ) { 60 | Invoke-External 7z x -y $Path "-o${DestinationPath}" 61 | } else { 62 | throw "Fallback utility 7-zip not found. Please install 7-zip first." 63 | } 64 | } 65 | } 66 | default { 67 | throw "Unsupported archive extension provided." 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /cmake/linux/helpers.cmake: -------------------------------------------------------------------------------- 1 | # CMake Linux helper functions module 2 | 3 | include_guard(GLOBAL) 4 | 5 | include(helpers_common) 6 | 7 | # set_target_properties_plugin: Set target properties for use in obs-studio 8 | function(set_target_properties_plugin target) 9 | set(options "") 10 | set(oneValueArgs "") 11 | set(multiValueArgs PROPERTIES) 12 | cmake_parse_arguments(PARSE_ARGV 0 _STPO "${options}" "${oneValueArgs}" "${multiValueArgs}") 13 | 14 | message(DEBUG "Setting additional properties for target ${target}...") 15 | 16 | while(_STPO_PROPERTIES) 17 | list(POP_FRONT _STPO_PROPERTIES key value) 18 | set_property(TARGET ${target} PROPERTY ${key} "${value}") 19 | endwhile() 20 | 21 | set_target_properties( 22 | ${target} 23 | PROPERTIES VERSION 0 24 | SOVERSION ${PLUGIN_VERSION} 25 | PREFIX "") 26 | 27 | install( 28 | TARGETS ${target} 29 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 30 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/obs-plugins) 31 | 32 | if(TARGET plugin-support) 33 | target_link_libraries(${target} PRIVATE plugin-support) 34 | endif() 35 | 36 | target_install_resources(${target}) 37 | 38 | get_target_property(target_sources ${target} SOURCES) 39 | set(target_ui_files ${target_sources}) 40 | list(FILTER target_ui_files INCLUDE REGEX ".+\\.(ui|qrc)") 41 | source_group( 42 | TREE "${CMAKE_CURRENT_SOURCE_DIR}" 43 | PREFIX "UI Files" 44 | FILES ${target_ui_files}) 45 | endfunction() 46 | 47 | # Helper function to add resources into bundle 48 | function(target_install_resources target) 49 | message(DEBUG "Installing resources for target ${target}...") 50 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/data") 51 | file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*") 52 | foreach(data_file IN LISTS data_files) 53 | cmake_path(RELATIVE_PATH data_file BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" OUTPUT_VARIABLE 54 | relative_path) 55 | cmake_path(GET relative_path PARENT_PATH relative_path) 56 | target_sources(${target} PRIVATE "${data_file}") 57 | source_group("Resources/${relative_path}" FILES "${data_file}") 58 | endforeach() 59 | 60 | install( 61 | DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" 62 | DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/obs/obs-plugins/${target} 63 | USE_SOURCE_PERMISSIONS) 64 | endif() 65 | endfunction() 66 | 67 | # Helper function to add a specific resource to a bundle 68 | function(target_add_resource target resource) 69 | message(DEBUG "Add resource '${resource}' to target ${target} at destination '${target_destination}'...") 70 | 71 | install(FILES "${resource}" DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/obs/obs-plugins/${target}) 72 | 73 | source_group("Resources" FILES "${resource}") 74 | endfunction() 75 | -------------------------------------------------------------------------------- /cmake/linux/defaults.cmake: -------------------------------------------------------------------------------- 1 | # CMake Linux defaults module 2 | 3 | # cmake-format: off 4 | # cmake-lint: disable=C0103 5 | # cmake-lint: disable=C0111 6 | # cmake-format: on 7 | 8 | include_guard(GLOBAL) 9 | 10 | include(GNUInstallDirs) 11 | 12 | # Enable find_package targets to become globally available targets 13 | set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE) 14 | 15 | set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") 16 | set(CPACK_PACKAGE_VERSION "${CMAKE_PROJECT_VERSION}") 17 | set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_C_LIBRARY_ARCHITECTURE}") 18 | 19 | set(CPACK_GENERATOR "DEB") 20 | set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) 21 | set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${PLUGIN_EMAIL}") 22 | set(CPACK_SET_DESTDIR ON) 23 | 24 | if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.25.0 OR NOT CMAKE_CROSSCOMPILING) 25 | set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON) 26 | endif() 27 | 28 | set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/release") 29 | 30 | set(CPACK_SOURCE_GENERATOR "TXZ") 31 | set(CPACK_SOURCE_IGNORE_FILES 32 | # cmake-format: sortable 33 | ".*~$" 34 | \\.git/ 35 | \\.github/ 36 | \\.gitignore 37 | build_.* 38 | cmake/\\.CMakeBuildNumber 39 | release/) 40 | 41 | set(CPACK_VERBATIM_VARIABLES YES) 42 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-source") 43 | set(CPACK_ARCHIVE_THREADS 0) 44 | 45 | include(CPack) 46 | 47 | find_package(libobs QUIET) 48 | 49 | if(NOT TARGET OBS::libobs) 50 | find_package(LibObs REQUIRED) 51 | add_library(OBS::libobs ALIAS libobs) 52 | 53 | if(ENABLE_FRONTEND_API) 54 | find_path( 55 | obs-frontend-api_INCLUDE_DIR 56 | NAMES obs-frontend-api.h 57 | PATHS /usr/include /usr/local/include 58 | PATH_SUFFIXES obs) 59 | 60 | find_library( 61 | obs-frontend-api_LIBRARY 62 | NAMES obs-frontend-api 63 | PATHS /usr/lib /usr/local/lib) 64 | 65 | if(obs-frontend-api_LIBRARY) 66 | if(NOT TARGET OBS::obs-frontend-api) 67 | if(IS_ABSOLUTE "${obs-frontend-api_LIBRARY}") 68 | add_library(OBS::obs-frontend-api UNKNOWN IMPORTED) 69 | set_property(TARGET OBS::obs-frontend-api PROPERTY IMPORTED_LOCATION "${obs-frontend-api_LIBRARY}") 70 | else() 71 | add_library(OBS::obs-frontend-api INTERFACE IMPORTED) 72 | set_property(TARGET OBS::obs-frontend-api PROPERTY IMPORTED_LIBNAME "${obs-frontend-api_LIBRARY}") 73 | endif() 74 | 75 | set_target_properties(OBS::obs-frontend-api PROPERTIES INTERFACE_INCLUDE_DIRECTORIES 76 | "${obs-frontend-api_INCLUDE_DIR}") 77 | endif() 78 | endif() 79 | endif() 80 | 81 | macro(find_package) 82 | if(NOT "${ARGV0}" STREQUAL libobs AND NOT "${ARGV0}" STREQUAL obs-frontend-api) 83 | _find_package(${ARGV}) 84 | endif() 85 | endmacro() 86 | endif() 87 | -------------------------------------------------------------------------------- /cmake/common/bootstrap.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16...3.26) 2 | 3 | include_guard(GLOBAL) 4 | 5 | # Enable automatic PUSH and POP of policies to parent scope 6 | if(POLICY CMP0011) 7 | cmake_policy(SET CMP0011 NEW) 8 | endif() 9 | 10 | # Enable distinction between Clang and AppleClang 11 | if(POLICY CMP0025) 12 | cmake_policy(SET CMP0025 NEW) 13 | endif() 14 | 15 | # Enable strict checking of "break()" usage 16 | if(POLICY CMP0055) 17 | cmake_policy(SET CMP0055 NEW) 18 | endif() 19 | 20 | # Honor visibility presets for all target types (executable, shared, module, static) 21 | if(POLICY CMP0063) 22 | cmake_policy(SET CMP0063 NEW) 23 | endif() 24 | 25 | # Disable export function calls to populate package registry by default 26 | if(POLICY CMP0090) 27 | cmake_policy(SET CMP0090 NEW) 28 | endif() 29 | 30 | # Prohibit in-source builds 31 | if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") 32 | message(FATAL_ERROR "In-source builds are not supported. " 33 | "Specify a build directory via 'cmake -S -B ' instead.") 34 | file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt" "${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles") 35 | endif() 36 | 37 | # Use folders for source file organization with IDE generators (Visual Studio/Xcode) 38 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 39 | 40 | # Add common module directories to default search path 41 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/common") 42 | 43 | file(READ "${CMAKE_CURRENT_SOURCE_DIR}/buildspec.json" buildspec) 44 | 45 | # cmake-format: off 46 | string(JSON _name GET ${buildspec} name) 47 | string(JSON _website GET ${buildspec} website) 48 | string(JSON _author GET ${buildspec} author) 49 | string(JSON _email GET ${buildspec} email) 50 | string(JSON _version GET ${buildspec} version) 51 | string(JSON _bundleId GET ${buildspec} platformConfig macos bundleId) 52 | string(JSON _macosPackageUUID GET ${buildspec} uuids macosPackage) 53 | string(JSON _macosInstallerUUID GET ${buildspec} uuids macosInstaller) 54 | string(JSON _windowsAppUUID GET ${buildspec} uuids windowsApp) 55 | # cmake-format: on 56 | 57 | set(PLUGIN_AUTHOR ${_author}) 58 | set(PLUGIN_WEBSITE ${_website}) 59 | set(PLUGIN_EMAIL ${_email}) 60 | set(PLUGIN_VERSION ${_version}) 61 | set(MACOS_BUNDLEID ${_bundleId}) 62 | 63 | include(buildnumber) 64 | include(osconfig) 65 | 66 | # Allow selection of common build types via UI 67 | if(NOT CMAKE_BUILD_TYPE) 68 | set(CMAKE_BUILD_TYPE 69 | "RelWithDebInfo" 70 | CACHE STRING "OBS build type [Release, RelWithDebInfo, Debug, MinSizeRel]" FORCE) 71 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release RelWithDebInfo Debug MinSizeRel) 72 | endif() 73 | 74 | # Disable exports automatically going into the CMake package registry 75 | set(CMAKE_EXPORT_PACKAGE_REGISTRY FALSE) 76 | # Enable default inclusion of targets' source and binary directory 77 | set(CMAKE_INCLUDE_CURRENT_DIR TRUE) 78 | -------------------------------------------------------------------------------- /cmake/linux/compilerconfig.cmake: -------------------------------------------------------------------------------- 1 | # CMake Linux compiler configuration module 2 | 3 | include_guard(GLOBAL) 4 | 5 | include(ccache) 6 | include(compiler_common) 7 | 8 | option(ENABLE_COMPILER_TRACE "Enable Clang time-trace (required Clang and Ninja)" OFF) 9 | mark_as_advanced(ENABLE_COMPILER_TRACE) 10 | 11 | # gcc options for C 12 | set(_obs_gcc_c_options 13 | # cmake-format: sortable 14 | -fno-strict-aliasing 15 | -fopenmp-simd 16 | -Wdeprecated-declarations 17 | -Wempty-body 18 | -Wenum-conversion 19 | -Werror=return-type 20 | -Wextra 21 | -Wformat 22 | -Wformat-security 23 | -Wno-conversion 24 | -Wno-float-conversion 25 | -Wno-implicit-fallthrough 26 | -Wno-missing-braces 27 | -Wno-missing-field-initializers 28 | -Wno-shadow 29 | -Wno-sign-conversion 30 | -Wno-trigraphs 31 | -Wno-unknown-pragmas 32 | -Wno-unused-function 33 | -Wno-unused-label 34 | -Wparentheses 35 | -Wshadow 36 | -Wuninitialized 37 | -Wunreachable-code 38 | -Wunused-parameter 39 | -Wunused-value 40 | -Wunused-variable 41 | -Wvla) 42 | 43 | # gcc options for C++ 44 | set(_obs_gcc_cxx_options 45 | # cmake-format: sortable 46 | ${_obs_gcc_c_options} -Wconversion -Wfloat-conversion -Winvalid-offsetof -Wno-overloaded-virtual) 47 | 48 | add_compile_options( 49 | -fopenmp-simd 50 | "$<$:${_obs_gcc_c_options}>" 51 | "$<$:-Wint-conversion;-Wno-missing-prototypes;-Wno-strict-prototypes;-Wpointer-sign>" 52 | "$<$:${_obs_gcc_cxx_options}>" 53 | "$<$:${_obs_clang_c_options}>" 54 | "$<$:${_obs_clang_cxx_options}>") 55 | 56 | # Add support for color diagnostics and CMake switch for warnings as errors to CMake < 3.24 57 | if(CMAKE_VERSION VERSION_LESS 3.24.0) 58 | add_compile_options($<$:-fcolor-diagnostics> $<$:-fcolor-diagnostics>) 59 | if(CMAKE_COMPILE_WARNING_AS_ERROR) 60 | add_compile_options(-Werror) 61 | endif() 62 | else() 63 | set(CMAKE_COLOR_DIAGNOSTICS ON) 64 | endif() 65 | 66 | if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) 67 | # Disable false-positive warning in GCC 12.1.0 and later 68 | add_compile_options(-Wno-error=maybe-uninitialized) 69 | 70 | # Add warning for infinite recursion (added in GCC 12) 71 | if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0.0) 72 | add_compile_options(-Winfinite-recursion) 73 | endif() 74 | endif() 75 | 76 | # Enable compiler and build tracing (requires Ninja generator) 77 | if(ENABLE_COMPILER_TRACE AND CMAKE_GENERATOR STREQUAL "Ninja") 78 | add_compile_options($<$:-ftime-trace> $<$:-ftime-trace>) 79 | else() 80 | set(ENABLE_COMPILER_TRACE 81 | OFF 82 | CACHE STRING "Enable Clang time-trace (required Clang and Ninja)" FORCE) 83 | endif() 84 | 85 | add_compile_definitions($<$:DEBUG> $<$:_DEBUG> SIMDE_ENABLE_OPENMP) 86 | -------------------------------------------------------------------------------- /.github/scripts/Package-Windows.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param( 3 | [ValidateSet('x64')] 4 | [string] $Target = 'x64', 5 | [ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')] 6 | [string] $Configuration = 'RelWithDebInfo', 7 | [switch] $BuildInstaller, 8 | [switch] $SkipDeps 9 | ) 10 | 11 | $ErrorActionPreference = 'Stop' 12 | 13 | if ( $DebugPreference -eq 'Continue' ) { 14 | $VerbosePreference = 'Continue' 15 | $InformationPreference = 'Continue' 16 | } 17 | 18 | if ( ! ( [System.Environment]::Is64BitOperatingSystem ) ) { 19 | throw "Packaging script requires a 64-bit system to build and run." 20 | } 21 | 22 | 23 | if ( $PSVersionTable.PSVersion -lt '7.0.0' ) { 24 | Write-Warning 'The packaging script requires PowerShell Core 7. Install or upgrade your PowerShell version: https://aka.ms/pscore6' 25 | exit 2 26 | } 27 | 28 | function Package { 29 | trap { 30 | Pop-Location -Stack BuildTemp -ErrorAction 'SilentlyContinue' 31 | Write-Error $_ 32 | Log-Group 33 | exit 2 34 | } 35 | 36 | $ScriptHome = $PSScriptRoot 37 | $ProjectRoot = Resolve-Path -Path "$PSScriptRoot/../.." 38 | $BuildSpecFile = "${ProjectRoot}/buildspec.json" 39 | 40 | $UtilityFunctions = Get-ChildItem -Path $PSScriptRoot/utils.pwsh/*.ps1 -Recurse 41 | 42 | foreach( $Utility in $UtilityFunctions ) { 43 | Write-Debug "Loading $($Utility.FullName)" 44 | . $Utility.FullName 45 | } 46 | 47 | $BuildSpec = Get-Content -Path ${BuildSpecFile} -Raw | ConvertFrom-Json 48 | $ProductName = $BuildSpec.name 49 | $ProductVersion = $BuildSpec.version 50 | 51 | $OutputName = "${ProductName}-${ProductVersion}-windows-${Target}" 52 | 53 | if ( ! $SkipDeps ) { 54 | Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile" 55 | } 56 | 57 | $RemoveArgs = @{ 58 | ErrorAction = 'SilentlyContinue' 59 | Path = @( 60 | "${ProjectRoot}/release/${ProductName}-*-windows-*.zip" 61 | "${ProjectRoot}/release/${ProductName}-*-windows-*.exe" 62 | ) 63 | } 64 | 65 | Remove-Item @RemoveArgs 66 | 67 | if ( ( $BuildInstaller ) ) { 68 | Log-Group "Packaging ${ProductName}..." 69 | $IsccFile = "${ProjectRoot}/build_${Target}/installer-Windows.generated.iss" 70 | 71 | if ( ! ( Test-Path -Path $IsccFile ) ) { 72 | throw 'InnoSetup install script not found. Run the build script or the CMake build and install procedures first.' 73 | } 74 | 75 | Log-Information 'Creating InnoSetup installer...' 76 | Push-Location -Stack BuildTemp 77 | Ensure-Location -Path "${ProjectRoot}/release" 78 | Copy-Item -Path ${Configuration} -Destination Package -Recurse 79 | Invoke-External iscc ${IsccFile} /O"${ProjectRoot}/release" /F"${OutputName}-Installer" 80 | Remove-Item -Path Package -Recurse 81 | Pop-Location -Stack BuildTemp 82 | } else { 83 | Log-Group "Archiving ${ProductName}..." 84 | $CompressArgs = @{ 85 | Path = (Get-ChildItem -Path "${ProjectRoot}/release/${Configuration}" -Exclude "${OutputName}*.*") 86 | CompressionLevel = 'Optimal' 87 | DestinationPath = "${ProjectRoot}/release/${OutputName}.zip" 88 | Verbose = ($Env:CI -ne $null) 89 | } 90 | 91 | Compress-Archive -Force @CompressArgs 92 | } 93 | Log-Group 94 | } 95 | 96 | Package 97 | -------------------------------------------------------------------------------- /.github/scripts/Build-Windows.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param( 3 | [ValidateSet('x64')] 4 | [string] $Target = 'x64', 5 | [ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')] 6 | [string] $Configuration = 'RelWithDebInfo', 7 | [switch] $SkipAll, 8 | [switch] $SkipBuild, 9 | [switch] $SkipDeps 10 | ) 11 | 12 | $ErrorActionPreference = 'Stop' 13 | 14 | if ( $DebugPreference -eq 'Continue' ) { 15 | $VerbosePreference = 'Continue' 16 | $InformationPreference = 'Continue' 17 | } 18 | 19 | if ( ! ( [System.Environment]::Is64BitOperatingSystem ) ) { 20 | throw "A 64-bit system is required to build the project." 21 | } 22 | 23 | if ( $PSVersionTable.PSVersion -lt '7.0.0' ) { 24 | Write-Warning 'The obs-deps PowerShell build script requires PowerShell Core 7. Install or upgrade your PowerShell version: https://aka.ms/pscore6' 25 | exit 2 26 | } 27 | 28 | function Build { 29 | trap { 30 | Pop-Location -Stack BuildTemp -ErrorAction 'SilentlyContinue' 31 | Write-Error $_ 32 | Log-Group 33 | exit 2 34 | } 35 | 36 | $ScriptHome = $PSScriptRoot 37 | $ProjectRoot = Resolve-Path -Path "$PSScriptRoot/../.." 38 | $BuildSpecFile = "${ProjectRoot}/buildspec.json" 39 | 40 | $UtilityFunctions = Get-ChildItem -Path $PSScriptRoot/utils.pwsh/*.ps1 -Recurse 41 | 42 | foreach($Utility in $UtilityFunctions) { 43 | Write-Debug "Loading $($Utility.FullName)" 44 | . $Utility.FullName 45 | } 46 | 47 | $BuildSpec = Get-Content -Path ${BuildSpecFile} -Raw | ConvertFrom-Json 48 | $ProductName = $BuildSpec.name 49 | $ProductVersion = $BuildSpec.version 50 | 51 | if ( ! $SkipDeps ) { 52 | Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile" 53 | } 54 | 55 | Push-Location -Stack BuildTemp 56 | if ( ! ( ( $SkipAll ) -or ( $SkipBuild ) ) ) { 57 | Ensure-Location $ProjectRoot 58 | 59 | $CmakeArgs = @() 60 | $CmakeBuildArgs = @() 61 | $CmakeInstallArgs = @() 62 | 63 | if ( $VerbosePreference -eq 'Continue' ) { 64 | $CmakeBuildArgs += ('--verbose') 65 | $CmakeInstallArgs += ('--verbose') 66 | } 67 | 68 | if ( $DebugPreference -eq 'Continue' ) { 69 | $CmakeArgs += ('--debug-output') 70 | } 71 | 72 | $Preset = "windows-$(if ( $Env:CI -ne $null ) { 'ci-' })${Target}" 73 | 74 | $CmakeArgs += @( 75 | '--preset', $Preset 76 | ) 77 | 78 | $CmakeBuildArgs += @( 79 | '--build' 80 | '--preset', $Preset 81 | '--config', $Configuration 82 | '--parallel' 83 | '--', '/consoleLoggerParameters:Summary', '/noLogo' 84 | ) 85 | 86 | $CmakeInstallArgs += @( 87 | '--install', "build_${Target}" 88 | '--prefix', "${ProjectRoot}/release/${Configuration}" 89 | '--config', $Configuration 90 | ) 91 | 92 | Log-Group "Configuring ${ProductName}..." 93 | Invoke-External cmake @CmakeArgs 94 | 95 | Log-Group "Building ${ProductName}..." 96 | Invoke-External cmake @CmakeBuildArgs 97 | } 98 | Log-Group "Install ${ProductName}..." 99 | Invoke-External cmake @CmakeInstallArgs 100 | 101 | Pop-Location -Stack BuildTemp 102 | Log-Group 103 | } 104 | 105 | Build 106 | -------------------------------------------------------------------------------- /.github/actions/build-plugin/action.yaml: -------------------------------------------------------------------------------- 1 | name: 'Set up and build plugin' 2 | description: 'Builds the plugin for specified architecture and build config' 3 | inputs: 4 | target: 5 | description: 'Target architecture for dependencies' 6 | required: true 7 | config: 8 | description: 'Build configuration' 9 | required: false 10 | default: 'RelWithDebInfo' 11 | codesign: 12 | description: 'Enable codesigning (macOS only)' 13 | required: false 14 | default: 'false' 15 | codesignIdent: 16 | description: 'Developer ID for application codesigning (macOS only)' 17 | required: false 18 | default: '-' 19 | workingDirectory: 20 | description: 'Working directory for packaging' 21 | required: false 22 | default: ${{ github.workspace }} 23 | runs: 24 | using: composite 25 | steps: 26 | - name: Run macOS Build 27 | if: runner.os == 'macOS' 28 | shell: zsh --no-rcs --errexit --pipefail {0} 29 | working-directory: ${{ inputs.workingDirectory }} 30 | env: 31 | CODESIGN_IDENT: ${{ inputs.codesignIdent }} 32 | CODESIGN_TEAM: ${{ inputs.codesignTeam }} 33 | run: | 34 | : Run macOS Build 35 | 36 | local -a build_args=(--config ${{ inputs.config }}) 37 | if (( ${+RUNNER_DEBUG} )) build_args+=(--debug) 38 | 39 | if [[ '${{ inputs.codesign }}' == 'true' ]] build_args+=(--codesign) 40 | 41 | .github/scripts/build-macos ${build_args} 42 | 43 | - name: Install Dependencies 🛍️ 44 | if: runner.os == 'Linux' 45 | shell: bash 46 | run: | 47 | : Install Dependencies 🛍️ 48 | echo ::group::Install Dependencies 49 | eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" 50 | echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH 51 | brew install --quiet zsh 52 | echo ::endgroup:: 53 | 54 | - name: Run Ubuntu Build 55 | if: runner.os == 'Linux' 56 | shell: zsh --no-rcs --errexit --pipefail {0} 57 | working-directory: ${{ inputs.workingDirectory }} 58 | run: | 59 | : Run Ubuntu Build 60 | 61 | local -a build_args=( 62 | --target linux-${{ inputs.target }} 63 | --config ${{ inputs.config }} 64 | ) 65 | if (( ${+RUNNER_DEBUG} )) build_args+=(--debug) 66 | 67 | .github/scripts/build-linux ${build_args} 68 | 69 | - name: Run Windows Build 70 | if: runner.os == 'Windows' 71 | shell: pwsh 72 | run: | 73 | # Run Windows Build 74 | if ( $Env:RUNNER_DEBUG -ne $null ) { 75 | Set-PSDebug -Trace 1 76 | } 77 | 78 | $BuildArgs = @{ 79 | Target = '${{ inputs.target }}' 80 | Configuration = '${{ inputs.config }}' 81 | } 82 | 83 | .github/scripts/Build-Windows.ps1 @BuildArgs 84 | 85 | - name: Create Summary 📊 86 | if: contains(fromJSON('["Linux", "macOS"]'),runner.os) 87 | shell: zsh --no-rcs --errexit --pipefail {0} 88 | env: 89 | CCACHE_CONFIGPATH: ${{ inputs.workingDirectory }}/.ccache.conf 90 | run: | 91 | : Create Summary 📊 92 | 93 | local -a ccache_data 94 | if (( ${+RUNNER_DEBUG} )) { 95 | setopt XTRACE 96 | ccache_data=("${(fA)$(ccache -s -vv)}") 97 | } else { 98 | ccache_data=("${(fA)$(ccache -s)}") 99 | } 100 | 101 | print '### ${{ runner.os }} Ccache Stats (${{ inputs.target }})' >> $GITHUB_STEP_SUMMARY 102 | print '```' >> $GITHUB_STEP_SUMMARY 103 | for line (${ccache_data}) { 104 | print ${line} >> $GITHUB_STEP_SUMMARY 105 | } 106 | print '```' >> $GITHUB_STEP_SUMMARY 107 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # please use clang-format version 8 or later 2 | 3 | Standard: Cpp11 4 | AccessModifierOffset: -8 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: false 7 | AlignConsecutiveDeclarations: false 8 | AlignEscapedNewlines: Left 9 | AlignOperands: true 10 | AlignTrailingComments: true 11 | #AllowAllArgumentsOnNextLine: false # requires clang-format 9 12 | #AllowAllConstructorInitializersOnNextLine: false # requires clang-format 9 13 | AllowAllParametersOfDeclarationOnNextLine: false 14 | AllowShortBlocksOnASingleLine: false 15 | AllowShortCaseLabelsOnASingleLine: false 16 | AllowShortFunctionsOnASingleLine: Inline 17 | AllowShortIfStatementsOnASingleLine: false 18 | #AllowShortLambdasOnASingleLine: Inline # requires clang-format 9 19 | AllowShortLoopsOnASingleLine: false 20 | AlwaysBreakAfterDefinitionReturnType: None 21 | AlwaysBreakAfterReturnType: None 22 | AlwaysBreakBeforeMultilineStrings: false 23 | AlwaysBreakTemplateDeclarations: false 24 | BinPackArguments: true 25 | BinPackParameters: true 26 | BraceWrapping: 27 | AfterClass: false 28 | AfterControlStatement: false 29 | AfterEnum: false 30 | AfterFunction: true 31 | AfterNamespace: false 32 | AfterObjCDeclaration: false 33 | AfterStruct: false 34 | AfterUnion: false 35 | AfterExternBlock: false 36 | BeforeCatch: false 37 | BeforeElse: false 38 | IndentBraces: false 39 | SplitEmptyFunction: true 40 | SplitEmptyRecord: true 41 | SplitEmptyNamespace: true 42 | BreakBeforeBinaryOperators: None 43 | BreakBeforeBraces: Custom 44 | BreakBeforeTernaryOperators: true 45 | BreakConstructorInitializers: BeforeColon 46 | BreakStringLiterals: false # apparently unpredictable 47 | ColumnLimit: 100 48 | CompactNamespaces: false 49 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 50 | ConstructorInitializerIndentWidth: 8 51 | ContinuationIndentWidth: 8 52 | Cpp11BracedListStyle: true 53 | DerivePointerAlignment: false 54 | DisableFormat: false 55 | FixNamespaceComments: false 56 | ForEachMacros: 57 | - 'json_object_foreach' 58 | - 'json_object_foreach_safe' 59 | - 'json_array_foreach' 60 | - 'HASH_ITER' 61 | IncludeBlocks: Preserve 62 | IndentCaseLabels: false 63 | IndentPPDirectives: None 64 | IndentWidth: 8 65 | IndentWrappedFunctionNames: false 66 | KeepEmptyLinesAtTheStartOfBlocks: true 67 | MaxEmptyLinesToKeep: 1 68 | NamespaceIndentation: None 69 | #ObjCBinPackProtocolList: Auto # requires clang-format 7 70 | ObjCBlockIndentWidth: 8 71 | ObjCSpaceAfterProperty: true 72 | ObjCSpaceBeforeProtocolList: true 73 | 74 | PenaltyBreakAssignment: 10 75 | PenaltyBreakBeforeFirstCallParameter: 30 76 | PenaltyBreakComment: 10 77 | PenaltyBreakFirstLessLess: 0 78 | PenaltyBreakString: 10 79 | PenaltyExcessCharacter: 100 80 | PenaltyReturnTypeOnItsOwnLine: 60 81 | 82 | PointerAlignment: Right 83 | ReflowComments: false 84 | SortIncludes: false 85 | SortUsingDeclarations: false 86 | SpaceAfterCStyleCast: false 87 | #SpaceAfterLogicalNot: false # requires clang-format 9 88 | SpaceAfterTemplateKeyword: false 89 | SpaceBeforeAssignmentOperators: true 90 | #SpaceBeforeCtorInitializerColon: true # requires clang-format 7 91 | #SpaceBeforeInheritanceColon: true # requires clang-format 7 92 | SpaceBeforeParens: ControlStatements 93 | #SpaceBeforeRangeBasedForLoopColon: true # requires clang-format 7 94 | SpaceInEmptyParentheses: false 95 | SpacesBeforeTrailingComments: 1 96 | SpacesInAngles: false 97 | SpacesInCStyleCastParentheses: false 98 | SpacesInContainerLiterals: false 99 | SpacesInParentheses: false 100 | SpacesInSquareBrackets: false 101 | #StatementMacros: # requires clang-format 8 102 | # - 'Q_OBJECT' 103 | TabWidth: 8 104 | #TypenameMacros: # requires clang-format 9 105 | # - 'DARRAY' 106 | UseTab: ForContinuationAndIndentation 107 | --- 108 | Language: ObjC 109 | -------------------------------------------------------------------------------- /src/llm-dock/ui/workflows.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Workflows 4 | 5 | 6 | 7 | 0 8 | 0 9 | 600 10 | 120 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 600 22 | 0 23 | 24 | 25 | 26 | Workflows 27 | 28 | 29 | 30 | 3 31 | 32 | 33 | 3 34 | 35 | 36 | 3 37 | 38 | 39 | 3 40 | 41 | 42 | 43 | 44 | QFrame::Panel 45 | 46 | 47 | QFrame::Plain 48 | 49 | 50 | 1 51 | 52 | 53 | QAbstractScrollArea::AdjustToContents 54 | 55 | 56 | true 57 | 58 | 59 | 60 | 61 | 0 62 | 0 63 | 592 64 | 70 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 0 76 | 0 77 | 78 | 79 | 80 | 81 | 0 82 | 83 | 84 | 0 85 | 86 | 87 | 0 88 | 89 | 90 | 0 91 | 92 | 93 | 94 | 95 | 96 | 0 97 | 0 98 | 99 | 100 | 101 | Add Workflow 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 0 110 | 0 111 | 112 | 113 | 114 | Save 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /src/llm-dock/Workflows.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Workflows.hpp" 4 | #include "ui/ui_workflows.h" 5 | #include "ui/ui_workflow.h" 6 | #include "plugin-support.h" 7 | #include "llm-config-data.h" 8 | 9 | #include 10 | #include 11 | 12 | class Workflow : public QWidget { 13 | public: 14 | Workflow(QWidget *parent = nullptr) : QWidget(parent), ui(new Ui::Workflow) 15 | { 16 | ui->setupUi(this); 17 | } 18 | ~Workflow() { delete ui; } 19 | 20 | Ui::Workflow *ui; 21 | }; 22 | 23 | Workflows::Workflows(QWidget *parent) : QDialog(parent), ui(new Ui::Workflows) 24 | { 25 | ui->setupUi(this); 26 | 27 | // get the list of workflows from the OBS module settings and add them to the list 28 | for (size_t i = 0; i < global_llm_config.workflows.size(); i++) { 29 | nlohmann::json workflowJson = nlohmann::json::parse(global_llm_config.workflows[i]); 30 | Workflow *workflow = new Workflow(this); 31 | ui->workflowsLayout->addWidget(workflow); 32 | workflow->ui->workflowGroupBox->setTitle( 33 | "Workflow " + QString::number(ui->workflowsLayout->count())); 34 | workflow->ui->prompt->setPlainText(QString::fromStdString(workflowJson["prompt"])); 35 | workflow->ui->source->setCurrentText( 36 | QString::fromStdString(workflowJson["source"])); 37 | workflow->ui->sourceFile->setText( 38 | QString::fromStdString(workflowJson["sourceFile"])); 39 | workflow->ui->target->setCurrentText( 40 | QString::fromStdString(workflowJson["target"])); 41 | workflow->ui->targetFile->setText( 42 | QString::fromStdString(workflowJson["targetFile"])); 43 | workflow->ui->localCloud->setCurrentText( 44 | QString::fromStdString(workflowJson["localOrCloud"])); 45 | workflow->ui->streaming->setChecked(workflowJson["streaming"]); 46 | workflow->ui->trigger->setCurrentText( 47 | QString::fromStdString(workflowJson["trigger_onChange_or_periodic"])); 48 | workflow->ui->timeMs->setText(QString::number((int)workflowJson["triggerMs"])); 49 | } 50 | 51 | connect(ui->add, &QPushButton::clicked, this, [=]() { 52 | // Add a new workflow to the list 53 | Workflow *workflow = new Workflow(this); 54 | ui->workflowsLayout->addWidget(workflow); 55 | workflow->ui->workflowGroupBox->setTitle( 56 | "Workflow " + QString::number(ui->workflowsLayout->count())); 57 | this->adjustSize(); 58 | }); 59 | 60 | connect(ui->save, &QPushButton::clicked, this, [=]() { 61 | // Serialize all workflows to json and save to the OBS module settings 62 | global_llm_config.workflows.clear(); 63 | for (int i = 0; i < ui->workflowsLayout->count(); i++) { 64 | Workflow *workflow = (Workflow *)ui->workflowsLayout->itemAt(i)->widget(); 65 | nlohmann::json workflowJson; 66 | workflowJson["prompt"] = workflow->ui->prompt->toPlainText().toStdString(); 67 | workflowJson["source"] = 68 | workflow->ui->source->itemText(workflow->ui->source->currentIndex()) 69 | .toStdString(); 70 | workflowJson["sourceFile"] = workflow->ui->sourceFile->text().toStdString(); 71 | workflowJson["target"] = 72 | workflow->ui->target->itemText(workflow->ui->target->currentIndex()) 73 | .toStdString(); 74 | workflowJson["targetFile"] = workflow->ui->targetFile->text().toStdString(); 75 | workflowJson["localOrCloud"] = 76 | workflow->ui->localCloud 77 | ->itemText(workflow->ui->localCloud->currentIndex()) 78 | .toStdString(); 79 | workflowJson["streaming"] = workflow->ui->streaming->isChecked(); 80 | workflowJson["trigger_onChange_or_periodic"] = 81 | workflow->ui->trigger 82 | ->itemText(workflow->ui->trigger->currentIndex()) 83 | .toStdString(); 84 | workflowJson["triggerMs"] = workflow->ui->timeMs->text().toUInt(); 85 | global_llm_config.workflows.push_back(workflowJson.dump()); 86 | } 87 | if (saveConfig() == OBS_BRAIN_CONFIG_SUCCESS) { 88 | obs_log(LOG_INFO, "Saved LLM settings"); 89 | } else { 90 | obs_log(LOG_ERROR, "Failed to save LLM settings"); 91 | } 92 | // close the dialog 93 | this->close(); 94 | }); 95 | } 96 | 97 | Workflows::~Workflows() 98 | { 99 | delete ui; 100 | } 101 | -------------------------------------------------------------------------------- /.github/scripts/utils.pwsh/Logger.ps1: -------------------------------------------------------------------------------- 1 | function Log-Debug { 2 | [CmdletBinding()] 3 | param( 4 | [Parameter(Mandatory,ValueFromPipeline)] 5 | [ValidateNotNullOrEmpty()] 6 | [string[]] $Message 7 | ) 8 | 9 | Process { 10 | foreach($m in $Message) { 11 | Write-Debug "$(if ( $env:CI -ne $null ) { '::debug::' })$m" 12 | } 13 | } 14 | } 15 | 16 | function Log-Verbose { 17 | [CmdletBinding()] 18 | param( 19 | [Parameter(Mandatory,ValueFromPipeline)] 20 | [ValidateNotNullOrEmpty()] 21 | [string[]] $Message 22 | ) 23 | 24 | Process { 25 | foreach($m in $Message) { 26 | Write-Verbose $m 27 | } 28 | } 29 | } 30 | 31 | function Log-Warning { 32 | [CmdletBinding()] 33 | param( 34 | [Parameter(Mandatory,ValueFromPipeline)] 35 | [ValidateNotNullOrEmpty()] 36 | [string[]] $Message 37 | ) 38 | 39 | Process { 40 | foreach($m in $Message) { 41 | Write-Warning "$(if ( $env:CI -ne $null ) { '::warning::' })$m" 42 | } 43 | } 44 | } 45 | 46 | function Log-Error { 47 | [CmdletBinding()] 48 | param( 49 | [Parameter(Mandatory,ValueFromPipeline)] 50 | [ValidateNotNullOrEmpty()] 51 | [string[]] $Message 52 | ) 53 | 54 | Process { 55 | foreach($m in $Message) { 56 | Write-Error "$(if ( $env:CI -ne $null ) { '::error::' })$m" 57 | } 58 | } 59 | } 60 | 61 | function Log-Information { 62 | [CmdletBinding()] 63 | param( 64 | [Parameter(Mandatory,ValueFromPipeline)] 65 | [ValidateNotNullOrEmpty()] 66 | [string[]] $Message 67 | ) 68 | 69 | Process { 70 | if ( ! ( $script:Quiet ) ) { 71 | $StageName = $( if ( $script:StageName -ne $null ) { $script:StageName } else { '' }) 72 | $Icon = ' =>' 73 | 74 | foreach($m in $Message) { 75 | Write-Host -NoNewLine -ForegroundColor Blue " ${StageName} $($Icon.PadRight(5)) " 76 | Write-Host "${m}" 77 | } 78 | } 79 | } 80 | } 81 | 82 | function Log-Group { 83 | [CmdletBinding()] 84 | param( 85 | [Parameter(ValueFromPipeline)] 86 | [string[]] $Message 87 | ) 88 | 89 | Process { 90 | if ( $Env:CI -ne $null ) { 91 | if ( $script:LogGroup ) { 92 | Write-Output '::endgroup::' 93 | $script:LogGroup = $false 94 | } 95 | 96 | if ( $Message.count -ge 1 ) { 97 | Write-Output "::group::$($Message -join ' ')" 98 | $script:LogGroup = $true 99 | } 100 | } else { 101 | if ( $Message.count -ge 1 ) { 102 | Log-Information $Message 103 | } 104 | } 105 | } 106 | } 107 | 108 | function Log-Status { 109 | [CmdletBinding()] 110 | param( 111 | [Parameter(Mandatory,ValueFromPipeline)] 112 | [ValidateNotNullOrEmpty()] 113 | [string[]] $Message 114 | ) 115 | 116 | Process { 117 | if ( ! ( $script:Quiet ) ) { 118 | $StageName = $( if ( $StageName -ne $null ) { $StageName } else { '' }) 119 | $Icon = ' >' 120 | 121 | foreach($m in $Message) { 122 | Write-Host -NoNewLine -ForegroundColor Green " ${StageName} $($Icon.PadRight(5)) " 123 | Write-Host "${m}" 124 | } 125 | } 126 | } 127 | } 128 | 129 | function Log-Output { 130 | [CmdletBinding()] 131 | param( 132 | [Parameter(Mandatory,ValueFromPipeline)] 133 | [ValidateNotNullOrEmpty()] 134 | [string[]] $Message 135 | ) 136 | 137 | Process { 138 | if ( ! ( $script:Quiet ) ) { 139 | $StageName = $( if ( $script:StageName -ne $null ) { $script:StageName } else { '' }) 140 | $Icon = '' 141 | 142 | foreach($m in $Message) { 143 | Write-Output " ${StageName} $($Icon.PadRight(5)) ${m}" 144 | } 145 | } 146 | } 147 | } 148 | 149 | $Columns = (Get-Host).UI.RawUI.WindowSize.Width - 5 150 | -------------------------------------------------------------------------------- /.github/actions/package-plugin/action.yaml: -------------------------------------------------------------------------------- 1 | name: 'Package plugin' 2 | description: 'Packages the plugin for specified architecture and build config.' 3 | inputs: 4 | target: 5 | description: 'Build target for dependencies' 6 | required: true 7 | config: 8 | description: 'Build configuration' 9 | required: false 10 | default: 'RelWithDebInfo' 11 | codesign: 12 | description: 'Enable codesigning (macOS only)' 13 | required: false 14 | default: 'false' 15 | notarize: 16 | description: 'Enable notarization (macOS only)' 17 | required: false 18 | default: 'false' 19 | codesignIdent: 20 | description: 'Developer ID for application codesigning (macOS only)' 21 | required: false 22 | default: '-' 23 | installerIdent: 24 | description: 'Developer ID for installer package codesigning (macOS only)' 25 | required: false 26 | default: '' 27 | codesignTeam: 28 | description: 'Developer team for codesigning (macOS only)' 29 | required: false 30 | default: '' 31 | codesignUser: 32 | description: 'Apple ID username for notarization (macOS only)' 33 | required: false 34 | default: '' 35 | codesignPass: 36 | description: 'Apple ID password for notarization (macOS only)' 37 | required: false 38 | default: '' 39 | package: 40 | description: 'Create Windows or macOS installation package' 41 | required: false 42 | default: 'false' 43 | workingDirectory: 44 | description: 'Working directory for packaging' 45 | required: false 46 | default: ${{ github.workspace }} 47 | runs: 48 | using: composite 49 | steps: 50 | - name: Run macOS Packaging 51 | if: runner.os == 'macOS' 52 | shell: zsh --no-rcs --errexit --pipefail {0} 53 | working-directory: ${{ inputs.workingDirectory }} 54 | env: 55 | CODESIGN_IDENT: ${{ inputs.codesignIdent }} 56 | CODESIGN_IDENT_INSTALLER: ${{ inputs.installerIdent }} 57 | CODESIGN_TEAM: ${{ inputs.codesignTeam }} 58 | CODESIGN_IDENT_USER: ${{ inputs.codesignUser }} 59 | CODESIGN_IDENT_PASS: ${{ inputs.codesignPass }} 60 | run: | 61 | : Run macOS Packaging 62 | 63 | local -a package_args=(--config ${{ inputs.config }}) 64 | if (( ${+RUNNER_DEBUG} )) package_args+=(--debug) 65 | 66 | if [[ '${{ inputs.codesign }}' == 'true' ]] package_args+=(--codesign) 67 | if [[ '${{ inputs.notarize }}' == 'true' ]] package_args+=(--notarize) 68 | if [[ '${{ inputs.package }}' == 'true' ]] package_args+=(--package) 69 | 70 | .github/scripts/package-macos ${package_args} 71 | 72 | - name: Install Dependencies 🛍️ 73 | if: runner.os == 'Linux' 74 | shell: bash 75 | run: | 76 | : Install Dependencies 🛍️ 77 | echo ::group::Install Dependencies 78 | eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" 79 | echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH 80 | brew install --quiet zsh 81 | echo ::endgroup:: 82 | 83 | - name: Run Ubuntu Packaging 84 | if: runner.os == 'Linux' 85 | shell: zsh --no-rcs --errexit --pipefail {0} 86 | working-directory: ${{ inputs.workingDirectory }} 87 | run: | 88 | : Run Ubuntu Packaging 89 | package_args=( 90 | --target linux-${{ inputs.target }} 91 | --config ${{ inputs.config }} 92 | ) 93 | if (( ${+RUNNER_DEBUG} )) build_args+=(--debug) 94 | 95 | if [[ '${{ inputs.package }}' == 'true' ]] package_args+=(--package) 96 | 97 | .github/scripts/package-linux ${package_args} 98 | 99 | - name: Run Windows Packaging 100 | if: runner.os == 'Windows' 101 | shell: pwsh 102 | run: | 103 | # Run Windows Packaging 104 | if ( $Env:RUNNER_DEBUG -ne $null ) { 105 | Set-PSDebug -Trace 1 106 | } 107 | 108 | $PackageArgs = @{ 109 | Target = '${{ inputs.target }}' 110 | Configuration = '${{ inputs.config }}' 111 | } 112 | 113 | if ( '${{ inputs.package }}' -eq 'true' ) { 114 | $PackageArgs += @{BuildInstaller = $true} 115 | } 116 | 117 | .github/scripts/Package-Windows.ps1 @PackageArgs 118 | -------------------------------------------------------------------------------- /.github/workflows/push.yaml: -------------------------------------------------------------------------------- 1 | name: Push to master 2 | run-name: ${{ github.ref_name }} push run 🚀 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - main 8 | - 'release/**' 9 | tags: 10 | - '*' 11 | permissions: 12 | contents: write 13 | concurrency: 14 | group: '${{ github.workflow }} @ ${{ github.ref }}' 15 | cancel-in-progress: ${{ github.ref_type == 'tag' }} 16 | jobs: 17 | check-format: 18 | name: Check Formatting 🔍 19 | if: github.ref_name == 'master' 20 | uses: ./.github/workflows/check-format.yaml 21 | permissions: 22 | contents: read 23 | 24 | build-project: 25 | name: Build Project 🧱 26 | uses: ./.github/workflows/build-project.yaml 27 | secrets: inherit 28 | permissions: 29 | contents: read 30 | 31 | create-release: 32 | name: Create Release 🛫 33 | if: github.ref_type == 'tag' 34 | runs-on: ubuntu-22.04 35 | needs: build-project 36 | defaults: 37 | run: 38 | shell: bash 39 | steps: 40 | - name: Check Release Tag ☑️ 41 | id: check 42 | run: | 43 | : Check Release Tag ☑️ 44 | if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi 45 | shopt -s extglob 46 | 47 | case "${GITHUB_REF_NAME}" in 48 | +([0-9]).+([0-9]).+([0-9]) ) 49 | echo 'validTag=true' >> $GITHUB_OUTPUT 50 | echo 'prerelease=false' >> $GITHUB_OUTPUT 51 | echo "version=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT 52 | ;; 53 | +([0-9]).+([0-9]).+([0-9])-@(beta|rc)*([0-9]) ) 54 | echo 'validTag=true' >> $GITHUB_OUTPUT 55 | echo 'prerelease=true' >> $GITHUB_OUTPUT 56 | echo "version=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT 57 | ;; 58 | *) echo 'validTag=false' >> $GITHUB_OUTPUT ;; 59 | esac 60 | 61 | - name: Download Build Artifacts 📥 62 | uses: actions/download-artifact@v3 63 | if: fromJSON(steps.check.outputs.validTag) 64 | id: download 65 | 66 | - name: Rename Files 🏷️ 67 | if: fromJSON(steps.check.outputs.validTag) 68 | run: | 69 | : Rename Files 🏷️ 70 | if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi 71 | shopt -s extglob 72 | shopt -s nullglob 73 | 74 | root_dir="$(pwd)" 75 | commit_hash="${GITHUB_SHA:0:9}" 76 | 77 | variants=( 78 | 'windows-x64;zip|exe' 79 | 'macos-universal;tar.xz|pkg' 80 | 'ubuntu-22.04-x86_64;tar.xz|deb|ddeb' 81 | 'sources;tar.xz' 82 | ) 83 | 84 | for variant_data in "${variants[@]}"; do 85 | IFS=';' read -r variant suffix <<< "${variant_data}" 86 | 87 | candidates=(*-${variant}-${commit_hash}/@(*|*-dbgsym).@(${suffix})) 88 | 89 | for candidate in "${candidates[@]}"; do 90 | mv "${candidate}" "${root_dir}" 91 | done 92 | done 93 | 94 | - name: Generate Checksums 🪪 95 | if: fromJSON(steps.check.outputs.validTag) 96 | run: | 97 | : Generate Checksums 🪪 98 | if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi 99 | shopt -s extglob 100 | 101 | echo "### Checksums" > ${{ github.workspace }}/CHECKSUMS.txt 102 | for file in ${{ github.workspace }}/@(*.exe|*.deb|*.ddeb|*.pkg|*.tar.xz|*.zip); do 103 | echo " ${file##*/}: $(sha256sum "${file}" | cut -d " " -f 1)" >> ${{ github.workspace }}/CHECKSUMS.txt 104 | done 105 | 106 | - name: Create Release 🛫 107 | if: fromJSON(steps.check.outputs.validTag) 108 | id: create_release 109 | uses: softprops/action-gh-release@d4e8205d7e959a9107da6396278b2f1f07af0f9b 110 | with: 111 | draft: true 112 | prerelease: ${{ fromJSON(steps.check.outputs.prerelease) }} 113 | tag_name: ${{ steps.check.outputs.version }} 114 | name: OBS Studio ${{ steps.check.outputs.version }} 115 | body_path: ${{ github.workspace }}/CHECKSUMS.txt 116 | files: | 117 | ${{ github.workspace }}/*.exe 118 | ${{ github.workspace }}/*.zip 119 | ${{ github.workspace }}/*.pkg 120 | ${{ github.workspace }}/*.deb 121 | ${{ github.workspace }}/*.ddeb 122 | ${{ github.workspace }}/*.tar.xz 123 | -------------------------------------------------------------------------------- /cmake/macos/helpers.cmake: -------------------------------------------------------------------------------- 1 | # CMake macOS helper functions module 2 | 3 | # cmake-format: off 4 | # cmake-lint: disable=C0103 5 | # cmake-lint: disable=C0307 6 | # cmake-format: on 7 | 8 | include_guard(GLOBAL) 9 | 10 | include(helpers_common) 11 | 12 | # set_target_properties_obs: Set target properties for use in obs-studio 13 | function(set_target_properties_plugin target) 14 | set(options "") 15 | set(oneValueArgs "") 16 | set(multiValueArgs PROPERTIES) 17 | cmake_parse_arguments(PARSE_ARGV 0 _STPO "${options}" "${oneValueArgs}" "${multiValueArgs}") 18 | 19 | message(DEBUG "Setting additional properties for target ${target}...") 20 | 21 | while(_STPO_PROPERTIES) 22 | list(POP_FRONT _STPO_PROPERTIES key value) 23 | set_property(TARGET ${target} PROPERTY ${key} "${value}") 24 | endwhile() 25 | 26 | string(TIMESTAMP CURRENT_YEAR "%Y") 27 | set_target_properties( 28 | ${target} 29 | PROPERTIES BUNDLE TRUE 30 | BUNDLE_EXTENSION plugin 31 | XCODE_ATTRIBUTE_PRODUCT_NAME ${target} 32 | XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER ${MACOS_BUNDLEID} 33 | XCODE_ATTRIBUTE_CURRENT_PROJECT_VERSION ${PLUGIN_BUILD_NUMBER} 34 | XCODE_ATTRIBUTE_MARKETING_VERSION ${PLUGIN_VERSION} 35 | XCODE_ATTRIBUTE_GENERATE_INFOPLIST_FILE YES 36 | XCODE_ATTRIBUTE_INFOPLIST_FILE "" 37 | XCODE_ATTRIBUTE_INFOPLIST_KEY_CFBundleDisplayName ${target} 38 | XCODE_ATTRIBUTE_INFOPLIST_KEY_NSHumanReadableCopyright "(c) ${CURRENT_YEAR} ${PLUGIN_AUTHOR}" 39 | XCODE_ATTRIBUTE_INSTALL_PATH "$(USER_LIBRARY_DIR)/Application Support/obs-studio/plugins") 40 | 41 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos/entitlements.plist") 42 | set_target_properties(${target} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS 43 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos/entitlements.plist") 44 | endif() 45 | 46 | if(TARGET plugin-support) 47 | target_link_libraries(${target} PRIVATE plugin-support) 48 | endif() 49 | 50 | target_install_resources(${target}) 51 | 52 | get_target_property(target_sources ${target} SOURCES) 53 | set(target_ui_files ${target_sources}) 54 | list(FILTER target_ui_files INCLUDE REGEX ".+\\.(ui|qrc)") 55 | source_group( 56 | TREE "${CMAKE_CURRENT_SOURCE_DIR}" 57 | PREFIX "UI Files" 58 | FILES ${target_ui_files}) 59 | 60 | set(valid_uuid FALSE) 61 | check_uuid(${_macosPackageUUID} valid_uuid) 62 | if(NOT valid_uuid) 63 | message(FATAL_ERROR "Specified macOS package UUID is not a valid UUID value: ${_macosPackageUUID}") 64 | else() 65 | set(UUID_PACKAGE ${_macosPackageUUID}) 66 | endif() 67 | 68 | set(valid_uuid FALSE) 69 | check_uuid(${_macosInstallerUUID} valid_uuid) 70 | if(NOT valid_uuid) 71 | message(FATAL_ERROR "Specified macOS package UUID is not a valid UUID value: ${_macosInstallerUUID}") 72 | else() 73 | set(UUID_INSTALLER ${_macosInstallerUUID}) 74 | endif() 75 | 76 | install(TARGETS ${target} LIBRARY DESTINATION .) 77 | install( 78 | FILES "$.dsym" 79 | CONFIGURATIONS Release 80 | DESTINATION . 81 | OPTIONAL) 82 | configure_file(cmake/macos/resources/distribution.in "${CMAKE_CURRENT_BINARY_DIR}/distribution" @ONLY) 83 | configure_file(cmake/macos/resources/create-package.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/create-package.cmake" @ONLY) 84 | install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/create-package.cmake") 85 | endfunction() 86 | 87 | # target_install_resources: Helper function to add resources into bundle 88 | function(target_install_resources target) 89 | message(DEBUG "Installing resources for target ${target}...") 90 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/data") 91 | file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*") 92 | foreach(data_file IN LISTS data_files) 93 | cmake_path(RELATIVE_PATH data_file BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" OUTPUT_VARIABLE 94 | relative_path) 95 | cmake_path(GET relative_path PARENT_PATH relative_path) 96 | target_sources(${target} PRIVATE "${data_file}") 97 | set_property(SOURCE "${data_file}" PROPERTY MACOSX_PACKAGE_LOCATION "Resources/${relative_path}") 98 | source_group("Resources/${relative_path}" FILES "${data_file}") 99 | endforeach() 100 | endif() 101 | endfunction() 102 | 103 | # target_add_resource: Helper function to add a specific resource to a bundle 104 | function(target_add_resource target resource) 105 | message(DEBUG "Add resource ${resource} to target ${target} at destination ${destination}...") 106 | target_sources(${target} PRIVATE "${resource}") 107 | set_property(SOURCE "${resource}" PROPERTY MACOSX_PACKAGE_LOCATION Resources) 108 | source_group("Resources" FILES "${resource}") 109 | endfunction() 110 | -------------------------------------------------------------------------------- /cmake/windows/helpers.cmake: -------------------------------------------------------------------------------- 1 | # CMake Windows helper functions module 2 | 3 | # cmake-format: off 4 | # cmake-lint: disable=C0103 5 | # cmake-format: on 6 | 7 | include_guard(GLOBAL) 8 | 9 | include(helpers_common) 10 | 11 | # set_target_properties_plugin: Set target properties for use in obs-studio 12 | function(set_target_properties_plugin target) 13 | set(options "") 14 | set(oneValueArgs "") 15 | set(multiValueArgs PROPERTIES) 16 | cmake_parse_arguments(PARSE_ARGV 0 _STPO "${options}" "${oneValueArgs}" "${multiValueArgs}") 17 | 18 | message(DEBUG "Setting additional properties for target ${target}...") 19 | 20 | while(_STPO_PROPERTIES) 21 | list(POP_FRONT _STPO_PROPERTIES key value) 22 | set_property(TARGET ${target} PROPERTY ${key} "${value}") 23 | endwhile() 24 | 25 | string(TIMESTAMP CURRENT_YEAR "%Y") 26 | 27 | set_target_properties(${target} PROPERTIES VERSION 0 SOVERSION ${PLUGIN_VERSION}) 28 | 29 | install( 30 | TARGETS ${target} 31 | RUNTIME DESTINATION bin/64bit 32 | LIBRARY DESTINATION obs-plugins/64bit) 33 | 34 | install( 35 | FILES "$" 36 | CONFIGURATIONS RelWithDebInfo Debug 37 | DESTINATION obs-plugins/64bit 38 | OPTIONAL) 39 | 40 | if(OBS_BUILD_DIR) 41 | add_custom_command( 42 | TARGET ${target} 43 | POST_BUILD 44 | COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/obs-plugins/64bit" 45 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$" 46 | "$<$:$>" "${OBS_BUILD_DIR}/obs-plugin/64bit" 47 | COMMENT "Copy ${target} to obs-studio directory ${OBS_BUILD_DIR}" 48 | VERBATIM) 49 | endif() 50 | 51 | if(TARGET plugin-support) 52 | target_link_libraries(${target} PRIVATE plugin-support) 53 | endif() 54 | 55 | target_install_resources(${target}) 56 | 57 | get_target_property(target_sources ${target} SOURCES) 58 | set(target_ui_files ${target_sources}) 59 | list(FILTER target_ui_files INCLUDE REGEX ".+\\.(ui|qrc)") 60 | source_group( 61 | TREE "${CMAKE_CURRENT_SOURCE_DIR}" 62 | PREFIX "UI Files" 63 | FILES ${target_ui_files}) 64 | 65 | set(valid_uuid FALSE) 66 | check_uuid(${_windowsAppUUID} valid_uuid) 67 | if(NOT valid_uuid) 68 | message(FATAL_ERROR "Specified Windows package UUID is not a valid UUID value: ${_windowsAppUUID}") 69 | else() 70 | set(UUID_APP ${_windowsAppUUID}) 71 | endif() 72 | 73 | configure_file(cmake/windows/resources/installer-Windows.iss.in 74 | "${CMAKE_CURRENT_BINARY_DIR}/installer-Windows.generated.iss") 75 | 76 | configure_file(cmake/windows/resources/resource.rc.in "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.rc") 77 | target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.rc") 78 | endfunction() 79 | 80 | # Helper function to add resources into bundle 81 | function(target_install_resources target) 82 | message(DEBUG "Installing resources for target ${target}...") 83 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/data") 84 | file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*") 85 | foreach(data_file IN LISTS data_files) 86 | cmake_path(RELATIVE_PATH data_file BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" OUTPUT_VARIABLE 87 | relative_path) 88 | cmake_path(GET relative_path PARENT_PATH relative_path) 89 | target_sources(${target} PRIVATE "${data_file}") 90 | source_group("Resources/${relative_path}" FILES "${data_file}") 91 | endforeach() 92 | 93 | install( 94 | DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" 95 | DESTINATION data/obs-plugins/${target} 96 | USE_SOURCE_PERMISSIONS) 97 | 98 | if(OBS_BUILD_DIR) 99 | add_custom_command( 100 | TARGET ${target} 101 | POST_BUILD 102 | COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/data/obs-plugins/${target}" 103 | COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/data" 104 | "${OBS_BUILD_DIR}/data/obs-plugins/${target}" 105 | COMMENT "Copy ${target} resources to data directory" 106 | VERBATIM) 107 | endif() 108 | endif() 109 | endfunction() 110 | 111 | # Helper function to add a specific resource to a bundle 112 | function(target_add_resource target resource) 113 | message(DEBUG "Add resource '${resource}' to target ${target} at destination '${target_destination}'...") 114 | 115 | install( 116 | FILES "${resource}" 117 | DESTINATION data/obs-plugins/${target} 118 | COMPONENT Runtime) 119 | 120 | if(OBS_BUILD_DIR) 121 | add_custom_command( 122 | TARGET ${target} 123 | POST_BUILD 124 | COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/data/obs-plugins/${target}" 125 | COMMAND "${CMAKE_COMMAND}" -E copy "${resource}" "${OBS_BUILD_DIR}/data/obs-plugins/${target}" 126 | COMMENT "Copy ${target} resource ${resource} to library directory" 127 | VERBATIM) 128 | endif() 129 | source_group("Resources" FILES "${resource}") 130 | endfunction() 131 | -------------------------------------------------------------------------------- /src/llm-dock/llm-config-data.cpp: -------------------------------------------------------------------------------- 1 | #include "llm-config-data.h" 2 | #include "plugin-support.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | llm_config_data global_llm_config; 9 | llm_global_context global_llm_context; 10 | 11 | void config_defaults() 12 | { 13 | const std::string LLAMA_DEFAULT_SYSTEM_PROMPT = R"([INST] <> 14 | You are a helpful, respectful, positive, safe and honest assistant. 15 | Don't include harmful, unethical, racist, sexist, toxic, dangerous, socially biased, untruthful or illegal content. 16 | <> Q: {0} [/INST] A:)"; 17 | 18 | global_llm_config.local = true; 19 | global_llm_config.local_model_path = ""; 20 | global_llm_config.cloud_model_name = ""; 21 | global_llm_config.cloud_api_key = ""; 22 | global_llm_config.temperature = 0.9f; 23 | global_llm_config.max_output_tokens = 64; 24 | global_llm_config.system_prompt = LLAMA_DEFAULT_SYSTEM_PROMPT; 25 | global_llm_config.end_sequence = ""; 26 | global_llm_config.workflows = {}; 27 | } 28 | 29 | void create_config_folder() 30 | { 31 | char *config_folder_path = obs_module_config_path(""); 32 | if (config_folder_path == nullptr) { 33 | obs_log(LOG_ERROR, "Failed to get config folder path"); 34 | return; 35 | } 36 | std::filesystem::path config_folder_std_path(config_folder_path); 37 | bfree(config_folder_path); 38 | 39 | // create the folder if it doesn't exist 40 | if (!std::filesystem::exists(config_folder_std_path)) { 41 | #ifdef _WIN32 42 | obs_log(LOG_INFO, "Config folder does not exist, creating: %S", 43 | config_folder_std_path.c_str()); 44 | #else 45 | obs_log(LOG_INFO, "Config folder does not exist, creating: %s", 46 | config_folder_std_path.c_str()); 47 | #endif 48 | // Create the config folder 49 | std::filesystem::create_directories(config_folder_std_path); 50 | } 51 | } 52 | 53 | int getConfig(config_t **config, bool create_if_not_exist = false) 54 | { 55 | create_config_folder(); // ensure the config folder exists 56 | 57 | // Get the config file 58 | char *config_file_path = obs_module_config_path("config.ini"); 59 | 60 | int ret = config_open(config, config_file_path, 61 | create_if_not_exist ? CONFIG_OPEN_ALWAYS : CONFIG_OPEN_EXISTING); 62 | if (ret != CONFIG_SUCCESS) { 63 | obs_log(LOG_INFO, "Failed to open config file %s", config_file_path); 64 | return OBS_BRAIN_CONFIG_FAIL; 65 | } 66 | 67 | return OBS_BRAIN_CONFIG_SUCCESS; 68 | } 69 | 70 | std::string llm_config_data_to_json(const llm_config_data &data); 71 | llm_config_data llm_config_data_from_json(const std::string &json); 72 | 73 | int saveConfig(bool create_if_not_exist) 74 | { 75 | config_t *config_file; 76 | if (getConfig(&config_file, create_if_not_exist) == OBS_BRAIN_CONFIG_SUCCESS) { 77 | std::string json = llm_config_data_to_json(global_llm_config); 78 | config_set_string(config_file, "general", "llm_config", json.c_str()); 79 | config_save(config_file); 80 | config_close(config_file); 81 | return OBS_BRAIN_CONFIG_SUCCESS; 82 | } 83 | return OBS_BRAIN_CONFIG_FAIL; 84 | } 85 | 86 | int loadConfig() 87 | { 88 | config_t *config_file; 89 | if (getConfig(&config_file) == OBS_BRAIN_CONFIG_SUCCESS) { 90 | const char *json = config_get_string(config_file, "general", "llm_config"); 91 | if (json != nullptr) { 92 | global_llm_config = llm_config_data_from_json(json); 93 | config_close(config_file); 94 | return OBS_BRAIN_CONFIG_SUCCESS; 95 | } 96 | config_close(config_file); 97 | } else { 98 | obs_log(LOG_WARNING, "Failed to load config file. Creating a new one."); 99 | config_defaults(); 100 | if (saveConfig(true) == OBS_BRAIN_CONFIG_SUCCESS) { 101 | obs_log(LOG_INFO, "Saved default LLM settings"); 102 | return OBS_BRAIN_CONFIG_SUCCESS; 103 | } else { 104 | obs_log(LOG_ERROR, "Failed to save LLM settings"); 105 | } 106 | } 107 | return OBS_BRAIN_CONFIG_FAIL; 108 | } 109 | 110 | // serialize llm_config_data to a json string 111 | std::string llm_config_data_to_json(const llm_config_data &data) 112 | { 113 | nlohmann::json j; 114 | j["local"] = data.local; 115 | j["local_model_path"] = data.local_model_path; 116 | j["cloud_model_name"] = data.cloud_model_name; 117 | j["cloud_api_key"] = data.cloud_api_key; 118 | j["temperature"] = data.temperature; 119 | j["max_output_tokens"] = data.max_output_tokens; 120 | j["system_prompt"] = data.system_prompt; 121 | j["end_sequence"] = data.end_sequence; 122 | j["workflows"] = data.workflows; 123 | return j.dump(); 124 | } 125 | 126 | // deserialize llm_config_data from a json string 127 | llm_config_data llm_config_data_from_json(const std::string &json) 128 | { 129 | nlohmann::json j = nlohmann::json::parse(json); 130 | llm_config_data data; 131 | data.local = j["local"]; 132 | data.local_model_path = j["local_model_path"]; 133 | data.cloud_model_name = j["cloud_model_name"]; 134 | data.cloud_api_key = j["cloud_api_key"]; 135 | data.temperature = j["temperature"]; 136 | data.max_output_tokens = j["max_output_tokens"]; 137 | data.system_prompt = j["system_prompt"]; 138 | data.end_sequence = j.value("end_sequence", ""); 139 | data.workflows = j["workflows"]; 140 | return data; 141 | } 142 | -------------------------------------------------------------------------------- /cmake/common/helpers_common.cmake: -------------------------------------------------------------------------------- 1 | # CMake common helper functions module 2 | 3 | # cmake-format: off 4 | # cmake-lint: disable=C0103 5 | # cmake-format: on 6 | 7 | include_guard(GLOBAL) 8 | 9 | # * Use QT_VERSION value as a hint for desired Qt version 10 | # * If "AUTO" was specified, prefer Qt6 over Qt5 11 | # * Creates versionless targets of desired component if none had been created by Qt itself (Qt versions < 5.15) 12 | if(NOT QT_VERSION) 13 | set(QT_VERSION 14 | AUTO 15 | CACHE STRING "OBS Qt version [AUTO, 5, 6]" FORCE) 16 | set_property(CACHE QT_VERSION PROPERTY STRINGS AUTO 5 6) 17 | endif() 18 | 19 | # find_qt: Macro to find best possible Qt version for use with the project: 20 | macro(find_qt) 21 | set(multiValueArgs COMPONENTS COMPONENTS_WIN COMPONENTS_MAC COMPONENTS_LINUX) 22 | cmake_parse_arguments(find_qt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 23 | 24 | # Do not use versionless targets in the first step to avoid Qt::Core being clobbered by later opportunistic 25 | # find_package runs 26 | set(QT_NO_CREATE_VERSIONLESS_TARGETS TRUE) 27 | 28 | message(DEBUG "Start Qt version discovery...") 29 | # Loop until _QT_VERSION is set or FATAL_ERROR aborts script execution early 30 | while(NOT _QT_VERSION) 31 | message(DEBUG "QT_VERSION set to ${QT_VERSION}") 32 | if(QT_VERSION STREQUAL AUTO AND NOT qt_test_version) 33 | set(qt_test_version 6) 34 | elseif(NOT QT_VERSION STREQUAL AUTO) 35 | set(qt_test_version ${QT_VERSION}) 36 | endif() 37 | message(DEBUG "Attempting to find Qt${qt_test_version}") 38 | 39 | find_package( 40 | Qt${qt_test_version} 41 | COMPONENTS Core 42 | QUIET) 43 | 44 | if(TARGET Qt${qt_test_version}::Core) 45 | set(_QT_VERSION 46 | ${qt_test_version} 47 | CACHE INTERNAL "") 48 | message(STATUS "Qt version found: ${_QT_VERSION}") 49 | unset(qt_test_version) 50 | break() 51 | elseif(QT_VERSION STREQUAL AUTO) 52 | if(qt_test_version EQUAL 6) 53 | message(WARNING "Qt6 was not found, falling back to Qt5") 54 | set(qt_test_version 5) 55 | continue() 56 | endif() 57 | endif() 58 | message(FATAL_ERROR "Neither Qt6 nor Qt5 found.") 59 | endwhile() 60 | 61 | # Enable versionless targets for the remaining Qt components 62 | set(QT_NO_CREATE_VERSIONLESS_TARGETS FALSE) 63 | 64 | set(qt_components ${find_qt_COMPONENTS}) 65 | if(OS_WINDOWS) 66 | list(APPEND qt_components ${find_qt_COMPONENTS_WIN}) 67 | elseif(OS_MACOS) 68 | list(APPEND qt_components ${find_qt_COMPONENTS_MAC}) 69 | else() 70 | list(APPEND qt_components ${find_qt_COMPONENTS_LINUX}) 71 | endif() 72 | message(DEBUG "Trying to find Qt components ${qt_components}...") 73 | 74 | find_package(Qt${_QT_VERSION} REQUIRED ${qt_components}) 75 | 76 | list(APPEND qt_components Core) 77 | 78 | if("Gui" IN_LIST find_qt_COMPONENTS_LINUX) 79 | list(APPEND qt_components "GuiPrivate") 80 | endif() 81 | 82 | # Check for versionless targets of each requested component and create if necessary 83 | foreach(component IN LISTS qt_components) 84 | message(DEBUG "Checking for target Qt::${component}") 85 | if(NOT TARGET Qt::${component} AND TARGET Qt${_QT_VERSION}::${component}) 86 | add_library(Qt::${component} INTERFACE IMPORTED) 87 | set_target_properties(Qt::${component} PROPERTIES INTERFACE_LINK_LIBRARIES Qt${_QT_VERSION}::${component}) 88 | endif() 89 | set_property(TARGET Qt::${component} PROPERTY INTERFACE_COMPILE_FEATURES "") 90 | endforeach() 91 | 92 | endmacro() 93 | 94 | # check_uuid: Helper function to check for valid UUID 95 | function(check_uuid uuid_string return_value) 96 | set(valid_uuid TRUE) 97 | set(uuid_token_lengths 8 4 4 4 12) 98 | set(token_num 0) 99 | 100 | string(REPLACE "-" ";" uuid_tokens ${uuid_string}) 101 | list(LENGTH uuid_tokens uuid_num_tokens) 102 | 103 | if(uuid_num_tokens EQUAL 5) 104 | message(DEBUG "UUID ${uuid_string} is valid with 5 tokens.") 105 | foreach(uuid_token IN LISTS uuid_tokens) 106 | list(GET uuid_token_lengths ${token_num} uuid_target_length) 107 | string(LENGTH "${uuid_token}" uuid_actual_length) 108 | if(uuid_actual_length EQUAL uuid_target_length) 109 | string(REGEX MATCH "[0-9a-fA-F]+" uuid_hex_match ${uuid_token}) 110 | if(NOT uuid_hex_match STREQUAL uuid_token) 111 | set(valid_uuid FALSE) 112 | break() 113 | endif() 114 | else() 115 | set(valid_uuid FALSE) 116 | break() 117 | endif() 118 | math(EXPR token_num "${token_num}+1") 119 | endforeach() 120 | else() 121 | set(valid_uuid FALSE) 122 | endif() 123 | message(DEBUG "UUID ${uuid_string} valid: ${valid_uuid}") 124 | set(${return_value} 125 | ${valid_uuid} 126 | PARENT_SCOPE) 127 | endfunction() 128 | 129 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-support.c.in") 130 | configure_file(src/plugin-support.c.in plugin-support.c @ONLY) 131 | add_library(plugin-support STATIC) 132 | target_sources( 133 | plugin-support 134 | PRIVATE plugin-support.c 135 | PUBLIC src/plugin-support.h) 136 | target_include_directories(plugin-support PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 137 | endif() 138 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # brAIn - AI Brain for your OBS 2 | 3 |
4 | 5 | [![GitHub](https://img.shields.io/github/license/occ-ai/obs-brain)](https://github.com/occ-ai/obs-brain/blob/main/LICENSE) 6 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/occ-ai/obs-brain/push.yaml)](https://github.com/occ-ai/obs-brain/actions/workflows/push.yaml) 7 | [![Total downloads](https://img.shields.io/github/downloads/occ-ai/obs-brain/total)](https://github.com/occ-ai/obs-brain/releases) 8 | [![GitHub release (latest by date)](https://img.shields.io/github/v/release/occ-ai/obs-brain)](https://github.com/occ-ai/obs-brain/releases) 9 | [![Discord](https://img.shields.io/discord/1200229425141252116)](https://discord.gg/KbjGU2vvUz) 10 | 11 |
12 | 13 | ## Introduction 14 | 15 | brAIn AI assistant plugin allows you to run AI / LLMs (Large Language Models), locally on your machine, to perform various language processing functions on text. ✅ No GPU required, ✅ no AI vendor costs! Privacy first - all data stays on your machine. 16 | 17 | If this free plugin has been valuable to you consider adding a ⭐ to this GH repo, subscribing to [my YouTube channel](https://www.youtube.com/@royshilk) where I post updates, and supporting my work: https://github.com/sponsors/royshil 18 | 19 | Current Features: 20 | - LLM inference on GGMF (.gguf v2) model 21 | - Connect to OpenAI API to run inference on GPT-3 models (need to provide your own API key) 22 | 23 | Roadmap: 24 | - Run many other LLMs and even e.g. LLaVA (vision-language) models 25 | 26 | Internally the plugin is running ([llama.cpp](https://github.com/ggerganov/llama.cpp)) locally to inference in real-time on the CPU or GPU. 27 | 28 | Check out our other plugins: 29 | - [Background Removal](https://github.com/occ-ai/obs-backgroundremoval) removes background from webcam without a green screen. 30 | - 🚧 Experimental 🚧 [CleanStream](https://github.com/occ-ai/obs-cleanstream) for real-time filler word (uh,um) and profanity removal from live audio stream 31 | - [URL/API Source](https://github.com/occ-ai/obs-urlsource) that allows fetching live data from an API and displaying it in OBS. 32 | - [LocalVocal](https://github.com/occ-ai/obs-localvocal) for real-time speech to text transcription in OBS. 33 | 34 | ## Download 35 | Check out the [latest releases](https://github.com/occ-ai/obs-brain/releases) for downloads and install instructions. 36 | 37 | ## Building 38 | 39 | The plugin was built and tested on Mac OSX (Intel & Apple silicon), Windows and Linux. 40 | 41 | Start by cloning this repo to a directory of your choice. 42 | 43 | Remember to sync and fetch the submodules before building, e.g. 44 | ```sh 45 | $ git submodule sync --recursive 46 | $ git update --init --recursive 47 | ``` 48 | 49 | ### Mac OSX 50 | 51 | Using the CI pipeline scripts, locally you would just call the zsh script. By default this builds a universal binary for both Intel and Apple Silicon. To build for a specific architecture please see `.github/scripts/.build.zsh` for the `-arch` options. 52 | 53 | ```sh 54 | $ ./.github/scripts/build-macos -c Release 55 | ``` 56 | 57 | #### Install 58 | The above script should succeed and the plugin files (e.g. `obs-urlsource.plugin`) will reside in the `./release/Release` folder off of the root. Copy the `.plugin` file to the OBS directory e.g. `~/Library/Application Support/obs-studio/plugins`. 59 | 60 | To get `.pkg` installer file, run for example 61 | ```sh 62 | $ ./.github/scripts/package-macos -c Release 63 | ``` 64 | (Note that maybe the outputs will be in the `Release` folder and not the `install` folder like `pakage-macos` expects, so you will need to rename the folder from `build_x86_64/Release` to `build_x86_64/install`) 65 | 66 | ### Linux (Ubuntu) 67 | 68 | Use the CI scripts again 69 | ```sh 70 | $ ./.github/scripts/build-linux.sh 71 | ``` 72 | 73 | Copy the results to the standard OBS folders on Ubuntu 74 | ```sh 75 | $ sudo cp -R release/RelWithDebInfo/lib/* /usr/lib/x86_64-linux-gnu/ 76 | $ sudo cp -R release/RelWithDebInfo/share/* /usr/share/ 77 | ``` 78 | Note: The official [OBS plugins guide](https://obsproject.com/kb/plugins-guide) recommends adding plugins to the `~/.config/obs-studio/plugins` folder. 79 | 80 | ### Windows 81 | 82 | Use the CI scripts again, for example: 83 | 84 | ```powershell 85 | > .github/scripts/Build-Windows.ps1 -Target x64 -CMakeGenerator "Visual Studio 17 2022" 86 | ``` 87 | 88 | The build should exist in the `./release` folder off the root. You can manually install the files in the OBS directory. 89 | 90 | #### Building with CUDA support on Windows 91 | 92 | To build with CUDA support on Windows, you need to install the CUDA toolkit from NVIDIA. The CUDA toolkit is available for download from [here](https://developer.nvidia.com/cuda-downloads). 93 | 94 | After installing the CUDA toolkit, you need to set variables to point CMake to the CUDA toolkit installation directory. For example, if you have installed the CUDA toolkit in `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4`, you need to set `CUDA_TOOLKIT_ROOT_DIR` to `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4` and `brAIn_WITH_CUDA` to `ON` when running `.github/scripts/Build-Windows.ps1`. 95 | 96 | For example 97 | ```powershell 98 | .github/scripts/Build-Windows.ps1 -Target x64 -ExtraCmakeArgs '-D','brAIn_WITH_CUDA=ON','-D',"CUDA_TOOLKIT_ROOT_DIR='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2'" 99 | ``` 100 | 101 | You will need to copy a few CUDA .dll files to the location of the plugin .dll for it to run. The required .dll files from CUDA (which are located in the `bin` folder of the CUDA toolkit installation directory) are: 102 | 103 | - `cudart64_NN.dll` 104 | - `cublas64_NN.dll` 105 | - `cublasLt64_NN.dll` 106 | 107 | where `NN` is the CUDA major version number. For example, if you have installed CUDA 12.2 as in example above, then `NN` is `12`. 108 | -------------------------------------------------------------------------------- /src/llm-dock/llm-dock-ui.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "plugin-support.h" 8 | #include "llm-dock-ui.hpp" 9 | #include "llm-dock.h" 10 | #include "llama-inference.h" 11 | #include "LLMSettingsDialog.hpp" 12 | #include "llm-config-data.h" 13 | #include "ui/ui_dockwidget.h" 14 | #include "Workflows.hpp" 15 | 16 | QDockWidget *createLLMDockWidget(QMainWindow *parent); 17 | 18 | void register_llm_dock(void) 19 | { 20 | // load plugin settings from config 21 | if (loadConfig() == OBS_BRAIN_CONFIG_SUCCESS) { 22 | obs_log(LOG_INFO, "Loaded LLM config from config file"); 23 | } else { 24 | obs_log(LOG_INFO, "Failed to load LLM config from config file"); 25 | } 26 | 27 | if (global_llm_config.local) { 28 | obs_log(LOG_INFO, "Using local LLM model: %s", 29 | global_llm_config.local_model_path.c_str()); 30 | // initialize the local LLM model 31 | if (global_llm_config.local_model_path.empty()) { 32 | obs_log(LOG_ERROR, "LLM Model not found."); 33 | } else { 34 | global_llm_context.ctx_llama = 35 | llama_init_context(global_llm_config.local_model_path); 36 | 37 | // If the model is loaded successfully, register the GPT dock 38 | if (global_llm_context.ctx_llama == nullptr) { 39 | obs_log(LOG_ERROR, "Failed to load LLM model from %s.", 40 | global_llm_config.local_model_path.c_str()); 41 | global_llm_context.error_message = 42 | "Failed to load local LLM model."; 43 | return; 44 | } 45 | } 46 | } else { 47 | obs_log(LOG_INFO, "Using cloud LLM model: %s", 48 | global_llm_config.cloud_model_name.c_str()); 49 | } 50 | 51 | // register the GPT dock 52 | obs_frontend_add_dock(createLLMDockWidget((QMainWindow *)obs_frontend_get_main_window())); 53 | } 54 | 55 | QDockWidget *createLLMDockWidget(QMainWindow *parent) 56 | { 57 | QDockWidget *dock = new LLMDockWidgetUI(parent); 58 | dock->setObjectName("LLMDockWidget"); 59 | dock->setWindowTitle("LLM Dock"); 60 | dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); 61 | parent->addDockWidget(Qt::BottomDockWidgetArea, dock); 62 | return dock; 63 | } 64 | 65 | LLMDockWidgetUI::LLMDockWidgetUI(QWidget *parent) : QDockWidget(parent), ui(new Ui::BrainDock) 66 | { 67 | ui->setupUi(this); 68 | 69 | // connect the settings button to open the settings dialog 70 | this->connect(this->ui->settings, &QPushButton::clicked, this, [=]() { 71 | // open the settings dialog 72 | LLMSettingsDialog *settings_dialog = new LLMSettingsDialog(this); 73 | settings_dialog->show(); 74 | }); 75 | 76 | this->connect(this->ui->generate, &QPushButton::clicked, this, &LLMDockWidgetUI::generate); 77 | this->connect(this->ui->clear, &QPushButton::clicked, this, &LLMDockWidgetUI::clear); 78 | this->connect(this->ui->stop, &QPushButton::clicked, this, &LLMDockWidgetUI::stop); 79 | this->connect(this, &LLMDockWidgetUI::update_text_signal, this, 80 | &LLMDockWidgetUI::update_text); 81 | // connect workflows 82 | this->connect(this->ui->workflows, &QPushButton::clicked, this, [=]() { 83 | Workflows *workflows_dialog = new Workflows(this); 84 | workflows_dialog->show(); 85 | }); 86 | } 87 | 88 | LLMDockWidgetUI::~LLMDockWidgetUI() {} 89 | 90 | void LLMDockWidgetUI::generate() 91 | { 92 | QString input_text = this->ui->prompt->toPlainText(); 93 | if (input_text.isEmpty()) { 94 | return; 95 | } 96 | this->stop_flag = false; 97 | 98 | this->ui->generated->insertHtml( 99 | QString("

%1


").arg(input_text)); 100 | this->ui->generated->moveCursor(QTextCursor::End); 101 | this->ui->prompt->clear(); 102 | // also clear any styles 103 | this->ui->prompt->setStyleSheet("QTextEdit { background-color: #000000; color: #ffffff; }"); 104 | 105 | // call LLM inference on a separate thread using a lambda function 106 | std::thread t([input_text, this]() { 107 | std::string generated_text = llama_inference( 108 | input_text.toStdString(), global_llm_context.ctx_llama, 109 | [this](const std::string &partial_generation) { 110 | emit update_text_signal(QString::fromStdString(partial_generation), 111 | true); 112 | }, 113 | [this](const std::string &generation) { 114 | // check if the stop button was pressed or the generation ends with the end sequence 115 | if (this->stop_flag) { 116 | return true; 117 | } 118 | if (!global_llm_config.end_sequence.empty()) { 119 | std::regex end_sequence_regex(global_llm_config.end_sequence); 120 | if (std::regex_search(generation, end_sequence_regex)) { 121 | return true; 122 | } 123 | } 124 | return false; 125 | }); 126 | emit update_text_signal(QString("
"), true); 127 | }); 128 | t.detach(); 129 | } 130 | 131 | void LLMDockWidgetUI::clear() 132 | { 133 | this->ui->prompt->clear(); 134 | this->ui->generated->clear(); 135 | } 136 | 137 | void LLMDockWidgetUI::stop() 138 | { 139 | this->stop_flag = true; 140 | } 141 | 142 | void LLMDockWidgetUI::update_text(const QString &text, bool partial_generation) 143 | { 144 | if (partial_generation) { 145 | if (text.isEmpty()) { 146 | return; 147 | } 148 | // if text is just a new line, append a
tag 149 | if (text == "\n") { 150 | this->ui->generated->insertHtml("
"); 151 | return; 152 | } 153 | // replace spaces with non-breaking spaces 154 | QString text_with_non_breaking_spaces = text; 155 | text_with_non_breaking_spaces.replace(" ", " "); 156 | 157 | // append text in a different color 158 | this->ui->generated->insertHtml(QString("%1") 159 | .arg(text_with_non_breaking_spaces)); 160 | } else { 161 | this->ui->generated->insertHtml( 162 | QString("

%1

").arg(text)); 163 | } 164 | // always scroll to the bottom 165 | this->ui->generated->moveCursor(QTextCursor::End); 166 | } 167 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "cmakeMinimumRequired": { 4 | "major": 3, 5 | "minor": 22, 6 | "patch": 0 7 | }, 8 | "configurePresets": [ 9 | { 10 | "name": "macos", 11 | "displayName": "macOS Universal", 12 | "description": "Build for macOS 11.0+ (Universal binary)", 13 | "binaryDir": "${sourceDir}/build_macos", 14 | "condition": { 15 | "type": "equals", 16 | "lhs": "${hostSystemName}", 17 | "rhs": "Darwin" 18 | }, 19 | "generator": "Xcode", 20 | "warnings": {"dev": true, "deprecated": true}, 21 | "cacheVariables": { 22 | "QT_VERSION": "6", 23 | "CMAKE_OSX_DEPLOYMENT_TARGET": "11.0", 24 | "CODESIGN_IDENTITY": "$penv{CODESIGN_IDENT}", 25 | "CODESIGN_TEAM": "$penv{CODESIGN_TEAM}", 26 | "ENABLE_FRONTEND_API": true, 27 | "ENABLE_QT": true 28 | } 29 | }, 30 | { 31 | "name": "macos-ci", 32 | "inherits": ["macos"], 33 | "displayName": "macOS Universal CI build", 34 | "description": "Build for macOS 11.0+ (Universal binary) for CI", 35 | "generator": "Xcode", 36 | "cacheVariables": { 37 | "CMAKE_COMPILE_WARNING_AS_ERROR": true 38 | } 39 | }, 40 | { 41 | "name": "windows-x64", 42 | "displayName": "Windows x64", 43 | "description": "Build for Windows x64", 44 | "binaryDir": "${sourceDir}/build_x64", 45 | "condition": { 46 | "type": "equals", 47 | "lhs": "${hostSystemName}", 48 | "rhs": "Windows" 49 | }, 50 | "generator": "Visual Studio 17 2022", 51 | "architecture": "x64", 52 | "warnings": {"dev": true, "deprecated": true}, 53 | "cacheVariables": { 54 | "QT_VERSION": "6", 55 | "CMAKE_SYSTEM_VERSION": "10.0.18363.657", 56 | "ENABLE_FRONTEND_API": true, 57 | "ENABLE_QT": true 58 | } 59 | }, 60 | { 61 | "name": "windows-ci-x64", 62 | "inherits": ["windows-x64"], 63 | "displayName": "Windows x64 CI build", 64 | "description": "Build for Windows x64 on CI", 65 | "cacheVariables": { 66 | "CMAKE_COMPILE_WARNING_AS_ERROR": true 67 | } 68 | }, 69 | { 70 | "name": "linux-x86_64", 71 | "displayName": "Linux x86_64", 72 | "description": "Build for Linux x86_64", 73 | "binaryDir": "${sourceDir}/build_x86_64", 74 | "condition": { 75 | "type": "equals", 76 | "lhs": "${hostSystemName}", 77 | "rhs": "Linux" 78 | }, 79 | "generator": "Ninja", 80 | "warnings": {"dev": true, "deprecated": true}, 81 | "cacheVariables": { 82 | "QT_VERSION": "6", 83 | "CMAKE_BUILD_TYPE": "RelWithDebInfo", 84 | "ENABLE_FRONTEND_API": true, 85 | "ENABLE_QT": true 86 | } 87 | }, 88 | { 89 | "name": "linux-ci-x86_64", 90 | "inherits": ["linux-x86_64"], 91 | "displayName": "Linux x86_64 CI build", 92 | "description": "Build for Linux x86_64 on CI", 93 | "cacheVariables": { 94 | "CMAKE_BUILD_TYPE": "RelWithDebInfo", 95 | "CMAKE_COMPILE_WARNING_AS_ERROR": true 96 | } 97 | }, 98 | { 99 | "name": "linux-aarch64", 100 | "displayName": "Linux aarch64", 101 | "description": "Build for Linux aarch64", 102 | "binaryDir": "${sourceDir}/build_aarch64", 103 | "condition": { 104 | "type": "equals", 105 | "lhs": "${hostSystemName}", 106 | "rhs": "Linux" 107 | }, 108 | "generator": "Ninja", 109 | "warnings": {"dev": true, "deprecated": true}, 110 | "cacheVariables": { 111 | "QT_VERSION": "6", 112 | "CMAKE_BUILD_TYPE": "RelWithDebInfo", 113 | "ENABLE_FRONTEND_API": true, 114 | "ENABLE_QT": true 115 | } 116 | }, 117 | { 118 | "name": "linux-ci-aarch64", 119 | "inherits": ["linux-aarch64"], 120 | "displayName": "Linux aarch64 CI build", 121 | "description": "Build for Linux aarch64 on CI", 122 | "cacheVariables": { 123 | "CMAKE_BUILD_TYPE": "RelWithDebInfo", 124 | "CMAKE_COMPILE_WARNING_AS_ERROR": true 125 | } 126 | } 127 | ], 128 | "buildPresets": [ 129 | { 130 | "name": "macos", 131 | "configurePreset": "macos", 132 | "displayName": "macOS Universal", 133 | "description": "macOS build for Universal architectures", 134 | "configuration": "Release" 135 | }, 136 | { 137 | "name": "macos-ci", 138 | "configurePreset": "macos-ci", 139 | "displayName": "macOS Universal CI", 140 | "description": "macOS CI build for Universal architectures", 141 | "configuration": "RelWithDebInfo" 142 | }, 143 | { 144 | "name": "windows-x64", 145 | "configurePreset": "windows-x64", 146 | "displayName": "Windows x64", 147 | "description": "Windows build for x64", 148 | "configuration": "RelWithDebInfo" 149 | }, 150 | { 151 | "name": "windows-ci-x64", 152 | "configurePreset": "windows-ci-x64", 153 | "displayName": "Windows x64 CI", 154 | "description": "Windows CI build for x64 (RelWithDebInfo configuration)", 155 | "configuration": "RelWithDebInfo" 156 | }, 157 | { 158 | "name": "linux-x86_64", 159 | "configurePreset": "linux-x86_64", 160 | "displayName": "Linux x86_64", 161 | "description": "Linux build for x86_64", 162 | "configuration": "RelWithDebInfo" 163 | }, 164 | { 165 | "name": "linux-ci-x86_64", 166 | "configurePreset": "linux-ci-x86_64", 167 | "displayName": "Linux x86_64 CI", 168 | "description": "Linux CI build for x86_64", 169 | "configuration": "RelWithDebInfo" 170 | }, 171 | { 172 | "name": "linux-aarch64", 173 | "configurePreset": "linux-aarch64", 174 | "displayName": "Linux aarch64", 175 | "description": "Linux build for aarch64", 176 | "configuration": "RelWithDebInfo" 177 | }, 178 | { 179 | "name": "linux-ci-aarch64", 180 | "configurePreset": "linux-ci-aarch64", 181 | "displayName": "Linux aarch64 CI", 182 | "description": "Linux CI build for aarch64", 183 | "configuration": "RelWithDebInfo" 184 | } 185 | ] 186 | } 187 | -------------------------------------------------------------------------------- /src/llm-dock/ui/dockwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | BrainDock 4 | 5 | 6 | 7 | 0 8 | 0 9 | 376 10 | 385 11 | 12 | 13 | 14 | brAIn Dock 15 | 16 | 17 | 18 | 19 | 2 20 | 21 | 22 | 3 23 | 24 | 25 | 3 26 | 27 | 28 | 3 29 | 30 | 31 | 3 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 0 41 | 0 42 | 43 | 44 | 45 | 46 | 0 47 | 48 | 49 | QLayout::SetDefaultConstraint 50 | 51 | 52 | 0 53 | 54 | 55 | 0 56 | 57 | 58 | 0 59 | 60 | 61 | 0 62 | 63 | 64 | 65 | 66 | 67 | 0 68 | 0 69 | 70 | 71 | 72 | 73 | 0 74 | 0 75 | 76 | 77 | 78 | 79 | 16777215 80 | 150 81 | 82 | 83 | 84 | false 85 | 86 | 87 | Prompt 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 0 96 | 0 97 | 98 | 99 | 100 | 101 | 3 102 | 103 | 104 | 3 105 | 106 | 107 | 3 108 | 109 | 110 | 3 111 | 112 | 113 | 3 114 | 115 | 116 | 117 | 118 | 119 | 0 120 | 0 121 | 122 | 123 | 124 | Gen. 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 0 133 | 0 134 | 135 | 136 | 137 | Clear 138 | 139 | 140 | 141 | 142 | 143 | 144 | Stop 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 1 159 | 160 | 161 | 0 162 | 163 | 164 | 0 165 | 166 | 167 | 0 168 | 169 | 170 | 0 171 | 172 | 173 | 174 | 175 | 176 | 0 177 | 0 178 | 179 | 180 | 181 | Workflows 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 0 190 | 0 191 | 192 | 193 | 194 | Settings 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | -------------------------------------------------------------------------------- /.github/actions/setup-macos-codesigning/action.yaml: -------------------------------------------------------------------------------- 1 | name: Set up macOS codesigning 2 | description: Sets up code signing certificates, provisioning profiles, and notarization information 3 | inputs: 4 | codesignIdentity: 5 | description: Codesigning identity 6 | required: true 7 | installerIdentity: 8 | description: Codesigning identity for package installer 9 | required: false 10 | codesignCertificate: 11 | description: PKCS12 certificate in base64 format 12 | required: true 13 | certificatePassword: 14 | description: Password required to install PKCS12 certificate 15 | required: true 16 | keychainPassword: 17 | description: Password to use for temporary keychain 18 | required: false 19 | notarizationUser: 20 | description: Apple ID to use for notarization 21 | required: false 22 | notarizationPassword: 23 | description: Application password for notarization 24 | provisioningProfile: 25 | description: Provisioning profile in base64 format 26 | required: false 27 | outputs: 28 | haveCodesignIdent: 29 | description: True if necessary codesigning credentials were found 30 | value: ${{ steps.codesign.outputs.haveCodesignIdent }} 31 | haveProvisioningProfile: 32 | description: True if necessary provisioning profile credentials were found 33 | value: ${{ steps.provisioning.outputs.haveProvisioningProfile }} 34 | haveNotarizationUser: 35 | description: True if necessary notarization credentials were found 36 | value: ${{ steps.notarization.outputs.haveNotarizationUser }} 37 | codesignIdent: 38 | description: Codesigning identity 39 | value: ${{ steps.codesign.outputs.codesignIdent }} 40 | installerIdent: 41 | description: Codesigning identity for package installer 42 | value: ${{ steps.codesign.outputs.installerIdent }} 43 | codesignTeam: 44 | description: Codesigning team 45 | value: ${{ steps.codesign.outputs.codesignTeam }} 46 | runs: 47 | using: composite 48 | steps: 49 | - name: Check Runner Operating System 🏃‍♂️ 50 | if: runner.os != 'macOS' 51 | shell: bash 52 | run: | 53 | : Check Runner Operating System 🏃‍♂️ 54 | echo "setup-macos-codesigning action requires a macOS-based runner." 55 | exit 2 56 | 57 | - name: macOS Codesigning ✍️ 58 | shell: zsh --no-rcs --errexit --pipefail {0} 59 | id: codesign 60 | env: 61 | MACOS_SIGNING_IDENTITY: ${{ inputs.codesignIdentity }} 62 | MACOS_SIGNING_IDENTITY_INSTALLER: ${{ inputs.installerIdentity}} 63 | MACOS_SIGNING_CERT: ${{ inputs.codesignCertificate }} 64 | MAOCS_SIGNING_CERT_PASSWORD: ${{ inputs.certificatePassword }} 65 | MACOS_KEYCHAIN_PASSWORD: ${{ inputs.keychainPassword }} 66 | run: | 67 | : macOS Codesigning ✍️ 68 | if (( ${+RUNNER_DEBUG} )) setopt XTRACE 69 | 70 | if [[ ${MACOS_SIGNING_IDENTITY} && ${MACOS_SIGNING_IDENTITY_INSTALLER} && ${MACOS_SIGNING_CERT} ]] { 71 | print 'haveCodesignIdent=true' >> $GITHUB_OUTPUT 72 | 73 | local -r certificate_path="${RUNNER_TEMP}/build_certificate.p12" 74 | local -r keychain_path="${RUNNER_TEMP}/app-signing.keychain-db" 75 | 76 | print -n "${MACOS_SIGNING_CERT}" | base64 --decode --output="${certificate_path}" 77 | 78 | : "${MACOS_KEYCHAIN_PASSWORD:="$(print ${RANDOM} | sha1sum | head -c 32)"}" 79 | 80 | print '::group::Keychain setup' 81 | security create-keychain -p "${MACOS_KEYCHAIN_PASSWORD}" ${keychain_path} 82 | security set-keychain-settings -lut 21600 ${keychain_path} 83 | security unlock-keychain -p "${MACOS_KEYCHAIN_PASSWORD}" ${keychain_path} 84 | 85 | security import "${certificate_path}" -P "${MAOCS_SIGNING_CERT_PASSWORD}" -A \ 86 | -t cert -f pkcs12 -k ${keychain_path} \ 87 | -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/xcrun 88 | 89 | security set-key-partition-list -S 'apple-tool:,apple:' -k "${MACOS_KEYCHAIN_PASSWORD}" \ 90 | ${keychain_path} &> /dev/null 91 | 92 | security list-keychain -d user -s ${keychain_path} 'login-keychain' 93 | print '::endgroup::' 94 | 95 | local -r team_id="${${MACOS_SIGNING_IDENTITY##* }//(\(|\))/}" 96 | 97 | print "codesignIdent=${MACOS_SIGNING_IDENTITY}" >> $GITHUB_OUTPUT 98 | print "installerIdent=${MACOS_SIGNING_IDENTITY_INSTALLER}" >> $GITHUB_OUTPUT 99 | print "MACOS_KEYCHAIN_PASSWORD=${MACOS_KEYCHAIN_PASSWORD}" >> $GITHUB_ENV 100 | print "codesignTeam=${team_id}" >> $GITHUB_OUTPUT 101 | } else { 102 | print 'haveCodesignIdent=false' >> $GITHUB_OUTPUT 103 | } 104 | 105 | - name: Provisioning Profile 👤 106 | shell: zsh --no-rcs --errexit --pipefail {0} 107 | id: provisioning 108 | if: ${{ fromJSON(steps.codesign.outputs.haveCodesignIdent) }} 109 | env: 110 | MACOS_SIGNING_PROVISIONING_PROFILE: ${{ inputs.provisioningProfile }} 111 | run: | 112 | : Provisioning Profile 👤 113 | if (( ${+RUNNER_DEBUG} )) setopt XTRACE 114 | 115 | if [[ ${MACOS_SIGNING_PROVISIONING_PROFILE} ]] { 116 | print 'haveProvisioningProfile=true' >> $GITHUB_OUTPUT 117 | 118 | local -r profile_path="${RUNNER_TEMP}/build_profile.provisionprofile" 119 | print -n "${MACOS_SIGNING_PROVISIONING_PROFILE}" \ 120 | | base64 --decode --output ${profile_path} 121 | 122 | print '::group::Provisioning Profile Setup' 123 | mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles 124 | security cms -D -i ${profile_path} -o ${RUNNER_TEMP}/build_profile.plist 125 | local -r uuid="$(plutil -extract UUID raw ${RUNNER_TEMP}/build_profile.plist)" 126 | local -r team_id="$(plutil -extract TeamIdentifier.0 raw -expect string ${RUNNER_TEMP}/build_profile.plist)" 127 | 128 | if [[ ${team_id} != '${{ steps.codesign.codesignTeam }}' ]] { 129 | print '::notice::Code Signing team in provisioning profile does not match certificate.' 130 | } 131 | 132 | cp ${profile_path} ~/Library/MobileDevice/Provisioning\ Profiles/${uuid}.provisionprofile 133 | print "provisioningProfileUUID=${uuid}" >> $GITHUB_OUTPUT 134 | print '::endgroup::' 135 | } else { 136 | print 'haveProvisioningProfile=false' >> $GITHUB_OUTPUT 137 | } 138 | 139 | - name: Notarization 🧑‍💼 140 | shell: zsh --no-rcs --errexit --pipefail {0} 141 | id: notarization 142 | if: ${{ fromJSON(steps.codesign.outputs.haveCodesignIdent) }} 143 | env: 144 | MACOS_NOTARIZATION_USERNAME: ${{ inputs.notarizationUser }} 145 | MACOS_NOTARIZATION_PASSWORD: ${{ inputs.notarizationPassword }} 146 | run: | 147 | : Notarization 🧑‍💼 148 | if (( ${+RUNNER_DEBUG} )) setopt XTRACE 149 | 150 | if [[ ${MACOS_NOTARIZATION_USERNAME} && ${MACOS_NOTARIZATION_PASSWORD} ]] { 151 | print 'haveNotarizationUser=true' >> $GITHUB_OUTPUT 152 | } else { 153 | print 'haveNotarizationUser=false' >> $GITHUB_OUTPUT 154 | } 155 | -------------------------------------------------------------------------------- /cmake/BuildLlamacpp.cmake: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | 3 | set(CMAKE_OSX_ARCHITECTURES_ "arm64$x86_64") 4 | 5 | if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo) 6 | set(Llamacpp_BUILD_TYPE Release) 7 | else() 8 | set(Llamacpp_BUILD_TYPE Debug) 9 | endif() 10 | 11 | # On linux add the `-fPIC` flag to the compiler 12 | if(UNIX AND NOT APPLE) 13 | set(LLAMA_EXTRA_CXX_FLAGS "-fPIC") 14 | set(LLAMA_ADDITIONAL_CMAKE_ARGS -DLLAMA_NATIVE=ON) 15 | endif() 16 | if(APPLE) 17 | set(LLAMA_ADDITIONAL_CMAKE_ARGS -DLLAMA_NATIVE=OFF -DLLAMA_METAL=OFF -DLLAMA_AVX=ON -DLLAMA_AVX2=ON -DLLAMA_FMA=ON 18 | -DLLAMA_F16C=ON) 19 | endif() 20 | 21 | if(WIN32) 22 | if(BRAIN_WITH_CUDA) 23 | # Build with CUDA Check that CUDA_TOOLKIT_ROOT_DIR is set 24 | if(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) 25 | message(FATAL_ERROR "CUDA_TOOLKIT_ROOT_DIR is not set. Please set it to the root directory of your CUDA " 26 | "installation.") 27 | endif(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) 28 | 29 | set(LLAMA_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}") 30 | set(LLAMA_ADDITIONAL_CMAKE_ARGS -DLLAMA_CUBLAS=ON -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) 31 | else() 32 | # Build with OpenBLAS 33 | set(OpenBLAS_URL "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip") 34 | set(OpenBLAS_SHA256 "6335128ee7117ea2dd2f5f96f76dafc17256c85992637189a2d5f6da0c608163") 35 | ExternalProject_Add( 36 | OpenBLAS 37 | URL ${OpenBLAS_URL} 38 | URL_HASH SHA256=${OpenBLAS_SHA256} 39 | DOWNLOAD_NO_PROGRESS true 40 | CONFIGURE_COMMAND "" 41 | BUILD_COMMAND "" 42 | INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ) 43 | ExternalProject_Get_Property(OpenBLAS INSTALL_DIR) 44 | set(OpenBLAS_DIR ${INSTALL_DIR}) 45 | set(LLAMA_ADDITIONAL_ENV "OPENBLAS_PATH=${OpenBLAS_DIR}") 46 | set(LLAMA_ADDITIONAL_CMAKE_ARGS -DLLAMA_BLAS=ON -DLLAMA_CUBLAS=OFF 47 | -DLLAMA_BLAS_VENDOR=OpenBLAS -DBLAS_LIBRARIES=${OpenBLAS_DIR}/lib/libopenblas.lib 48 | -DBLAS_INCLUDE_DIRS=${OpenBLAS_DIR}/include) 49 | endif() 50 | 51 | ExternalProject_Add( 52 | Llamacpp_Build 53 | DOWNLOAD_EXTRACT_TIMESTAMP true 54 | GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git 55 | GIT_TAG f28af0d81aa1010afa5de74cf627dcb04bea3157 56 | BUILD_COMMAND ${CMAKE_COMMAND} --build --config ${Llamacpp_BUILD_TYPE} 57 | BUILD_BYPRODUCTS 58 | /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}llama${CMAKE_STATIC_LIBRARY_SUFFIX} 59 | /bin/${CMAKE_SHARED_LIBRARY_PREFIX}llama${CMAKE_SHARED_LIBRARY_SUFFIX} 60 | /lib/${CMAKE_IMPORT_LIBRARY_PREFIX}llama${CMAKE_IMPORT_LIBRARY_SUFFIX} 61 | CMAKE_GENERATOR ${CMAKE_GENERATOR} 62 | INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Llamacpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy 63 | /${Llamacpp_BUILD_TYPE}/llama.lib /lib 64 | CONFIGURE_COMMAND 65 | ${CMAKE_COMMAND} -E env ${LLAMA_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G 66 | ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Llamacpp_BUILD_TYPE} 67 | -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 68 | -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${LLAMA_EXTRA_CXX_FLAGS} 69 | -DCMAKE_C_FLAGS=${LLAMA_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=ON -DLLAMA_BUILD_TESTS=OFF 70 | -DLLAMA_BUILD_EXAMPLES=OFF ${LLAMA_ADDITIONAL_CMAKE_ARGS} -DLLAMA_STATIC=OFF) 71 | 72 | if(NOT BRAIN_WITH_CUDA) 73 | add_dependencies(Llamacpp_Build OpenBLAS) 74 | endif(NOT BRAIN_WITH_CUDA) 75 | else() 76 | # On Linux and MacOS build a static Llama library 77 | ExternalProject_Add( 78 | Llamacpp_Build 79 | DOWNLOAD_EXTRACT_TIMESTAMP true 80 | GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git 81 | GIT_TAG f28af0d81aa1010afa5de74cf627dcb04bea3157 82 | BUILD_COMMAND ${CMAKE_COMMAND} --build --config ${Llamacpp_BUILD_TYPE} 83 | BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}llama${CMAKE_STATIC_LIBRARY_SUFFIX} 84 | CMAKE_GENERATOR ${CMAKE_GENERATOR} 85 | INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Llamacpp_BUILD_TYPE} 86 | CONFIGURE_COMMAND 87 | ${CMAKE_COMMAND} -E env ${LLAMA_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G 88 | ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Llamacpp_BUILD_TYPE} 89 | -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 90 | -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${LLAMA_EXTRA_CXX_FLAGS} 91 | -DCMAKE_C_FLAGS=${LLAMA_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=OFF -DLLAMA_BUILD_TESTS=OFF 92 | -DLLAMA_BUILD_EXAMPLES=OFF ${LLAMA_ADDITIONAL_CMAKE_ARGS} -DLLAMA_STATIC=ON) 93 | endif(WIN32) 94 | 95 | ExternalProject_Get_Property(Llamacpp_Build INSTALL_DIR) 96 | 97 | # add the Llama library to the link line 98 | if(WIN32) 99 | add_library(Llamacpp::Llama SHARED IMPORTED) 100 | set_target_properties( 101 | Llamacpp::Llama PROPERTIES IMPORTED_LOCATION 102 | ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}llama${CMAKE_SHARED_LIBRARY_SUFFIX}) 103 | set_target_properties( 104 | Llamacpp::Llama PROPERTIES IMPORTED_IMPLIB 105 | ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}llama${CMAKE_STATIC_LIBRARY_SUFFIX}) 106 | 107 | install(FILES ${INSTALL_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}llama${CMAKE_SHARED_LIBRARY_SUFFIX} 108 | DESTINATION "obs-plugins/64bit") 109 | 110 | if(NOT BRAIN_WITH_CUDA) 111 | # add openblas to the link line 112 | add_library(Llamacpp::OpenBLAS STATIC IMPORTED) 113 | set_target_properties(Llamacpp::OpenBLAS PROPERTIES IMPORTED_LOCATION ${OpenBLAS_DIR}/lib/libopenblas.dll.a) 114 | install(FILES ${OpenBLAS_DIR}/bin/libopenblas.dll DESTINATION "obs-plugins/64bit") 115 | else(NOT BRAIN_WITH_CUDA) 116 | # normalize CUDA path with file(TO_CMAKE_PATH) 117 | file(TO_CMAKE_PATH ${CUDA_TOOLKIT_ROOT_DIR} CUDA_TOOLKIT_ROOT_DIR) 118 | # find the CUDA DLLs for cuBLAS in the bin directory of the CUDA installation e.g. cublas64_NN.dll 119 | file(GLOB CUBLAS_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cublas64_*.dll") 120 | # find cublasLt DLL, e.g. cublasLt64_11.dll 121 | file(GLOB CUBLASLT_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cublasLt64_*.dll") 122 | # find cudart DLL, e.g. cudart64_110.dll 123 | file(GLOB CUDART_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cudart64_*.dll") 124 | # if any of the files cannot be found, abort 125 | if(NOT CUBLAS_DLLS 126 | OR NOT CUBLASLT_DLLS 127 | OR NOT CUDART_DLLS) 128 | message(FATAL_ERROR "Could not find cuBLAS, cuBLASLt or cuDART DLLs in ${CUDA_TOOLKIT_ROOT_DIR}/bin") 129 | endif() 130 | # copy the DLLs to the OBS plugin directory 131 | install(FILES ${CUBLAS_DLLS} ${CUBLASLT_DLLS} ${CUDART_DLLS} DESTINATION "obs-plugins/64bit") 132 | endif(NOT BRAIN_WITH_CUDA) 133 | else() 134 | # on Linux and MacOS add the static Llama library to the link line 135 | add_library(Llamacpp::Llama STATIC IMPORTED) 136 | set_target_properties( 137 | Llamacpp::Llama PROPERTIES IMPORTED_LOCATION 138 | ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}llama${CMAKE_STATIC_LIBRARY_SUFFIX}) 139 | endif(WIN32) 140 | 141 | add_library(Llamacpp INTERFACE) 142 | add_dependencies(Llamacpp Llamacpp_Build) 143 | target_link_libraries(Llamacpp INTERFACE Llamacpp::Llama) 144 | if(WIN32 AND NOT BRAIN_WITH_CUDA) 145 | target_link_libraries(Llamacpp INTERFACE Llamacpp::OpenBLAS) 146 | endif() 147 | set_target_properties(Llamacpp::Llama PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include) 148 | if(APPLE) 149 | target_link_libraries(Llamacpp INTERFACE "-framework Accelerate") 150 | endif(APPLE) 151 | -------------------------------------------------------------------------------- /src/llm-dock/ui/settingsdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SettingsDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 500 10 | 397 11 | 12 | 13 | 14 | 15 | 500 16 | 0 17 | 18 | 19 | 20 | BrAIn Settings 21 | 22 | 23 | true 24 | 25 | 26 | 27 | 6 28 | 29 | 30 | 6 31 | 32 | 33 | 6 34 | 35 | 36 | 6 37 | 38 | 39 | 6 40 | 41 | 42 | 43 | 44 | 0 45 | 46 | 47 | 48 | General 49 | 50 | 51 | 52 | QFormLayout::ExpandingFieldsGrow 53 | 54 | 55 | Qt::AlignCenter 56 | 57 | 58 | 59 | 60 | Dock LLM 61 | 62 | 63 | 64 | 65 | 66 | 67 | true 68 | 69 | 70 | 71 | Local 72 | 73 | 74 | 75 | 76 | Cloud 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | Prompt Templ. 85 | 86 | 87 | 88 | 89 | 90 | 91 | Max. Tokens 92 | 93 | 94 | 95 | 96 | 97 | 98 | 64 99 | 100 | 101 | 102 | 103 | 104 | 105 | Temperature 106 | 107 | 108 | 109 | 110 | 111 | 112 | 0.9 113 | 114 | 115 | 116 | 117 | 118 | 119 | <|im_start|>system... 120 | 121 | 122 | 123 | 124 | 125 | 126 | End sequence 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | Local LLM 138 | 139 | 140 | 141 | 142 | 143 | LLM File 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 2 152 | 153 | 154 | 0 155 | 156 | 157 | 0 158 | 159 | 160 | 0 161 | 162 | 163 | 0 164 | 165 | 166 | 167 | 168 | .gguf 169 | 170 | 171 | 172 | 173 | 174 | 175 | ... 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | Cloud LLM 187 | 188 | 189 | 190 | 191 | 192 | OpenAI API Key 193 | 194 | 195 | 196 | 197 | 198 | 199 | QLineEdit::Password 200 | 201 | 202 | sk-... 203 | 204 | 205 | 206 | 207 | 208 | 209 | Model 210 | 211 | 212 | 213 | 214 | 215 | 216 | gpt-3.5-turbo 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | Qt::Horizontal 228 | 229 | 230 | QDialogButtonBox::Cancel|QDialogButtonBox::Save 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | buttonBox 240 | accepted() 241 | SettingsDialog 242 | accept() 243 | 244 | 245 | 248 246 | 254 247 | 248 | 249 | 157 250 | 274 251 | 252 | 253 | 254 | 255 | buttonBox 256 | rejected() 257 | SettingsDialog 258 | reject() 259 | 260 | 261 | 316 262 | 260 263 | 264 | 265 | 286 266 | 274 267 | 268 | 269 | 270 | 271 | 272 | -------------------------------------------------------------------------------- /cmake/common/buildspec_common.cmake: -------------------------------------------------------------------------------- 1 | # Common build dependencies module 2 | 3 | # cmake-format: off 4 | # cmake-lint: disable=C0103 5 | # cmake-lint: disable=E1126 6 | # cmake-lint: disable=R0912 7 | # cmake-lint: disable=R0915 8 | # cmake-format: on 9 | 10 | include_guard(GLOBAL) 11 | 12 | # _check_deps_version: Checks for obs-deps VERSION file in prefix paths 13 | function(_check_deps_version version) 14 | # cmake-format: off 15 | set(found FALSE PARENT_SCOPE) 16 | # cmake-format: on 17 | 18 | foreach(path IN LISTS CMAKE_PREFIX_PATH) 19 | if(EXISTS "${path}/share/obs-deps/VERSION") 20 | if(dependency STREQUAL qt6 AND NOT EXISTS "${path}/lib/cmake/Qt6/Qt6Config.cmake") 21 | # cmake-format: off 22 | set(found FALSE PARENT_SCOPE) 23 | # cmake-format: on 24 | continue() 25 | endif() 26 | 27 | file(READ "${path}/share/obs-deps/VERSION" _check_version) 28 | string(REPLACE "\n" "" _check_version "${_check_version}") 29 | string(REPLACE "-" "." _check_version "${_check_version}") 30 | string(REPLACE "-" "." version "${version}") 31 | 32 | if(_check_version VERSION_EQUAL version) 33 | # cmake-format: off 34 | set(found TRUE PARENT_SCOPE) 35 | # cmake-format: on 36 | break() 37 | elseif(_check_version VERSION_LESS version) 38 | message(AUTHOR_WARNING "Older ${label} version detected in ${path}: \n" 39 | "Found ${_check_version}, require ${version}") 40 | list(REMOVE_ITEM CMAKE_PREFIX_PATH "${path}") 41 | list(APPEND CMAKE_PREFIX_PATH "${path}") 42 | # cmake-format: off 43 | set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE) 44 | # cmake-format: on 45 | continue() 46 | else() 47 | message(AUTHOR_WARNING "Newer ${label} version detected in ${path}: \n" 48 | "Found ${_check_version}, require ${version}") 49 | # cmake-format: off 50 | set(found TRUE PARENT_SCOPE) 51 | # cmake-format: on 52 | break() 53 | endif() 54 | endif() 55 | endforeach() 56 | endfunction() 57 | 58 | # _setup_obs_studio: Create obs-studio build project, then build libobs and obs-frontend-api 59 | function(_setup_obs_studio) 60 | if(NOT libobs_DIR) 61 | set(_is_fresh --fresh) 62 | endif() 63 | 64 | if(OS_WINDOWS) 65 | set(_cmake_generator "${CMAKE_GENERATOR}") 66 | set(_cmake_arch "-A ${arch}") 67 | set(_cmake_extra "-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION} -DCMAKE_ENABLE_SCRIPTING=OFF") 68 | set(_cmake_version "2.0.0") 69 | elseif(OS_MACOS) 70 | set(_cmake_generator "Xcode") 71 | set(_cmake_arch "-DCMAKE_OSX_ARCHITECTURES:STRING='arm64;x86_64'") 72 | set(_cmake_extra "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}") 73 | set(_cmake_version "3.0.0") 74 | endif() 75 | 76 | message(STATUS "Patch libobs") 77 | execute_process( 78 | COMMAND patch --forward "libobs/CMakeLists.txt" "${CMAKE_CURRENT_SOURCE_DIR}/patch_libobs.diff" 79 | RESULT_VARIABLE _process_result 80 | WORKING_DIRECTORY "${dependencies_dir}/${_obs_destination}") 81 | message(STATUS "Patch - done") 82 | 83 | message(STATUS "Configure ${label} (${arch})") 84 | execute_process( 85 | COMMAND 86 | "${CMAKE_COMMAND}" -S "${dependencies_dir}/${_obs_destination}" -B 87 | "${dependencies_dir}/${_obs_destination}/build_${arch}" -G ${_cmake_generator} "${_cmake_arch}" 88 | -DOBS_CMAKE_VERSION:STRING=${_cmake_version} -DENABLE_PLUGINS:BOOL=OFF -DENABLE_UI:BOOL=OFF 89 | -DOBS_VERSION_OVERRIDE:STRING=${_obs_version} "-DCMAKE_PREFIX_PATH='${CMAKE_PREFIX_PATH}'" ${_is_fresh} 90 | ${_cmake_extra} 91 | RESULT_VARIABLE _process_result COMMAND_ERROR_IS_FATAL ANY 92 | OUTPUT_QUIET) 93 | message(STATUS "Configure ${label} (${arch}) - done") 94 | 95 | message(STATUS "Build ${label} (${arch})") 96 | execute_process( 97 | COMMAND "${CMAKE_COMMAND}" --build build_${arch} --target obs-frontend-api --config Debug --parallel 98 | WORKING_DIRECTORY "${dependencies_dir}/${_obs_destination}" 99 | RESULT_VARIABLE _process_result COMMAND_ERROR_IS_FATAL ANY 100 | OUTPUT_QUIET) 101 | message(STATUS "Build ${label} (${arch}) - done") 102 | 103 | message(STATUS "Install ${label} (${arch})") 104 | if(OS_WINDOWS) 105 | set(_cmake_extra "--component obs_libraries") 106 | else() 107 | set(_cmake_extra "") 108 | endif() 109 | execute_process( 110 | COMMAND "${CMAKE_COMMAND}" --install build_${arch} --component Development --config Debug --prefix 111 | "${dependencies_dir}" ${_cmake_extra} 112 | WORKING_DIRECTORY "${dependencies_dir}/${_obs_destination}" 113 | RESULT_VARIABLE _process_result COMMAND_ERROR_IS_FATAL ANY 114 | OUTPUT_QUIET) 115 | message(STATUS "Install ${label} (${arch}) - done") 116 | endfunction() 117 | 118 | # _check_dependencies: Fetch and extract pre-built OBS build dependencies 119 | function(_check_dependencies) 120 | if(NOT buildspec) 121 | file(READ "${CMAKE_CURRENT_SOURCE_DIR}/buildspec.json" buildspec) 122 | endif() 123 | 124 | # cmake-format: off 125 | string(JSON dependency_data GET ${buildspec} dependencies) 126 | # cmake-format: on 127 | 128 | foreach(dependency IN LISTS dependencies_list) 129 | # cmake-format: off 130 | string(JSON data GET ${dependency_data} ${dependency}) 131 | string(JSON version GET ${data} version) 132 | string(JSON hash GET ${data} hashes ${platform}) 133 | string(JSON url GET ${data} baseUrl) 134 | string(JSON label GET ${data} label) 135 | string(JSON revision ERROR_VARIABLE error GET ${data} revision ${platform}) 136 | # cmake-format: on 137 | 138 | message(STATUS "Setting up ${label} (${arch})") 139 | 140 | set(file "${${dependency}_filename}") 141 | set(destination "${${dependency}_destination}") 142 | string(REPLACE "VERSION" "${version}" file "${file}") 143 | string(REPLACE "VERSION" "${version}" destination "${destination}") 144 | string(REPLACE "ARCH" "${arch}" file "${file}") 145 | string(REPLACE "ARCH" "${arch}" destination "${destination}") 146 | if(revision) 147 | string(REPLACE "_REVISION" "_v${revision}" file "${file}") 148 | string(REPLACE "-REVISION" "-v${revision}" file "${file}") 149 | else() 150 | string(REPLACE "_REVISION" "" file "${file}") 151 | string(REPLACE "-REVISION" "" file "${file}") 152 | endif() 153 | 154 | set(skip FALSE) 155 | if(dependency STREQUAL prebuilt OR dependency STREQUAL qt6) 156 | _check_deps_version(${version}) 157 | 158 | if(found) 159 | set(skip TRUE) 160 | endif() 161 | endif() 162 | 163 | if(skip) 164 | message(STATUS "Setting up ${label} (${arch}) - skipped") 165 | continue() 166 | endif() 167 | 168 | if(dependency STREQUAL obs-studio) 169 | set(url ${url}/${file}) 170 | else() 171 | set(url ${url}/${version}/${file}) 172 | endif() 173 | 174 | if(NOT EXISTS "${dependencies_dir}/${file}") 175 | message(STATUS "Downloading ${url}") 176 | file( 177 | DOWNLOAD "${url}" "${dependencies_dir}/${file}" 178 | STATUS download_status 179 | EXPECTED_HASH SHA256=${hash}) 180 | 181 | list(GET download_status 0 error_code) 182 | list(GET download_status 1 error_message) 183 | if(error_code GREATER 0) 184 | message(STATUS "Downloading ${url} - Failure") 185 | message(FATAL_ERROR "Unable to download ${url}, failed with error: ${error_message}") 186 | file(REMOVE "${dependencies_dir}/${file}") 187 | else() 188 | message(STATUS "Downloading ${url} - done") 189 | endif() 190 | endif() 191 | 192 | if(NOT EXISTS "${dependencies_dir}/${destination}") 193 | file(MAKE_DIRECTORY "${dependencies_dir}/${destination}") 194 | if(dependency STREQUAL obs-studio) 195 | file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}") 196 | else() 197 | file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}/${destination}") 198 | endif() 199 | endif() 200 | 201 | if(dependency STREQUAL prebuilt) 202 | list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}") 203 | elseif(dependency STREQUAL qt6) 204 | list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}") 205 | elseif(dependency STREQUAL obs-studio) 206 | set(_obs_version ${version}) 207 | set(_obs_destination "${destination}") 208 | list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}") 209 | 210 | endif() 211 | 212 | message(STATUS "Setting up ${label} (${arch}) - done") 213 | endforeach() 214 | 215 | list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH) 216 | 217 | # cmake-format: off 218 | set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} CACHE PATH "CMake prefix search path" FORCE) 219 | # cmake-format: on 220 | 221 | _setup_obs_studio() 222 | endfunction() 223 | -------------------------------------------------------------------------------- /cmake/macos/xcode.cmake: -------------------------------------------------------------------------------- 1 | # CMake macOS Xcode module 2 | 3 | include_guard(GLOBAL) 4 | 5 | # Use a compiler wrapper to enable ccache in Xcode projects 6 | if(ENABLE_CCACHE AND CCACHE_PROGRAM) 7 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos/resources/ccache-launcher-c.in" ccache-launcher-c) 8 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos/resources/ccache-launcher-cxx.in" ccache-launcher-cxx) 9 | 10 | execute_process(COMMAND chmod a+rx "${CMAKE_CURRENT_BINARY_DIR}/ccache-launcher-c" 11 | "${CMAKE_CURRENT_BINARY_DIR}/ccache-launcher-cxx") 12 | set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_CURRENT_BINARY_DIR}/ccache-launcher-c") 13 | set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_CURRENT_BINARY_DIR}/ccache-launcher-cxx") 14 | set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_C_COMPILER}") 15 | set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_CXX_COMPILER}") 16 | endif() 17 | 18 | # Set project variables 19 | set(CMAKE_XCODE_ATTRIBUTE_CURRENT_PROJECT_VERSION ${PLUGIN_BUILD_NUMBER}) 20 | set(CMAKE_XCODE_ATTRIBUTE_DYLIB_COMPATIBILITY_VERSION 1.0.0) 21 | set(CMAKE_XCODE_ATTRIBUTE_MARKETING_VERSION ${PLUGIN_VERSION}) 22 | 23 | # Set deployment target 24 | set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET}) 25 | 26 | if(NOT CODESIGN_TEAM) 27 | # Switch to manual codesigning if no codesigning team is provided 28 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual) 29 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${CODESIGN_IDENTITY}") 30 | else() 31 | if(CODESIGN_IDENTITY AND NOT CODESIGN_IDENTITY STREQUAL "-") 32 | # Switch to manual codesigning if a non-adhoc codesigning identity is provided 33 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual) 34 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${CODESIGN_IDENTITY}") 35 | else() 36 | # Switch to automatic codesigning via valid team ID 37 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE Automatic) 38 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development") 39 | endif() 40 | set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "${CODESIGN_TEAM}") 41 | endif() 42 | 43 | # Only create a single Xcode project file 44 | set(CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY TRUE) 45 | # Add all libraries to project link phase (lets Xcode handle linking) 46 | set(CMAKE_XCODE_LINK_BUILD_PHASE_MODE KNOWN_LOCATION) 47 | 48 | # Enable codesigning with secure timestamp when not in Debug configuration (required for Notarization) 49 | set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS[variant=Release] "--timestamp") 50 | set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS[variant=RelWithDebInfo] "--timestamp") 51 | set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS[variant=MinSizeRel] "--timestamp") 52 | 53 | # Enable codesigning with hardened runtime option when not in Debug configuration (required for Notarization) 54 | set(CMAKE_XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME[variant=Release] YES) 55 | set(CMAKE_XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME[variant=RelWithDebInfo] YES) 56 | set(CMAKE_XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME[variant=MinSizeRel] YES) 57 | 58 | # Disable injection of Xcode's base entitlements used for debugging when not in Debug configuration (required for 59 | # Notarization) 60 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_INJECT_BASE_ENTITLEMENTS[variant=Release] NO) 61 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_INJECT_BASE_ENTITLEMENTS[variant=RelWithDebInfo] NO) 62 | set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_INJECT_BASE_ENTITLEMENTS[variant=MinSizeRel] NO) 63 | 64 | # Use Swift version 5.0 by default 65 | set(CMAKE_XCODE_ATTRIBUTE_SWIFT_VERSION 5.0) 66 | 67 | # Use DWARF with separate dSYM files when in Release or MinSizeRel configuration. 68 | # 69 | # * Currently overruled by CMake's Xcode generator, requires adding '-g' flag to raw compiler command line for desired 70 | # output configuration. Report to KitWare. 71 | # 72 | set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT[variant=Debug] dwarf) 73 | set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT[variant=RelWithDebInfo] dwarf) 74 | set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT[variant=Release] dwarf-with-dsym) 75 | set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT[variant=MinSizeRel] dwarf-with-dsym) 76 | 77 | # Make all symbols hidden by default (currently overriden by CMake's compiler flags) 78 | set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES) 79 | set(CMAKE_XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN YES) 80 | 81 | # Strip unused code 82 | set(CMAKE_XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING YES) 83 | 84 | # Display mangled names in Debug configuration 85 | set(CMAKE_XCODE_ATTRIBUTE_LINKER_DISPLAYS_MANGLED_NAMES[variant=Debug] YES) 86 | 87 | # Build active architecture only in Debug configuration 88 | set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Debug] YES) 89 | 90 | # Enable testability in Debug configuration 91 | set(CMAKE_XCODE_ATTRIBUTE_ENABLE_TESTABILITY[variant=Debug] YES) 92 | 93 | # Enable using ARC in ObjC by default 94 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES) 95 | # Enable weak references in manual retain release 96 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_WEAK YES) 97 | # Disable strict aliasing 98 | set(CMAKE_XCODE_ATTRIBUTE_GCC_STRICT_ALIASING NO) 99 | 100 | # Set C++ language default to c17 101 | # 102 | # * CMake explicitly sets the version via compiler flag when transitive dependencies require specific compiler feature 103 | # set, resulting in the flag being added twice. Report to KitWare as a feature request for Xcode generator 104 | # * See also: https://gitlab.kitware.com/cmake/cmake/-/issues/17183 105 | # 106 | # set(CMAKE_XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD c17) 107 | # 108 | # Set C++ language default to c++17 109 | # 110 | # * See above. Report to KitWare as a feature request for Xcode generator 111 | # 112 | # set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD c++17) 113 | 114 | # Enable support for module imports in ObjC 115 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES YES) 116 | # Enable automatic linking of imported modules in ObjC 117 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_MODULES_AUTOLINK YES) 118 | # Enable strict msg_send rules for ObjC 119 | set(CMAKE_XCODE_ATTRIBUTE_ENABLE_STRICT_OBJC_MSGSEND YES) 120 | 121 | # Set default warnings for ObjC and C++ 122 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING YES_ERROR) 123 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION YES) 124 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS YES) 125 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_COMMA YES) 126 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION YES) 127 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY YES) 128 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION YES) 129 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INFINITE_RECURSION YES) 130 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION YES) 131 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_NON_LITERAL_NULL_CONVERSION YES) 132 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF YES) 133 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_OBJC_LITERAL_CONVERSION YES) 134 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK YES) 135 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER YES) 136 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_RANGE_LOOP_ANALYSIS YES) 137 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_STRICT_PROTOTYPES NO) 138 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION NO) 139 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_SUSPICIOUS_MOVE YES) 140 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_UNREACHABLE_CODE YES) 141 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN__DUPLICATE_METHOD_MATCH YES) 142 | 143 | # Set default warnings for C and C++ 144 | set(CMAKE_XCODE_ATTRIBUTE_GCC_NO_COMMON_BLOCKS YES) 145 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION YES) 146 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS NO) 147 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE YES) 148 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE YES_ERROR) 149 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_CHECK_SWITCH_STATEMENTS YES) 150 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_FOUR_CHARACTER_CONSTANTS YES) 151 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SHADOW NO) 152 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE YES) 153 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_TYPECHECK_CALLS_TO_PRINTF YES) 154 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNDECLARED_SELECTOR YES) 155 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS YES) 156 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION NO) 157 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_PARAMETER YES) 158 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE YES) 159 | set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE YES) 160 | 161 | # Add additional warning compiler flags 162 | set(CMAKE_XCODE_ATTRIBUTE_WARNING_CFLAGS "-Wvla -Wformat-security") 163 | 164 | if(CMAKE_COMPILE_WARNING_AS_ERROR) 165 | set(CMAKE_XCODE_ATTRIBUTE_GCC_TREAT_WARNINGS_AS_ERRORS YES) 166 | endif() 167 | 168 | # Enable color diagnostics 169 | set(CMAKE_COLOR_DIAGNOSTICS TRUE) 170 | 171 | # Disable usage of RPATH in build or install configurations 172 | set(CMAKE_SKIP_RPATH TRUE) 173 | # Have Xcode set default RPATH entries 174 | set(CMAKE_XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks") 175 | -------------------------------------------------------------------------------- /src/llm-dock/llama-inference.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "llama-inference.h" 3 | #include "plugin-support.h" 4 | #include "llm-config-data.h" 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | std::string replace(const std::string &s, const std::string &from, const std::string &to) 16 | { 17 | std::string result = s; 18 | size_t pos = 0; 19 | while ((pos = result.find(from, pos)) != std::string::npos) { 20 | result.replace(pos, from.length(), to); 21 | pos += to.length(); 22 | } 23 | return result; 24 | } 25 | 26 | std::string get_system_info(const llama_context_params ¶ms) 27 | { 28 | std::ostringstream os; 29 | 30 | os << "system_info: n_threads = " << params.n_threads; 31 | os << " (n_threads_batch = " << params.n_threads_batch << ")"; 32 | os << " / " << std::thread::hardware_concurrency() << " | " << llama_print_system_info(); 33 | 34 | return os.str(); 35 | } 36 | 37 | void llama_batch_clear(struct llama_batch &batch) 38 | { 39 | batch.n_tokens = 0; 40 | } 41 | 42 | void llama_batch_add(struct llama_batch &batch, llama_token id, llama_pos pos, 43 | const std::vector &seq_ids, bool logits) 44 | { 45 | batch.token[batch.n_tokens] = id; 46 | batch.pos[batch.n_tokens] = pos, batch.n_seq_id[batch.n_tokens] = (int32_t)seq_ids.size(); 47 | for (size_t i = 0; i < seq_ids.size(); ++i) { 48 | batch.seq_id[batch.n_tokens][i] = seq_ids[i]; 49 | } 50 | batch.logits[batch.n_tokens] = logits; 51 | 52 | batch.n_tokens++; 53 | } 54 | 55 | std::vector llama_tokenize(const struct llama_model *model, const std::string &text, 56 | bool add_bos, bool special = false) 57 | { 58 | // upper limit for the number of tokens 59 | int n_tokens = (int)text.length() + (add_bos ? 1 : 0); 60 | std::vector result(n_tokens); 61 | n_tokens = llama_tokenize(model, text.data(), (int)text.length(), result.data(), 62 | (int)result.size(), add_bos, special); 63 | if (n_tokens < 0) { 64 | result.resize(-n_tokens); 65 | int check = llama_tokenize(model, text.data(), (int)text.length(), result.data(), 66 | (int)result.size(), add_bos, special); 67 | GGML_ASSERT(check == -n_tokens); 68 | } else { 69 | result.resize(n_tokens); 70 | } 71 | return result; 72 | } 73 | 74 | std::vector llama_tokenize(const struct llama_context *ctx, const std::string &text, 75 | bool add_bos, bool special = false) 76 | { 77 | return llama_tokenize(llama_get_model(ctx), text, add_bos, special); 78 | } 79 | 80 | std::string llama_token_to_piece(const struct llama_context *ctx, llama_token token) 81 | { 82 | std::vector result(8, 0); 83 | const int n_tokens = llama_token_to_piece(llama_get_model(ctx), token, result.data(), 84 | (int)result.size()); 85 | if (n_tokens < 0) { 86 | result.resize(-n_tokens); 87 | int check = llama_token_to_piece(llama_get_model(ctx), token, result.data(), 88 | (int)result.size()); 89 | GGML_ASSERT(check == (int)-n_tokens); 90 | } else { 91 | result.resize(n_tokens); 92 | } 93 | 94 | return std::string(result.data(), result.size()); 95 | } 96 | 97 | struct llama_context *llama_init_context(const std::string &model_file_path) 98 | { 99 | llama_backend_init(true); 100 | 101 | // initialize the model 102 | struct llama_model_params mparams = llama_model_default_params(); 103 | 104 | struct llama_model *model_llama = 105 | llama_load_model_from_file(model_file_path.c_str(), mparams); 106 | 107 | if (model_llama == nullptr) { 108 | obs_log(LOG_ERROR, "%s: error: unable to load model\n", __func__); 109 | return nullptr; 110 | } 111 | 112 | // get model details using llama_model_desc 113 | char model_desc[128]; 114 | llama_model_desc(model_llama, model_desc, sizeof(model_desc)); 115 | obs_log(LOG_INFO, "%s: model_desc = %s", __func__, model_desc); 116 | 117 | // initialize the context 118 | struct llama_context_params lparams = llama_context_default_params(); 119 | 120 | struct llama_context *ctx_llama = llama_new_context_with_model(model_llama, lparams); 121 | 122 | if (ctx_llama == nullptr) { 123 | obs_log(LOG_ERROR, "%s: error: failed to create the llama_context", __func__); 124 | return nullptr; 125 | } 126 | 127 | if (llama_get_model(ctx_llama) == nullptr) { 128 | obs_log(LOG_ERROR, "%s: error: failed to get model from llama_context", __func__); 129 | return nullptr; 130 | } 131 | 132 | obs_log(LOG_INFO, "%s", get_system_info(lparams).c_str()); 133 | 134 | // Warm up in another thread 135 | std::thread t([ctx_llama, lparams]() { 136 | obs_log(LOG_INFO, "warming up the model with an empty run"); 137 | 138 | std::vector tokens_list = { 139 | llama_token_bos(llama_get_model(ctx_llama)), 140 | llama_token_eos(llama_get_model(ctx_llama)), 141 | }; 142 | 143 | llama_decode(ctx_llama, llama_batch_get_one(tokens_list.data(), 144 | (int)std::min(tokens_list.size(), 145 | (size_t)lparams.n_batch), 146 | 0, 0)); 147 | llama_kv_cache_clear(ctx_llama); 148 | llama_reset_timings(ctx_llama); 149 | 150 | obs_log(LOG_INFO, "warmed up the model"); 151 | }); 152 | t.detach(); 153 | 154 | return ctx_llama; 155 | } 156 | 157 | std::string llama_inference(const std::string &promptIn, struct llama_context *ctx, 158 | std::function partial_generation_callback, 159 | std::function should_stop_callback) 160 | { 161 | std::string output = ""; 162 | 163 | // tokenize the prompt 164 | // replace {0} in the system prompt with the prompt 165 | std::string prompt = replace(global_llm_config.system_prompt, "{0}", promptIn); 166 | 167 | std::vector tokens_list; 168 | tokens_list = ::llama_tokenize(ctx, prompt, true); 169 | 170 | // total length of the sequence including the prompt 171 | const int n_len = 512; 172 | 173 | const int n_ctx = llama_n_ctx(ctx); 174 | const int n_kv_req = (int)(tokens_list.size() + (n_len - tokens_list.size())); 175 | 176 | obs_log(LOG_INFO, "%s: n_len = %d, n_ctx = %d, n_kv_req = %d", __func__, n_len, n_ctx, 177 | n_kv_req); 178 | 179 | // make sure the KV cache is big enough to hold all the prompt and generated tokens 180 | if (n_kv_req > n_ctx) { 181 | obs_log(LOG_INFO, 182 | "%s: error: n_kv_req > n_ctx, the required KV cache size is not big enough", 183 | __func__); 184 | obs_log(LOG_INFO, "%s: either reduce n_parallel or increase n_ctx", 185 | __func__); 186 | return ""; 187 | } 188 | 189 | // create a llama_batch with size 512 190 | // we use this object to submit token data for decoding 191 | 192 | llama_batch batch = llama_batch_init(512, 0, 1); 193 | 194 | // evaluate the initial prompt 195 | for (size_t i = 0; i < tokens_list.size(); i++) { 196 | llama_batch_add(batch, tokens_list[i], (llama_pos)i, {0}, false); 197 | } 198 | 199 | // llama_decode will output logits only for the last token of the prompt 200 | batch.logits[batch.n_tokens - 1] = true; 201 | 202 | if (llama_decode(ctx, batch) != 0) { 203 | obs_log(LOG_INFO, "%s: llama_decode() failed\n", __func__); 204 | return ""; 205 | } 206 | 207 | // main loop 208 | 209 | int n_cur = batch.n_tokens; 210 | int n_decode = 0; 211 | 212 | const auto t_main_start = ggml_time_us(); 213 | 214 | while (n_cur <= n_len) { 215 | // sample the next token 216 | { 217 | auto n_vocab = llama_n_vocab(llama_get_model(ctx)); 218 | auto *logits = llama_get_logits_ith(ctx, batch.n_tokens - 1); 219 | 220 | std::vector candidates; 221 | candidates.reserve(n_vocab); 222 | 223 | for (llama_token token_id = 0; token_id < n_vocab; token_id++) { 224 | candidates.emplace_back( 225 | llama_token_data{token_id, logits[token_id], 0.0f}); 226 | } 227 | 228 | llama_token_data_array candidates_p = {candidates.data(), candidates.size(), 229 | false}; 230 | 231 | // sample the most likely token 232 | const llama_token new_token_id = 233 | llama_sample_token_greedy(ctx, &candidates_p); 234 | 235 | // is it an end of stream? 236 | if (new_token_id == llama_token_eos(llama_get_model(ctx)) || 237 | n_cur == n_len) { 238 | break; 239 | } 240 | 241 | std::string piece = llama_token_to_piece(ctx, new_token_id); 242 | partial_generation_callback(piece); 243 | output += piece; 244 | 245 | // prepare the next batch 246 | llama_batch_clear(batch); 247 | 248 | // push this new token for next evaluation 249 | llama_batch_add(batch, new_token_id, n_cur, {0}, true); 250 | 251 | n_decode += 1; 252 | } 253 | 254 | n_cur += 1; 255 | 256 | // evaluate the current batch with the transformer model 257 | if (llama_decode(ctx, batch)) { 258 | obs_log(LOG_ERROR, "%s : failed to eval, return code %d", __func__, 1); 259 | return ""; 260 | } 261 | 262 | if (should_stop_callback(output)) { 263 | break; 264 | } 265 | } 266 | 267 | // reset the KV cache 268 | llama_kv_cache_clear(ctx); 269 | llama_reset_timings(ctx); 270 | 271 | const auto t_main_end = ggml_time_us(); 272 | 273 | obs_log(LOG_INFO, "%s: decoded %d tokens in %.2f s, speed: %.2f t/s", __func__, n_decode, 274 | (t_main_end - t_main_start) / 1000000.0f, 275 | n_decode / ((t_main_end - t_main_start) / 1000000.0f)); 276 | 277 | return output; 278 | } 279 | -------------------------------------------------------------------------------- /.github/scripts/.package.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | 3 | builtin emulate -L zsh 4 | setopt EXTENDED_GLOB 5 | setopt PUSHD_SILENT 6 | setopt ERR_EXIT 7 | setopt ERR_RETURN 8 | setopt NO_UNSET 9 | setopt PIPE_FAIL 10 | setopt NO_AUTO_PUSHD 11 | setopt NO_PUSHD_IGNORE_DUPS 12 | setopt FUNCTION_ARGZERO 13 | 14 | ## Enable for script debugging 15 | # setopt WARN_CREATE_GLOBAL 16 | # setopt WARN_NESTED_VAR 17 | # setopt XTRACE 18 | 19 | autoload -Uz is-at-least && if ! is-at-least 5.2; then 20 | print -u2 -PR "${CI:+::error::}%F{1}${funcstack[1]##*/}:%f Running on Zsh version %B${ZSH_VERSION}%b, but Zsh %B5.2%b is the minimum supported version. Upgrade Zsh to fix this issue." 21 | exit 1 22 | fi 23 | 24 | TRAPEXIT() { 25 | local return_value=$? 26 | 27 | if (( ${+CI} )) { 28 | unset NSUnbufferedIO 29 | } 30 | 31 | return ${return_value} 32 | } 33 | 34 | TRAPZERR() { 35 | if (( ${_loglevel:-3} > 2 )) { 36 | print -u2 -PR "${CI:+::error::}%F{1} ✖︎ script execution error%f" 37 | print -PR -e " 38 | Callstack: 39 | ${(j:\n :)funcfiletrace} 40 | " 41 | } 42 | 43 | exit 2 44 | } 45 | 46 | package() { 47 | if (( ! ${+SCRIPT_HOME} )) typeset -g SCRIPT_HOME=${ZSH_ARGZERO:A:h} 48 | local host_os=${${(s:-:)ZSH_ARGZERO:t:r}[2]} 49 | local project_root=${SCRIPT_HOME:A:h:h} 50 | local buildspec_file=${project_root}/buildspec.json 51 | 52 | fpath=("${SCRIPT_HOME}/utils.zsh" ${fpath}) 53 | autoload -Uz set_loglevel log_info log_group log_error log_output check_${host_os} 54 | 55 | if [[ ! -r ${buildspec_file} ]] { 56 | log_error \ 57 | 'No buildspec.json found. Please create a build specification for your project.' 58 | return 2 59 | } 60 | 61 | local -i verbosity=1 62 | local -r _version='2.0.0' 63 | local -r -a _valid_targets=( 64 | macos-universal 65 | linux-x86_64 66 | ) 67 | local target 68 | local config='RelWithDebInfo' 69 | local -r -a _valid_configs=(Debug RelWithDebInfo Release MinSizeRel) 70 | local -i codesign=0 71 | local -i notarize=0 72 | local -i package=0 73 | local -i skip_deps=0 74 | 75 | if [[ ${host_os} == macos ]] { 76 | local -r _usage_host=" 77 | %F{yellow} Additional options for macOS builds%f 78 | ----------------------------------------------------------------------------- 79 | %B-s | --codesign%b Enable codesigning (macOS only) 80 | %B-n | --notarize%b Enable notarization (macOS only) 81 | %B-p | --package%b Create package installer (macOS only)" 82 | } 83 | 84 | local -r _usage=" 85 | Usage: %B${functrace[1]%:*}%b