> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monostate.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 生成参数

> 控制模型如何生成回复

# 生成参数

调整这些设置以控制模型输出。

## 关键参数

### Temperature

控制回复中的随机性。

| 值         | 效果       | 用例       |
| --------- | -------- | -------- |
| 0.0 - 0.3 | 非常一致，确定性 | 事实性答案，代码 |
| 0.5 - 0.7 | 平衡       | 一般对话     |
| 0.8 - 1.0 | 更多变化，创造性 | 创意写作     |
| 1.0+      | 非常随机     | 头脑风暴     |

```
Low temperature (0.3):  "The capital of France is Paris."
High temperature (1.2): "Paris, the city of lights, serves as France's bustling capital!"
```

### Max Tokens

回复的最大长度。

| 值        | 典型用途  |
| -------- | ----- |
| 50-100   | 简短答案  |
| 256      | 标准回复  |
| 512-1024 | 详细解释  |
| 2048+    | 长文本内容 |

<Note>
  更大的 max tokens = 更长的生成时间。
</Note>

### Top-p (Nucleus Sampling)

将 token 选择限制为累积概率。

* **0.95** (UI 默认值) - 考虑直到 95% 概率质量的 tokens
* **0.9** - 稍微更聚焦
* **0.5** - 非常聚焦

### Top-k

限制为 k 个最可能的 tokens。

* **50** (默认值) - 考虑前 50 个 tokens
* **10** - 非常聚焦
* **100** - 更多变化

## 参数组合

### 事实性问答

```
temperature: 0.3
max_tokens: 256
top_p: 0.9
```

一致、准确的答案。

### 创意写作

```
temperature: 0.9
max_tokens: 1024
top_p: 0.95
```

多样化、创造性的输出。

### 代码生成

```
temperature: 0.2
max_tokens: 512
top_p: 0.95
```

精确、语法正确的代码。

### 对话

```
temperature: 0.7
max_tokens: 256
top_p: 0.9
```

自然、多样化的回复。

## 找到正确的设置

### 从默认值开始

默认设置适用于大多数情况：

* temperature: 0.7
* max\_tokens: 256
* top\_p: 0.95
* top\_k: 50
* do\_sample: true

### UI 滑块范围

聊天界面提供以下参数范围：

| 参数          | 最小值 | 最大值  | 步长   | 默认值  |
| ----------- | --- | ---- | ---- | ---- |
| Temperature | 0   | 2    | 0.1  | 0.7  |
| Max Tokens  | 50  | 2048 | 50   | 256  |
| Top P       | 0   | 1    | 0.05 | 0.95 |
| Top K       | 0   | 100  | 5    | 50   |

### 一次调整一个

1. 如果回复太随机 → 降低 temperature
2. 如果回复太重复 → 提高 temperature
3. 如果回复被截断 → 增加 max\_tokens
4. 如果回复太长 → 减少 max\_tokens

### 系统化测试

对于重要应用：

1. 选择 5-10 个测试提示
2. 尝试每个参数设置
3. 比较输出
4. 记录有效的方法

## 高级参数

### Repetition Penalty

减少重复短语。

* **1.0** - 无惩罚
* **1.1** - 轻微惩罚（推荐）
* **1.3+** - 强惩罚

### Stop Sequences

当这些 tokens 出现时结束生成。

* 对结构化输出有用
* 示例：`["\n\n", "User:"]`

### Do Sample

控制是否使用采样或贪心解码。

* **true** (默认值) - 使用 temperature/top-p/top-k 进行采样
* **false** - 贪心解码（总是选择最可能的 token）

### System Prompt

设置系统消息以指导模型行为。可在聊天界面设置面板中使用。

示例 system prompts：

* "You are a helpful coding assistant. Provide concise code examples."
* "You are a creative writing partner. Be imaginative and descriptive."
* "You are a technical documentation expert. Be precise and thorough."

System prompt 会前置到对话上下文中，并在整个会话期间影响模型的响应方式。

## 参数效果总结

| 参数                  | 低值    | 高值     |
| ------------------- | ----- | ------ |
| temperature         | 一致，聚焦 | 随机，创造性 |
| max\_tokens         | 短回复   | 长回复    |
| top\_p              | 聚焦    | 多样化    |
| top\_k              | 非常聚焦  | 更多选项   |
| repetition\_penalty | 可能重复  | 避免重复   |

## 下一步

<CardGroup cols={2}>
  <Card title="CLI 训练" href="/cli/llm-training">
    使用 CLI 训练模型
  </Card>

  <Card title="Python API" href="/api/introduction">
    程序化控制
  </Card>
</CardGroup>
