├── img ├── demo.gif └── self.png ├── sample ├── Resources │ ├── add.png │ ├── del.png │ ├── eye.png │ ├── avatar.png │ ├── cancel.png │ ├── copy.png │ ├── edit.png │ ├── icon.aps │ ├── icon.icns │ ├── icon.ico │ ├── icon.png │ ├── left.png │ ├── pause.png │ ├── play.png │ ├── resource.h │ ├── right.png │ ├── send.png │ ├── Mao │ │ ├── Mao.moc3 │ │ ├── Mao.2048 │ │ │ └── texture_00.png │ │ ├── Mao.pose3.json │ │ ├── Mao.model3.json │ │ └── expressions │ │ │ ├── exp_01.exp3.json │ │ │ ├── exp_05.exp3.json │ │ │ ├── exp_06.exp3.json │ │ │ ├── exp_08.exp3.json │ │ │ ├── exp_02.exp3.json │ │ │ ├── exp_03.exp3.json │ │ │ ├── exp_04.exp3.json │ │ │ └── exp_07.exp3.json │ ├── message.png │ ├── font │ │ └── default.otf │ ├── default avatar.png │ ├── PythonScripts │ │ └── getInstalledPackage.py │ ├── dll_search_paths.props │ ├── Plugins │ │ └── Test │ │ │ └── Plugin.lua │ ├── Info.plist │ ├── Info.rc │ ├── RCa15684 │ └── Chatbot.manifest ├── Vendor │ ├── llava │ │ ├── requirements.txt │ │ ├── android │ │ │ ├── build_64.sh │ │ │ └── adb_run.sh │ │ ├── glmedge-surgery.py │ │ ├── llava_surgery.py │ │ ├── README-glmedge.md │ │ ├── clip-quantize-cli.cpp │ │ ├── llava.h │ │ ├── minicpmv-surgery.py │ │ ├── README-minicpmo2.6.md │ │ ├── README-quantize.md │ │ ├── CMakeLists.txt │ │ ├── clip.h │ │ ├── README-minicpmv2.5.md │ │ ├── README-minicpmv2.6.md │ │ ├── README.md │ │ ├── qwen2_vl_surgery.py │ │ ├── llava_surgery_v2.py │ │ └── glmedge-convert-image-encoder-to-gguf.py │ └── CMakeLists.txt ├── vcpkg-configuration.json ├── vcpkg.json ├── main.cpp ├── SystemRole.h └── CMakeLists.txt ├── src ├── stb_image.cpp ├── stb_image_resize.cpp ├── stb_image_wirte.cpp ├── ChatBot.cpp ├── Logger.cpp ├── StableDiffusion.cpp ├── Translate.cpp ├── VoiceToText.cpp ├── AES_Crypto.cpp ├── Recorder.cpp └── base64.cpp ├── include ├── Impls │ ├── Bots.h │ ├── Gemini_Impl.h │ ├── CustomRule_Impl.h │ ├── LLama_Impl.h │ ├── Claude_Impl.h │ └── ChatGPT_Impl.h ├── Translate.h ├── StableDiffusion.h ├── VoiceToText.h ├── AES_Crypto.h ├── base64.h ├── pch.h ├── Script.h ├── Logger.h ├── Recorder.h ├── Progress.hpp ├── ChatBot.h └── Downloader.h ├── .gitignore ├── .gitmodules ├── README.md └── READEME_EN.md /img/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/img/demo.gif -------------------------------------------------------------------------------- /img/self.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/img/self.png -------------------------------------------------------------------------------- /sample/Resources/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/add.png -------------------------------------------------------------------------------- /sample/Resources/del.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/del.png -------------------------------------------------------------------------------- /sample/Resources/eye.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/eye.png -------------------------------------------------------------------------------- /sample/Resources/avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/avatar.png -------------------------------------------------------------------------------- /sample/Resources/cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/cancel.png -------------------------------------------------------------------------------- /sample/Resources/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/copy.png -------------------------------------------------------------------------------- /sample/Resources/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/edit.png -------------------------------------------------------------------------------- /sample/Resources/icon.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/icon.aps -------------------------------------------------------------------------------- /sample/Resources/icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/icon.icns -------------------------------------------------------------------------------- /sample/Resources/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/icon.ico -------------------------------------------------------------------------------- /sample/Resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/icon.png -------------------------------------------------------------------------------- /sample/Resources/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/left.png -------------------------------------------------------------------------------- /sample/Resources/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/pause.png -------------------------------------------------------------------------------- /sample/Resources/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/play.png -------------------------------------------------------------------------------- /sample/Resources/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/resource.h -------------------------------------------------------------------------------- /sample/Resources/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/right.png -------------------------------------------------------------------------------- /sample/Resources/send.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/send.png -------------------------------------------------------------------------------- /src/stb_image.cpp: -------------------------------------------------------------------------------- 1 | // std_image.cpp 2 | #define STB_IMAGE_IMPLEMENTATION 3 | #include "stb_image.h" -------------------------------------------------------------------------------- /src/stb_image_resize.cpp: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_RESIZE_IMPLEMENTATION 2 | 3 | #include "stb_image_resize.h" -------------------------------------------------------------------------------- /src/stb_image_wirte.cpp: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_WRITE_IMPLEMENTATION 2 | 3 | #include "stb_image_write.h" -------------------------------------------------------------------------------- /sample/Resources/Mao/Mao.moc3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/Mao/Mao.moc3 -------------------------------------------------------------------------------- /sample/Resources/message.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/message.png -------------------------------------------------------------------------------- /sample/Resources/font/default.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/font/default.otf -------------------------------------------------------------------------------- /sample/Resources/default avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/default avatar.png -------------------------------------------------------------------------------- /sample/Resources/Mao/Mao.2048/texture_00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NGLSG/ChatBot/HEAD/sample/Resources/Mao/Mao.2048/texture_00.png -------------------------------------------------------------------------------- /sample/Vendor/llava/requirements.txt: -------------------------------------------------------------------------------- 1 | -r ../../requirements/requirements-convert_legacy_llama.txt 2 | --extra-index-url https://download.pytorch.org/whl/cpu 3 | pillow~=10.2.0 4 | torch~=2.2.1 5 | torchvision~=0.17.1 6 | -------------------------------------------------------------------------------- /include/Impls/Bots.h: -------------------------------------------------------------------------------- 1 | #ifndef BOTS_H 2 | #define BOTS_H 3 | #include "ChatGPT_Impl.h" 4 | #include "Claude_Impl.h" 5 | #include "Gemini_Impl.h" 6 | #include "LLama_Impl.h" 7 | #include "CustomRule_Impl.h" 8 | #endif //BOTS_H 9 | -------------------------------------------------------------------------------- /sample/Vendor/llava/android/build_64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cmake ../../../../ \ 3 | -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ 4 | -DCMAKE_BUILD_TYPE=Release \ 5 | -DANDROID_ABI="arm64-v8a" \ 6 | -DANDROID_PLATFORM=android-23 $1 7 | 8 | make -j4 9 | -------------------------------------------------------------------------------- /src/ChatBot.cpp: -------------------------------------------------------------------------------- 1 | #include "ChatBot.h" 2 | 3 | static inline void TrimLeading(std::string& s) 4 | { 5 | size_t pos = 0; 6 | while (pos < s.size() && std::isspace(static_cast(s[pos]))) 7 | pos++; 8 | if (pos > 0) 9 | s.erase(0, pos); 10 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | cmake-build*/ 10 | 11 | # 忽略IDE的配置文件 12 | .idea/ 13 | .vscode/ 14 | build/ 15 | 16 | # 17 | *.zip -------------------------------------------------------------------------------- /sample/Resources/PythonScripts/getInstalledPackage.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import importlib.metadata 3 | 4 | 5 | def get_installed_packages(): 6 | # 获取所有已安装的包 7 | installed_packages = [dist.metadata['Name'] for dist in importlib.metadata.distributions()] 8 | return installed_packages 9 | 10 | 11 | print(get_installed_packages()) 12 | -------------------------------------------------------------------------------- /sample/Resources/Mao/Mao.pose3.json: -------------------------------------------------------------------------------- 1 | { 2 | "Type": "Live2D Pose", 3 | "Groups": [ 4 | [ 5 | { 6 | "Id": "PartArmLA", 7 | "Link": [] 8 | }, 9 | { 10 | "Id": "PartArmLB", 11 | "Link": [] 12 | } 13 | ], 14 | [ 15 | { 16 | "Id": "PartArmRA", 17 | "Link": [] 18 | }, 19 | { 20 | "Id": "PartArmRB", 21 | "Link": [] 22 | } 23 | ] 24 | ] 25 | } -------------------------------------------------------------------------------- /sample/Resources/dll_search_paths.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /DEPENDENTLOADFLAG:0x800 /DELAYLOAD:*.dll %(AdditionalOptions) 6 | 7 | 8 | -------------------------------------------------------------------------------- /include/Translate.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSLATE_H 2 | #define TRANSLATE_H 3 | #include "utils.h" 4 | 5 | class Translate { 6 | public : 7 | Translate(const TranslateData &data); 8 | 9 | std::string translate(std::string originText, std::string destLanguage = "en", std::string originLanguage = "auto"); 10 | 11 | private: 12 | TranslateData _data; 13 | cpr::Session session; 14 | }; 15 | 16 | #endif -------------------------------------------------------------------------------- /sample/vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "default-registry": { 3 | "kind": "git", 4 | "baseline": "6220088b956e4e4c7de27fb5f5eff8c9745cb4c8", 5 | "repository": "https://github.com/microsoft/vcpkg" 6 | }, 7 | "registries": [ 8 | { 9 | "kind": "artifact", 10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", 11 | "name": "microsoft" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sample/Vendor/spdlog"] 2 | path = sample/Vendor/spdlog 3 | url = https://github.com/gabime/spdlog.git 4 | [submodule "Vendor/libarchive"] 5 | path = sample/Vendor/libarchive 6 | url = https://github.com/libarchive/libarchive 7 | [submodule "sample/Vendor/libarchive"] 8 | path = sample/Vendor/libarchive 9 | url = https://github.com/libarchive/libarchive 10 | [submodule "sample/Vendor/imgui"] 11 | path = sample/Vendor/imgui 12 | url = https://github.com/ocornut/imgui.git 13 | branch = docking 14 | -------------------------------------------------------------------------------- /include/StableDiffusion.h: -------------------------------------------------------------------------------- 1 | #ifndef STABLEDIFFUSION_H 2 | #define STABLEDIFFUSION_H 3 | 4 | #include "utils.h" 5 | 6 | class StableDiffusion { 7 | public : 8 | const std::string ResPath = "Resources/Images/"; 9 | 10 | StableDiffusion(StableDiffusionData data); 11 | 12 | std::string Text2Img(std::string prompt, std::string negative_prompt=""); 13 | StableDiffusionData _data; 14 | private: 15 | 16 | const int _maxSize = 256; 17 | std::string t2iurl; 18 | }; 19 | 20 | 21 | #endif //STABLEDIFFUSION_H 22 | -------------------------------------------------------------------------------- /include/VoiceToText.h: -------------------------------------------------------------------------------- 1 | #ifndef VOICETOTEXT_H 2 | #define VOICETOTEXT_H 3 | 4 | #include "utils.h" 5 | 6 | using json = nlohmann::json; 7 | 8 | 9 | class VoiceToText { 10 | public: 11 | VoiceToText(const OpenAIBotCreateInfo &voiceData); 12 | 13 | std::string Convert(std::string voicePath); 14 | 15 | json sendRequest(std::string data); 16 | 17 | std::future ConvertAsync(std::string voicePath); 18 | 19 | private: 20 | cpr::Session session; 21 | OpenAIBotCreateInfo _voiceData; 22 | }; 23 | 24 | #endif -------------------------------------------------------------------------------- /sample/Resources/Plugins/Test/Plugin.lua: -------------------------------------------------------------------------------- 1 | -- Called when the plugin is loaded 2 | function Initialize() 3 | print("Plugin Test") 4 | end 5 | 6 | -- Call each frame 7 | function UIRenderer() 8 | UIBegin("Lua") 9 | UIText("Hello, World!") 10 | UIEnd() 11 | end 12 | 13 | -- Called when a chat message is received 14 | function OnChat(message) 15 | if type(message) ~= "string" then 16 | error("Expected a string as parameter") 17 | end 18 | print("Received: " .. message) 19 | return message 20 | end 21 | 22 | -- Call before UIRenderer 23 | function PreRenderer() 24 | print("PreRender") 25 | end -------------------------------------------------------------------------------- /sample/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies" : [ "libsndfile", "nlohmann-json", "opengl", "portaudio", "vulkan", { 3 | "name" : "glfw3", 4 | "version>=" : "3.4#1" 5 | }, { 6 | "name" : "yaml-cpp", 7 | "version>=" : "0.8.0#1" 8 | }, { 9 | "name" : "sol2", 10 | "version>=" : "3.3.1" 11 | }, { 12 | "name" : "lua", 13 | "version>=" : "5.4.7" 14 | }, { 15 | "name" : "sdl2", 16 | "version>=" : "2.30.11" 17 | }, { 18 | "name" : "sdl2-image", 19 | "version>=" : "2.8.4" 20 | }, { 21 | "name" : "openssl", 22 | "version>=" : "3.4.0#1" 23 | }, { 24 | "name" : "cpr", 25 | "version>=" : "1.11.1" 26 | }, { 27 | "name" : "glad", 28 | "version>=" : "0.1.36" 29 | } ] 30 | } -------------------------------------------------------------------------------- /include/AES_Crypto.h: -------------------------------------------------------------------------------- 1 | #ifndef SECURE_AES_H 2 | #define SECURE_AES_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class SecureAES { 11 | public: 12 | static void X1(); 13 | static void X2(); 14 | static std::vector X3(const std::string& X4); 15 | static std::string X5(const std::vector& X6); 16 | static std::string X7(const std::vector& X8); 17 | static std::vector X9(const std::string& X10); 18 | 19 | private: 20 | static std::vector X11(); 21 | static std::vector X12(const std::vector& X13, std::vector& X14); 22 | static std::vector X15(const std::vector& X16, const std::vector& X17); 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /sample/Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CFBundleDisplayName 7 | CyberGirl 8 | CFBundleExecutable 9 | CyberGirl 10 | CFBundleIdentifier 11 | com.gezhi.cybergirl 12 | CFBundleInfoDictionaryVersion 13 | 6.0 14 | CFBundleName 15 | CyberGirl 16 | CFBundlePackageType 17 | APPL 18 | CFBundleShortVersionString 19 | v1.0 20 | CFBundleVersion 21 | v1.0 22 | CFBundleIconFile 23 | icon.icns 24 | CFBundleGetInfoString 25 | CyberGirl 26 | CFBundleDevelopmentRegion 27 | zh 28 | 29 | 30 | -------------------------------------------------------------------------------- /sample/Vendor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(libs) 2 | add_library(libs INTERFACE) 3 | 4 | find_package(OpenGL REQUIRED) 5 | find_package(glad REQUIRED) 6 | find_package(Vulkan REQUIRED) 7 | find_package(SDL2 CONFIG REQUIRED) 8 | find_package(SDL2_image CONFIG REQUIRED) 9 | find_package(glfw3 CONFIG REQUIRED) 10 | 11 | project(ImGUI) 12 | file(GLOB IMGUI_SOURCES ./imgui/*.cpp ./imgui/*.h ./imgui/backends/imgui_impl_opengl3.* ./imgui/backends/imgui_impl_glfw.* ./imgui/backends/imgui_impl_sdl2.* ./imgui/backends/imgui_impl_vulkan.*) 13 | add_library(ImGUI STATIC 14 | ${IMGUI_SOURCES} 15 | ) 16 | target_link_libraries(ImGUI PUBLIC OpenGL::GL glad::glad glfw ${Vulkan_LIBRARIES} 17 | $ 18 | $,SDL2::SDL2,SDL2::SDL2-static> 19 | $,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static> 20 | ) 21 | target_include_directories(ImGUI PUBLIC ./imgui ./imgui/backends ${Vulkan_INCLUDE_DIRS}) 22 | -------------------------------------------------------------------------------- /sample/Resources/Info.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON "icon.ico" 2 | 3 | #include "winver.h" 4 | VS_VERSION_INFO VERSIONINFO 5 | FILEVERSION 1,0,0,1 6 | PRODUCTVERSION 1,0,0,1 7 | FILEFLAGSMASK 0x3fL 8 | #ifdef _DEBUG 9 | FILEFLAGS 0x1L 10 | #else 11 | FILEFLAGS 0x0L 12 | #endif 13 | FILEOS 0x40004L 14 | FILETYPE 0x0L 15 | FILESUBTYPE 0x0L 16 | BEGIN 17 | BLOCK "StringFileInfo" 18 | BEGIN 19 | BLOCK "080404b0" 20 | BEGIN 21 | VALUE "CompanyName", "Artiverse Studio" 22 | VALUE "FileDescription", "" 23 | VALUE "FileVersion", "2.0.0.1" 24 | VALUE "InternalName", "Chatbot.exe" 25 | VALUE "LegalCopyright", "Copyright (C) 2025 Artiverse Studio" 26 | VALUE "OriginalFilename", "Chatbot.exe" 27 | VALUE "ProductName", "" 28 | VALUE "ProductVersion", "2.0.0.1" 29 | END 30 | END 31 | BLOCK "VarFileInfo" 32 | BEGIN 33 | VALUE "Translation", 0x804, 1200 34 | END 35 | END -------------------------------------------------------------------------------- /include/base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // base64 encoding and decoding with C++. 3 | // Version: 2.rc.09 (release candidate) 4 | // 5 | 6 | #ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A 7 | #define BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A 8 | 9 | #include 10 | 11 | #if __cplusplus >= 201703L 12 | #include 13 | #endif // __cplusplus >= 201703L 14 | 15 | std::string base64_encode (std::string const& s, bool url = false); 16 | std::string base64_encode_pem (std::string const& s); 17 | std::string base64_encode_mime(std::string const& s); 18 | 19 | std::string base64_decode(std::string const& s, bool remove_linebreaks = false); 20 | std::string base64_encode(unsigned char const*, size_t len, bool url = false); 21 | 22 | #if __cplusplus >= 201703L 23 | // 24 | // Interface with std::string_view rather than const std::string& 25 | // Requires C++17 26 | // Provided by Yannic Bonenberger (https://github.com/Yannic) 27 | // 28 | std::string base64_encode (std::string_view s, bool url = false); 29 | std::string base64_encode_pem (std::string_view s); 30 | std::string base64_encode_mime(std::string_view s); 31 | 32 | std::string base64_decode(std::string_view s, bool remove_linebreaks = false); 33 | #endif // __cplusplus >= 201703L 34 | 35 | #endif /* BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A */ 36 | -------------------------------------------------------------------------------- /sample/Vendor/llava/glmedge-surgery.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | import torch 4 | from transformers import AutoModel 5 | 6 | ap = argparse.ArgumentParser() 7 | ap.add_argument("-m", "--model", help="Path to GLM model") 8 | args = ap.parse_args() 9 | 10 | # find the model part that includes the the multimodal projector weights 11 | model = AutoModel.from_pretrained(args.model, trust_remote_code=True, local_files_only=True) 12 | checkpoint = model.state_dict() 13 | 14 | # get a list of mm tensor names 15 | mm_tensors = [k for k, v in checkpoint.items() if k.startswith("vision.adapter.")] 16 | 17 | # store these tensors in a new dictionary and torch.save them 18 | projector = {name: checkpoint[name].float() for name in mm_tensors} 19 | torch.save(projector, f"{args.model}/glm.projector") 20 | 21 | clip_tensors = [k for k, v in checkpoint.items() if k.startswith("vision.vit.model.vision_model.")] 22 | if len(clip_tensors) > 0: 23 | clip = {name.replace("vision.vit.model.", ""): checkpoint[name].float() for name in clip_tensors} 24 | torch.save(clip, f"{args.model}/glm.clip") 25 | 26 | # added tokens should be removed to be able to convert Mistral models 27 | if os.path.exists(f"{args.model}/added_tokens.json"): 28 | with open(f"{args.model}/added_tokens.json", "w") as f: 29 | f.write("{}\n") 30 | 31 | print("Done!") 32 | print(f"Now you can convert {args.model} to a regular LLaMA GGUF file.") 33 | print(f"Also, use {args.model}glm.projector to prepare a glm-encoder.gguf file.") 34 | -------------------------------------------------------------------------------- /sample/Vendor/llava/llava_surgery.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import glob 3 | import os 4 | import torch 5 | 6 | 7 | ap = argparse.ArgumentParser() 8 | ap.add_argument("-m", "--model", help="Path to LLaVA v1.5 model") 9 | args = ap.parse_args() 10 | 11 | # find the model part that includes the the multimodal projector weights 12 | path = sorted(glob.glob(f"{args.model}/pytorch_model*.bin"))[-1] 13 | checkpoint = torch.load(path) 14 | 15 | # get a list of mm tensor names 16 | mm_tensors = [k for k, v in checkpoint.items() if k.startswith("model.mm_projector")] 17 | 18 | # store these tensors in a new dictionary and torch.save them 19 | projector = {name: checkpoint[name].float() for name in mm_tensors} 20 | torch.save(projector, f"{args.model}/llava.projector") 21 | 22 | # BakLLaVA models contain CLIP tensors in it 23 | clip_tensors = [k for k, v in checkpoint.items() if k.startswith("model.vision_tower")] 24 | if len(clip_tensors) > 0: 25 | clip = {name.replace("vision_tower.vision_tower.", ""): checkpoint[name].float() for name in clip_tensors} 26 | torch.save(clip, f"{args.model}/llava.clip") 27 | 28 | 29 | # added tokens should be removed to be able to convert Mistral models 30 | if os.path.exists(f"{args.model}/added_tokens.json"): 31 | with open(f"{args.model}/added_tokens.json", "w") as f: 32 | f.write("{}\n") 33 | 34 | 35 | 36 | print("Done!") 37 | print(f"Now you can convert {args.model} to a regular LLaMA GGUF file.") 38 | print(f"Also, use {args.model}/llava.projector to prepare a llava-encoder.gguf file.") 39 | -------------------------------------------------------------------------------- /include/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef PCH_H 3 | #define PCH_H 4 | 5 | #include 6 | //#include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #define FRAMES_PER_BUFFER (1024) 24 | const int kMaxThreads = 10; // 最大线程数 25 | const int kBlockSize = 1024 * 1024; // 每个块的大小 26 | const int kRetryTimes = 3; // 下载失败的重试次数 27 | 28 | typedef struct { 29 | float* buffer; 30 | int bufferSize; 31 | int readIndex; 32 | } paUserData; 33 | 34 | 35 | template 36 | T Min(T a, T b) { 37 | return a < b ? a : b; 38 | } 39 | 40 | template 41 | T Max(T a, T b) { 42 | return a > b ? a : b; 43 | } 44 | 45 | template 46 | using Scope = std::unique_ptr; 47 | 48 | template 49 | constexpr Scope CreateScope(Args&&... args) { 50 | return std::make_unique(std::forward(args)...); 51 | } 52 | 53 | template 54 | using Ref = std::shared_ptr; 55 | 56 | template 57 | constexpr Ref CreateRef(Args&&... args) { 58 | return std::make_shared(std::forward(args)...); 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /include/Script.h: -------------------------------------------------------------------------------- 1 | #ifndef SCRIPTINTERPRETER_H 2 | #define SCRIPTINTERPRETER_H 3 | 4 | #include 5 | 6 | class Script { 7 | public: 8 | friend class ScriptManager; 9 | 10 | Script(); 11 | 12 | ~Script(); 13 | 14 | bool Initialize(std::string scriptsPath); 15 | 16 | sol::protected_function getFunction(const std::string&funcName); 17 | 18 | template 19 | sol::object Invoke(const std::string&funcName, Args&&... args); 20 | 21 | bool checkFunc(const std::string&funcName); 22 | 23 | void PrintAllFunctions(); 24 | 25 | static std::shared_ptr