自定义模型
2025年2月22日大约 2 分钟
自定义模型
要自定义提示模板或模型的默认设置,需要使用配置文件。此文件必须遵循LocalAI YAML配置标准。有关完整的语法细节,请参阅高级文档。配置文件可以位于远程(例如在Github Gist中)或本地文件系统或远程URL中。
可以使用LocalAI的容器镜像或二进制文件启动LocalAI,命令包括模型配置文件的URL或使用简写格式(如huggingface://
或github://
),该格式会展开为完整的URL。
配置也可以通过环境变量设置。例如:
# 命令行参数
local-ai github://owner/repo/file.yaml@branch
# 环境变量
MODELS="github://owner/repo/file.yaml@branch,github://owner/repo/file.yaml@branch" local-ai
以下是启动phi-2模型的示例:
docker run -p 8080:8080 localai/localai:-ffmpeg-core https://gist.githubusercontent.com/mudler/ad601a0488b497b69ec549150d9edd18/raw/a8a8869ef1bb7e3830bf5c0bae29a0cce991ff8d/phi-2.yaml
您还可以查看所有嵌入式模型配置的这里。
快速启动中使用的模型配置在此处可用:https://github.com/mudler/LocalAI/tree/master/embedded/models。欢迎贡献力量;请随时提交Pull Request。
快速启动中的phi-2
模型配置从https://github.com/mudler/LocalAI/blob/master/examples/configurations/phi-2.yaml展开。
示例:自定义提示模板
要修改提示模板,请创建一个Githubgist或Pastebin文件,并复制https://github.com/mudler/LocalAI/blob/master/examples/configurations/phi-2.yaml中的内容。根据需要更改字段:
name: phi-2
context_size: 2048
f16: true
threads: 11
gpu_layers: 90
mmap: true
parameters:
# 在此处引用任何HF模型或本地文件
model: huggingface://TheBloke/phi-2-GGUF/phi-2.Q8_0.gguf
temperature: 0.2
top_k: 40
top_p: 0.95
template:
chat: &template |
Instruct:
Output:
# 在此处修改提示模板 ^^^ 以满足您的需求
completion: *template
然后,使用您的gist URL启动LocalAI:
## 重要!用您的gist URL替换!
docker run -p 8080:8080 localai/localai:-ffmpeg-core https://gist.githubusercontent.com/xxxx/phi-2.yaml