Ollama 官方中文文档
  1. 生成补全
Ollama 官方中文文档
  • 接口 Endpoints
  • 规范 Conventions
  • 生成补全
    • 概括
    • 流式生成请求(Streaming)
      POST
    • 非流式生成请求(No Streaming)
      POST
    • 带后缀的生成请求(with Suffix)
      POST
    • 结构化输出请求(Structured Outputs)
      POST
    • JSON 模式请求(JSON Mode)
      POST
    • 带图像的生成请求(with Images)
      POST
    • 原始模式请求(Raw Mode)
      POST
    • 可复现输出请求(Reproducible Outputs)
      POST
    • 参数化生成请求(with Options)
      POST
    • 加载模型
      POST
    • 卸载模型
      POST
  • 生成对话补全
    • 概括
    • 流式对话请求(Streaming)
      POST
    • 非流式对话请求(No Streaming)
      POST
    • 结构化输出对话请求(Structured Outputs)
      POST
    • 带历史上下文的对话请求(With History)
      POST
    • 带图像的对话请求(with Images)
      POST
    • 可复现输出的对话请求(Reproducible Outputs)
      POST
    • 支持工具调用的对话请求(with Tools)
      POST
    • 加载模型
      POST
    • 卸载模型
      POST
  • 创建模型
    • 概括
    • 创建新模型
      POST
    • 量化模型
      POST
    • 从 GGUF 文件创建模型
      POST
    • 从 Safetensors 目录创建模型
      POST
  • 检查 Blob 是否存在
    • 概括
  • 推送 Blob
    • 概括
  • 列出本地模型
    • 概括
    • 示例
  • 显示模型详情
    • 概括
    • 示例
  • 复制模型
    • 概括
    • 示例
  • 删除模型
    • 概括
    • 示例
  • 拉取模型
    • 概括
    • 示例
  • 推送模型
    • 概括
  • 生成嵌入向量
    • 概括
    • 示例
    • 多输入请求(Multiple Input)
  • 列出运行中模型
    • 概括
    • 示例
  • 生成单个嵌入向量
    • 概括
    • 示例
  • 版本信息
    • 概括
  1. 生成补全

参数化生成请求(with Options)

POST
http://localhost:11434/api/generate
If you want to set custom options for the model at runtime rather than in the Modelfile, you can do so with the options parameter. This example sets every available option, but you can set any of them individually and omit the ones you do not want to override.
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'http://localhost:11434/api/generate' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "llama2-7b",
    "prompt": "请用中文回答以下问题",
    "stream": false,
    "options": {
        "num_keep": 1024,
        "seed": 42,
        "num_predict": 128,
        "top_k": 40,
        "top_p": 0.9,
        "temperature": 0.8,
        "repeat_penalty": 1.1,
        "stop": [
            "\n",
            "。"
        ]
    }
}'
响应示例响应示例
{
  "model": "llama3.2",
  "created_at": "2023-08-04T19:22:45.499127Z",
  "response": "The sky is blue because it is the color of the sky.",
  "done": true,
  "context": [1, 2, 3],
  "total_duration": 4935886791,
  "load_duration": 534986708,
  "prompt_eval_count": 26,
  "prompt_eval_duration": 107345000,
  "eval_count": 237,
  "eval_duration": 4289432000
}

请求参数

Body 参数application/json
model
string 
必需
示例值:
llama2-7b
prompt
string 
必需
示例值:
请用中文回答以下问题
stream
boolean 
必需
示例值:
false
options
object 
必需
num_keep
integer 
必需
示例值:
1024
seed
integer 
必需
示例值:
42
num_predict
integer 
必需
示例值:
128
top_k
integer 
必需
示例值:
40
top_p
number 
必需
示例值:
0.9
temperature
number 
必需
示例值:
0.8
repeat_penalty
number 
必需
示例值:
1.1
stop
array[string]
必需
示例值:
["\n","。"]
示例

返回响应

🟢200Success
application/json
Body
model
string 
必需
created_at
string 
必需
response
string 
必需
done
boolean 
必需
context
array[integer]
必需
total_duration
integer 
必需
load_duration
integer 
必需
prompt_eval_count
integer 
必需
prompt_eval_duration
integer 
必需
eval_count
integer 
必需
eval_duration
integer 
必需
修改于 2025-03-26 10:16:41
上一页
可复现输出请求(Reproducible Outputs)
下一页
加载模型
Built with