本地部署自托管的AI编码助手

有部分私有项目是不方便使用公网API或AI IDE来实时推理代码辅助生成的,之前一直使用ollama配合continue,模型Qwen-Coder-14B, 但continue现在商业感越来越浓,本地模型的部署配置也越藏越深。

换Tabby试试。

brew install tabbyml/tabby/tabby

下载模型并运行

tabby serve --device metal --model Qwen2.5-Coder-14B

打开web后台进行配置,完成后可以查看模型运行状态

重点来了,tabby还能自动部署 上下文提供者来增强大型语言模型的性能。

现在回到VSCode,安装扩展 tabby

生成速度和质量还不错,意图理解也准确。

配置好之后,将tabby以服务自启动, 先修改配置 code .tabby/config.toml

[model.completion.local]
model_id = "Qwen2.5-Coder-14B"

然后再运行

brew services start tabby

与ollama的区别:

ollama 拉取的模型,默认为Q4_K_M量化,模型大小9G
tabby 拉取的是Q8_0量化,模型大小15G

M2 Max 32G统一内存下都能流畅运行。

解决Trae在MacOS下开发C/C++的问题

VSCode下 C/C++插件是微软自己开发的,根据VSCode扩展商店政策,第三方Fork的VSCode项目是不允许使用的。

Trae下如果打开C/C++项目,默认会推荐安装ccls插件来支持。

Mac下使用还需要一点小改动。

首先通过brew安装ccls命令行

brew install ccls

自动安装ccls和它的依赖比如llvm

再次通过Trae打开项目,发现仍然找不到标准头文件。

打开终端,输入命令

clang++ -xc++ -fsyntax-only -v /dev/null

打印:

InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1"
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple arm64-apple-macosx15.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name null -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-strict-return -ffp-contract=on -fno-rounding-math -funwind-tables=1 -fobjc-msgsend-selector-stubs -target-sdk-version=15.4 -fvisibility-inlines-hidden-static-local-var -fdefine-target-os-macros -fno-assume-unique-vtables -fno-modulemap-allow-subdirectory-search -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8.5a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -target-abi darwinpcs -debugger-tuning=lldb -fdebug-compilation-dir=/Users/aliang -target-linker-version 1167.4.1 -v -fcoverage-compilation-dir=/Users/aliang -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -fdeprecated-macro -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-cxx-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcommon -fcolor-diagnostics -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -clang-vendor-feature=+disableAtImportPrivateFrameworkInImplementationError -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ /dev/null
clang -cc1 version 17.0.0 (clang-1700.0.13.3) default target arm64-apple-darwin24.4.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/SubFrameworks"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.

打开Trae,切换到扩展,点ccls的配置,点ccls.clang.extraArgs

根据前一个打印,修改这个值为:

  "ccls.clang.extraArgs": [
    "-isystem/usr/local/include",
    "-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1",
    "-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17/include",
    "-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
    "-isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
    "-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
  ],

重启Trae后,再点头文件,正常跳转

MacOS 从配置PHP开发环境到VSCode调试

来让我看看还有谁2024年了还在用PHP 🙂

Homebrew是必须的,没有的话先安装 Homebrew — The Missing Package Manager for macOS (or Linux)

由于我们需要用到redis xdebug等扩展,brew默认的php是不够的。配置以下两个tap

brew tap shivammathur/php
brew tap shivammathur/extensions

通过brew安装php@8.3 xdebug@8.3 redis@8.3

brew install shivammathur/php/php@8.3 shivammathur/extensions/xdebug@8.3 shivammathur/extensions/redis@8.3

Apple Silicon修改xdebug配置

/opt/homebrew/etc/php/8.3/conf.d/20-xdebug.ini

Intel 修改xdebug配置

/usr/local/etc/php/8.3/conf.d/20-xdebug.ini

添加内容

xdebug.mode = debug
xdebug.start_with_request = yes

此时运行 php artisan serve ,有以下打印则配置完成

Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).

接下来配置vscode

搜索并安装扩展 PHP Debug,开发者为Xdebug的。

打开PHP项目,切换到“运行与调试标签”,点创建launch.json文件,选 “PHP(Xdebug)”。
切换运行方式为 “Listen for Xdebug”,点运行。注意一定要先点调试运行后再启动项目。

这时候再执行php artisan serve,没有错误打印了,现在应该就能在源码中断点调试了。

没有最好的语言,只有最适合的,适合自己适合需求。

解决apple silicon vscode远程到一个amd64容器里无法安装扩展到问题

在M1/M2/M3的MacOS上运行amd64的容器,采用命令行

docker run -it --name ubuntu --platform linux/amd64 ubuntu:22.04 bash

进入容器后可以看到所有命令都是通过/run/rosetta/rosetta转译运行

如果需要通过vscode直接远程到容器内进行开发,目前版本1.88.1在容器内安装开发插件会失败,一直卡在扩展签名处,解决办法是:

修改remote的settings.json, 添加

"extensions.verifySignature": false

Xcode 15.1 在使用cocoapods时编译错误的问题

error: Sandbox: rsync.samba(20783) deny(1) file-read-data /Users/aliang/Library/Developer/Xcode/DerivedData/NodeMediaClient-iOSDemo-fppdzkiffmqafafcjxkmoahlcydy/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/NodeMediaClient/NodeMediaClient.framework/_CodeSignature (in target 'NodeMediaClient-iOSDemo' from project 'NodeMediaClient-iOSDemo')
error: Sandbox: rsync.samba(20784) deny(1) file-write-create /Users/aliang/Library/Developer/Xcode/DerivedData/NodeMediaClient-iOSDemo-fppdzkiffmqafafcjxkmoahlcydy/Build/Products/Debug-iphoneos/NodeMediaClient-iOSDemo.app/Frameworks/NodeMediaClient.framework/_CodeSignature (in target 'NodeMediaClient-iOSDemo' from project 'NodeMediaClient-iOSDemo')
error: Sandbox: rsync.samba(20783) deny(1) file-read-data /Users/aliang/Library/Developer/Xcode/DerivedData/NodeMediaClient-iOSDemo-fppdzkiffmqafafcjxkmoahlcydy/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/NodeMediaClient/NodeMediaClient.framework/Info.plist (in target 'NodeMediaClient-iOSDemo' from project 'NodeMediaClient-iOSDemo')
error: Sandbox: rsync.samba(20785) deny(1) file-write-create /Users/aliang/Library/Developer/Xcode/DerivedData/NodeMediaClient-iOSDemo-fppdzkiffmqafafcjxkmoahlcydy/Build/Products/Debug-iphoneos/NodeMediaClient-iOSDemo.app/Frameworks/NodeMediaClient.framework/.NodeMediaClient.3j4juc (in target 'NodeMediaClient-iOSDemo' from project 'NodeMediaClient-iOSDemo')

像这样的错误,那么解决方法是: 选择项目-> Build Settings->搜索sandbox,将一个名为 User Script Sandboxing 设置为No 再编译问题解决。

为CasaOS Docker环境下的jellyfin安装Tesla p4显卡加速

我的NAS使用E5处理器,由于没有编解码硬件加速,在用jellyfin播放h265 10bit HDR时会进行实时转码,cpu占用1800%,功耗150W。

Tesla P4这张卡现在价格来到300块,8G的显存,接近1060的3D性能,可以达到多路4K@60的编解码性能,非常适合。

我的NAS系统安装Debian12 CasaOS,这里记录下配置过程。

一、首先安装必要的包

apt install linux-headers-amd64 gcc make libvulkan1 pkg-config

二、初次运行驱动,会提示加载了开源驱动,问是否自动进行关闭,选yes,然后重启系统

./NVIDIA-Linux-x86_64-535.104.05-grid.run
继续阅读“为CasaOS Docker环境下的jellyfin安装Tesla p4显卡加速”

罗技C920使用嵌入式设备直播

今天需要给3D打印机装一个监控,正好有个C920和orangepi zero2闲置。

usb插入设备

root@orangepizero2:~# v4l2-ctl --list-devices
cedrus (platform:cedrus):
	/dev/video0
	/dev/media0

HD Pro Webcam C920 (usb-5200000.usb-1):
	/dev/video1
	/dev/video2
	/dev/media1

可以看到已识别到设备,由于这款C920摄像头内集成264编码,因此通过v4l是可以直接从摄像头取264视频的,那么直接开始直播。

继续阅读“罗技C920使用嵌入式设备直播”