🖼️ Model gallery
🖼️ Model gallery
模型库是一个由 LocalAI 精选的模型配置集合,它允许用户直接从 LocalAI Web 界面一键安装模型。
可在 Public LocalAI Gallery 浏览可用的模型列表。
LocalAI 提供了一种在启动时预加载模型以及在运行时下载和安装模型的方法,以简化模型的安装。您可以通过复制到 models 目录手动安装模型,或者使用 API 或 Web 界面来配置、下载和验证模型资产。
有用链接和资源
- Open LLM Leaderboard - 在这里您可以找到在 Open LLM 基准测试中表现最出色的模型列表。请记住,与 LocalAI 兼容的模型必须量化为
gguf格式。
工作原理
在顶部导航栏的 "Models" 部分导航到 WebUI 界面。在这里您可以找到可以安装的模型列表,点击 "Install" 按钮即可安装它们。
添加其他画廊
您可以通过设置 GALLERIES 环境变量来添加其他画廊。GALLERIES 环境变量是一个 JSON 对象列表,其中每个对象都有一个 name 和一个 url 字段。name 字段是画廊的名称,url 字段是画廊索引文件的 URL,例如:
GALLERIES=[{"name":"<GALLERY_NAME>", "url":"<GALLERY_URL"}]画廊中的模型将被自动索引并可用于安装。
API 参考文档
模型仓库
您可以在运行时安装模型,即 API 正在运行且已启动后,或者在启动 API 之前通过预加载模型。
要在运行时安装模型,您需要使用 /models/apply LocalAI API 端点。
默认情况下,LocalAI 配置了 localai 仓库。
要使用其他仓库,您需要使用 GALLERIES 环境变量启动 local-ai:
GALLERIES=[{"name":"<GALLERY_NAME>", "url":"<GALLERY_URL"}]例如,要启用默认的 localai 仓库,您可以这样启动 local-ai:
GALLERIES=[{"name":"localai", "url":"github:mudler/localai/gallery/index.yaml"}]其中 github:mudler/localai/gallery/index.yaml 将自动展开为 https://raw.githubusercontent.com/mudler/LocalAI/main/index.yaml。
注意:对于 github 和 huggingface,URL 会自动展开,但也可以使用 https:// 和 http:// 前缀。
列出模型
要列出所有可用模型,请使用 /models/available 端点:
curl http://localhost:8080/models/available要搜索模型,您可以使用 jq:
# 获取包含 "replit" 名称的所有模型的信息
curl http://localhost:8080/models/available | jq '.[] | select(.name | contains("replit"))'
# 获取所有本地模型(不在 Hugging Face 上托管)的二进制名称
curl http://localhost:8080/models/available | jq '.[] | .name | select(contains("localmodels"))'
# 获取所有包含 "orca" 的模型 URL
curl http://localhost:8080/models/available | jq '.[] | .urls | select(. != null) | add | select(contains("orca"))'如何从仓库安装模型
可以通过传递 YAML 配置文件的全 URL 或者在画廊中的模型标识符来安装模型。画廊是一个可以传递模型名称来安装的模型仓库。
要从画廊仓库安装模型,可以在 id 字段中传递模型名称。例如,要安装 bert-embeddings 模型,您可以使用以下命令:
LOCALAI=http://localhost:8080
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"id": "localai@bert-embeddings"
}'其中:
localai是仓库,它是可选的,可以被省略。如果省略仓库,LocalAI 将在所有仓库中按名称搜索模型。如果两个画廊中都有相同的模型名称,则第一个匹配项获胜。bert-embeddings是画廊中的模型名称(阅读其 配置文件)。
如何安装非画廊中的模型
如果您不希望设置任何画廊仓库,仍然可以通过加载模型配置文件来安装模型。
在请求正文中,您必须指定模型配置文件 URL (url),可选的模型安装名称 (name),要安装的额外文件 (files) 以及配置覆盖 (overrides)。调用 API 端点时,LocalAI 将下载模型文件并将配置写入用于存储模型的文件夹。
LOCALAI=http://localhost:8080
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"config_url": "<MODEL_CONFIG_FILE_URL>"
}'
# 或者如果来自仓库
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"id": "<GALLERY>@<MODEL_NAME>"
}'
# 或者来自画廊配置
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "<MODEL_CONFIG_FILE_URL>"
}'安装 hermes-2-pro-mistral 的一个示例可能是:
LOCALAI=http://localhost:8080
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"config_url": "https://raw.githubusercontent.com/mudler/LocalAI/v2.25.0/embedded/models/hermes-2-pro-mistral.yaml"
}'API 将返回一个 uuid,您可以用它来跟踪工作进度:
{"uuid":"1059474d-f4f9-11ed-8d99-c4cbe106d571","status":"http://localhost:8080/models/jobs/1059474d-f4f9-11ed-8d99-c4cbe106d571"}例如,一个等待工作完成的小型示例 bash 脚本(需要 jq):
response=$(curl -s http://localhost:8080/models/apply -H "Content-Type: application/json" -d '{"url": "$model_url"}')
job_id=$(echo "$response" | jq -r '.uuid')
while [ "$(curl -s http://localhost:8080/models/jobs/"$job_id" | jq -r '.processed')" != "true" ]; do
sleep 1
done
echo "Job completed"要在启动时预加载模型,您可以使用 PRELOAD_MODELS 环境变量。
要在启动时预加载模型,通过设置 PRELOAD_MODELS 环境变量为模型 URI 的 JSON 数组:
PRELOAD_MODELS='[{"url": "<MODEL_URL>"}]'注意:必须指定 url 或 id。url 用于指向模型画廊配置的 URL,而 id 用于引用仓库中的模型。如果两者都指定,将使用 id。
例如:
PRELOAD_MODELS=[{"url": "github:mudler/LocalAI/gallery/stablediffusion.yaml@master"}]或者作为参数:
local-ai --preload-models '[{"url": "github:mudler/LocalAI/gallery/stablediffusion.yaml@master"}]'或者在 YAML 文件中:
local-ai --preload-models-config "/path/to/yaml"YAML:
- url: github:mudler/LocalAI/gallery/stablediffusion.yaml@master您可以在 LocalAI 画廊 中找到一些已开放的许可模型。
如果在画廊中找不到模型,可以尝试使用 "base" 模型并提供一个 URL 给 LocalAI:
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "github:mudler/LocalAI/gallery/base.yaml@master",
"name": "model-name",
"files": [
{
"uri": "<URL>",
"sha256": "<SHA>",
"filename": "model"
}
]
}'重命名模型
要在安装模型时指定不同的名称,请在请求正文中指定 name 参数。
LOCALAI=http://localhost:8080
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "<MODEL_CONFIG_FILE>",
"name": "<MODEL_NAME>"
}'例如,要将模型安装为 gpt-3.5-turbo:
LOCALAI=http://localhost:8080
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "github:mudler/LocalAI/gallery/gpt4all-j.yaml",
"name": "gpt-3.5-turbo"
}'额外文件
要下载模型的额外文件,请使用 files 参数:
LOCALAI=http://localhost:8080
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "<MODEL_CONFIG_FILE>",
"name": "<MODEL_NAME>",
"files": [
{
"uri": "<additional_file_url>",
"sha256": "<additional_file_hash>",
"filename": "<additional_file_name>"
}
]
}'覆盖配置文件
要覆盖配置文件的部分内容,如后端或模型文件,请使用 overrides 参数:
LOCALAI=http://localhost:8080
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "<MODEL_CONFIG_FILE>",
"name": "model-name",
"overrides": {
"backend": "new-backend",
"model": "new-model-file"
}
}'嵌入:Bert
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"id": "bert-embeddings",
"name": "text-embedding-ada-002"
}'测试:
LOCALAI=http://localhost:8080
curl $LOCALAI/v1/embeddings -H "Content-Type: application/json" -d '{
"input": "Test",
"model": "text-embedding-ada-002"
}'图像生成:Stable diffusion
URL: https://github.com/EdVince/Stable-Diffusion-NCNN
准备运行时模型
在API运行时,您可以使用 /models/apply 端点并指向 models-gallery 中的 stablediffusion 模型:
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "github:mudler/LocalAI/gallery/stablediffusion.yaml@master"
}'启动前自动准备模型
您可以设置 PRELOAD_MODELS 环境变量:
PRELOAD_MODELS=[{"url": "github:mudler/LocalAI/gallery/stablediffusion.yaml@master"}]或者作为参数:
local-ai --preload-models '[{"url": "github:mudler/LocalAI/gallery/stablediffusion.yaml@master"}]'或者在YAML文件中:
local-ai --preload-models-config "/path/to/yaml"YAML:
- url: github:mudler/LocalAI/gallery/stablediffusion.yaml@master测试:
curl $LOCALAI/v1/images/generations -H "Content-Type: application/json" -d '{
"prompt": "floating hair, portrait, ((loli)), ((one girl)), cute face, hidden hands, asymmetrical bangs, beautiful detailed eyes, eye shadow, hair ornament, ribbons, bowties, buttons, pleated skirt, (((masterpiece))), ((best quality)), colorful|((part of the head)), ((((mutated hands and fingers)))), deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, extra limb, ugly, poorly drawn hands, missing limb, blurry, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, Octane renderer, lowres, bad anatomy, bad hands, text",
"mode": 2, "seed":9000,
"size": "256x256", "n":2
}'音频转录:Whisper
URL: https://github.com/ggerganov/whisper.cpp
准备运行时模型
curl $LOCALAI/models/apply -H "Content-Type: application/json" -d '{
"url": "github:mudler/LocalAI/gallery/whisper-base.yaml@master",
"name": "whisper-1"
}'启动前自动准备模型
您可以设置 PRELOAD_MODELS 环境变量:
PRELOAD_MODELS=[{"url": "github:mudler/LocalAI/gallery/whisper-base.yaml@master", "name": "whisper-1"}]或者作为参数:
local-ai --preload-models '[{"url": "github:mudler/LocalAI/gallery/whisper-base.yaml@master", "name": "whisper-1"}]'或者在YAML文件中:
local-ai --preload-models-config "/path/to/yaml"YAML:
- url: github:mudler/LocalAI/gallery/whisper-base.yaml@master
name: whisper-1注意
LocalAI 会创建一个批处理过程,从模型定义中下载所需的文件并自动重新加载以包含新模型。
输入:url 或 id(必填),name(可选),files(可选)
curl http://localhost:8080/models/apply -H "Content-Type: application/json" -d '{
"url": "<MODEL_DEFINITION_URL>",
"id": "<GALLERY>@<MODEL_NAME>",
"name": "<INSTALLED_MODEL_NAME>",
"files": [
{
"uri": "<additional_file>",
"sha256": "<additional_file_hash>",
"filename": "<additional_file_name>"
},
"overrides": { "backend": "...", "f16": true }
]
}可选的,可以在 files 中指定要下载的附加文件列表。name 允许覆盖模型名称。最后,可以使用 override 覆盖模型配置文件。
url 是完整的URL,或者是github URL(github:org/repo/file.yaml),或者是本地文件(file:///path/to/file.yaml)。id 是形式为 <GALLERY>@<MODEL_NAME> 的字符串,其中 <GALLERY> 是图库的名称,<MODEL_NAME> 是图库中的模型名称。图库可以在启动时使用 GALLERIES 环境变量指定。
返回一个 uuid 和一个 url 来跟踪进程的状态:
{ "uuid":"251475c9-f666-11ed-95e0-9a8a4480ac58", "status":"http://localhost:8080/models/jobs/251475c9-f666-11ed-95e0-9a8a4480ac58"}要查看经过策划的模型定义文件集合示例,请查看 LocalAI 存储库。
获取模型作业状态 /models/jobs/<uid>
此端点返回与模型安装相关联的批处理作业的状态。
curl http://localhost:8080/models/jobs/<JOB_ID>返回包含错误和作业是否正在处理的json:
{"error":null,"processed":true,"message":"completed"}