AnythingLLM是使用大语言模型LLM的一站式轻便框架。官网的先容如下:
AnythingLLM is the easiest to use, all-in-one AI application that can do RAG, AI Agents, and much more with no code or infrastructure headaches.
1. 使用官方docker
最方便的方法是使用 docker. 参考Local Docker Installation ~ AnythingLLM
1.1 拉取镜像
- docker pull mintplexlabs/anythingllm
复制代码 1.2 创建db目录和设置文件
Linux:
- export STORAGE_LOCATION=/var/lib/anythingllm && \
- mkdir -p $STORAGE_LOCATION && \
- touch "$STORAGE_LOCATION/.env"
复制代码 Windows:
- $env:STORAGE_LOCATION="$HOME\Documents\anythingllm"; `
- If(!(Test-Path $env:STORAGE_LOCATION)) {New-Item $env:STORAGE_LOCATION -ItemType Directory}; `
- If(!(Test-Path "$env:STORAGE_LOCATION\.env")) {New-Item "$env:STORAGE_LOCATION\.env" -ItemType File};
复制代码 1.3 运行docker
- docker run -d \
- --name anythingllm \
- --add-host=host.docker.internal:host-gateway \
- --env STORAGE_DIR=/app/server/storage \
- --health-cmd "/bin/bash /usr/local/bin/docker-healthcheck.sh || exit 1" \
- --health-interval 60s \
- --health-start-period 60s \
- --health-timeout 10s \
- -p 3001:3001/tcp \
- --restart=always \
- --user anythingllm \
- -v ${STORAGE_LOCATION}:/app/server/storage \
- -v ${STORAGE_LOCATION}/.env:/app/server/.env \
- -w /app \
- mintplexlabs/anythingllm
复制代码 --add-host 设置是为了访问同台呆板上的ollama服务。
1.4 访问 http://localhost:3001 进行初始设置,最好设置团队,可以进行权限控制
可以设置大语言模型LLM、向量模型、向量数据库等等。
完成后查看 .env 文件,如下(因人而异):
- SERVER_PORT=3001
- JWT_SECRET="my-random-string-for-seeding" # Please generate random string at least 12 chars long.
- STORAGE_DIR="/var/lib/anything"
- OPEN_AI_KEY=""
- LLM_PROVIDER='ollama'
- OLLAMA_BASE_PATH='http://localhost:11434'
- OLLAMA_MODEL_PREF='llama3-64k:latest'
- OLLAMA_MODEL_TOKEN_LIMIT='4096'
- EMBEDDING_ENGINE='native'
- VECTOR_DB='lancedb'
复制代码 1.5 访问api
http://localhost:3001/api/docs/可以查看已有的API接口。
在设置里天生APIKEY,客户端编程通过这个Key来访问接口。
1.6 一个好用的小工具get_command_4_run_container,查看运行容器的启动命令参数
- docker pull cucker/get_command_4_run_container
复制代码- docker run --rm -v /var/run/docker.sock:/var/run/docker.sock cucker/get_command_4_run_container [容器名称]/[容器ID]
复制代码 2. 天生自己的docker镜像
如果想要有更多的自主和控制,好比加一些api接口。
2.1 下载代码
- git clone https://github.com/Mintplex-Labs/anything-llm.git
复制代码 2.2 Windows下天生镜像
进入代码目录anything-llm, 实行命令
- docker build -f ./docker/Dockerfile -t anythingllm:my_1.0 .
复制代码 如果中间超时报错了可以多跑频频,因为会访问github下载一些依赖的东西,而我们访问github是不稳定的, 如果你有署理服务就最好了。
2.3 Ubuntu下天生镜像
这里碰到不少问题,开始不管是用docker build还是docker-compose build都报错。
后来研究./docker/Dockerfile 文件才发现,它是支持多平台编译的。
为什么在Windows下没有问题呢,缘故原由是我Windows下用的是Docker Desktop,而它自带buildx工具,会自动识别当前系统平台。
2.3.1 安装工具buildx
下载:
- export BUILDX_VERSION=$(curl -s https://api.github.com/repos/docker/buildx/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
- curl -LO https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-amd64
复制代码 安装:
- mkdir -p ~/.docker/cli-plugins
- mv buildx-${BUILDX_VERSION}.linux-amd64 ~/.docker/cli-plugins/docker-buildx
- chmod +x ~/.docker/cli-plugins/docker-buildx
复制代码 查看版本号:
使用,这个工具也是个docker:
- docker buildx create --use
- docker buildx inspect --bootstrap
复制代码 2.3.2 天生镜像,使用buildx指定platform
- docker buildx build --platform linux/amd64 --build-arg ARG_UID=1000 --build-arg ARG_GID=1000 -f ./docker/Dockerfile -t anythingllm:my_1.0 --load --output type=docker .
复制代码 2.3.3 启动命令和上面的类似
a. 创建本地store目录
- mkdir /var/lib/anythingllm-my
复制代码 b. 创建db和env设置文件
- cd /var/lib/anythingllm-my
- mkdir logs
- touch anythingllm.db
- touch .env
- chown 1000:1000 /var/lib/anythingllm-my/ -R
复制代码 这里要留意的是肯定要给目录/var/lib/anythingllm-my修改owner(最后一条命令),不然docker启动会失败,报写readonly db的错误。
c. 启动docker,不发起用docker-compose,
- export STORAGE_LOCATION=/var/lib/anythingllm-my &&
- docker run -d \
- --name anythingllm-my \
- --add-host=host.docker.internal:host-gateway \
- --env STORAGE_DIR=/app/server/storage \
- -p 3001:3001/tcp \
- --restart=always \
- --user anythingllm \
- -v ${STORAGE_LOCATION}:/app/server/storage \
- -v ${STORAGE_LOCATION}/.env:/app/server/.env \
- -v ${STORAGE_LOCATION}/logs:/app/server/logs/ \
- -w /app \
- anythingllm:my_1.0
复制代码 修改了文件./docker/docker-entrypoint.sh如下,增长了输出服务端log:
- #!/bin/bash
- {
- cd /app/server/ &&
- npx prisma generate --schema=./prisma/schema.prisma &&
- npx prisma migrate deploy --schema=./prisma/schema.prisma &&
- node /app/server/index.js &> /app/server/logs/server.log
- } &
- { node /app/collector/index.js; } &
- wait -n
- exit $?
复制代码 3. 结束
有了自己的镜像,背面你可以自主修改代码了!!
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |