复制模型接口可以快速创建现有模型的副本,适用于创建备份或测试版本。
curl http://localhost:11434/api/copy -d '{
"source": "llama3.2",
"destination": "llama3.2-backup"
}'
成功时返回 200 状态码,无响应体。
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
| source | string | 是 | 源模型名称 |
| destination | string | 是 | 目标模型名称 |
import requests
def copy_model(source, destination):
response = requests.post(
"http://localhost:11434/api/copy",
json={
"source": source,
"destination": destination
}
)
if response.status_code == 200:
print(f"模型已复制: {source} -> {destination}")
else:
print(f"复制失败: {response.json()}")
copy_model("llama3.2", "llama3.2-backup")
def backup_models(suffix="-backup"):
models = requests.get("http://localhost:11434/api/tags").json()["models"]
for model in models:
source = model["name"]
if not source.endswith(suffix):
destination = source.split(":")[0] + suffix
copy_model(source, destination)
backup_models()
async function copyModel(source, destination) {
const response = await fetch('http://localhost:11434/api/copy', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ source, destination })
});
if (response.ok) {
console.log(`模型已复制: ${source} -> ${destination}`);
} else {
const error = await response.json();
console.error(`复制失败:`, error);
}
}
await copyModel('llama3.2', 'llama3.2-backup');
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type CopyRequest struct {
Source string `json:"source"`
Destination string `json:"destination"`
}
func copyModel(source, destination string) error {
req := CopyRequest{
Source: source,
Destination: destination,
}
body, _ := json.Marshal(req)
resp, err := http.Post(
"http://localhost:11434/api/copy",
"application/json",
bytes.NewReader(body),
)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
fmt.Printf("模型已复制: %s -> %s\n", source, destination)
}
return nil
}
func main() {
copyModel("llama3.2", "llama3.2-backup")
}
def create_test_version(model_name):
test_name = f"{model_name}-test"
copy_model(model_name, test_name)
response = requests.post(
"http://localhost:11434/api/create",
json={
"name": test_name,
"modelfile": f"""
FROM {model_name}
SYSTEM 你是一个测试助手,用于测试新的系统提示。
PARAMETER temperature 0.5
"""
}
)
print(f"测试版本已创建: {test_name}")
create_test_version("llama3.2")
import datetime
def create_version(model_name, version_note=""):
date_str = datetime.datetime.now().strftime("%Y%m%d")
version_name = f"{model_name}-v{date_str}"
copy_model(model_name, version_name)
print(f"版本已创建: {version_name}")
if version_note:
print(f"备注: {version_note}")
create_version("llama3.2", "修改系统提示前的备份")