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

# Text Generation

## 文本生成 / 通用对话大语言模型

这类模型适合开放式对话、知识问答、内容生成以及各类通用语言任务。它们提供兼容 OpenAI 的 Chat Completions API，可直接接入，并支持按量计费。

**代表性模型：** `deepseek-ai/DeepSeek-V4-Pro`、`Qwen/Qwen3-32B`、`openai/gpt-oss-120b`。完整列表与价格请参见 [模型广场](https://console.siflow.cn/maas-api/model_plaza)。

***

### 1. 能力

* **文本生成**：支持多题材、多风格的自然语言生成，兼顾结构化与长篇内容。
* **语义理解**：多轮对话与意图识别，可保持对话上下文。
* **知识问答**：广泛覆盖科学、技术、文化、历史等多个领域。
* **长上下文**：上下文窗口从 4k 到 131k tokens（因模型而异），适用于长文档与复杂任务。
* **指令遵循**：准确执行复杂指令（例如"用 Markdown 表格对比方案 A 和方案 B"）。
* **风格控制**：使用系统提示词强制统一的语气与风格（学术、口语、诗歌等）。

***

> **注意**\
> 代码生成与数学推理（例如根据自然语言实现函数、重构代码、编写单元测试、分步求解问题）通常也由这类通用模型完成。建议使用较低的 `temperature`（例如 0.1-0.3），以获得更稳定、更可预期的输出。

***

### 2. 使用场景

* **开放式对话**：客服机器人、FAQ 助手、对话式智能体。
* **知识问答**：企业知识库、文档检索、事实类与流程类解答。
* **内容生成**：营销文案、摘要、长篇文章以及创意写作。
* **指令遵循**：任务拆解、分步指南以及结构化输出（例如列表、表格）。

***

### 3. 消息结构

| 角色        | 说明              | 示例                                      |
| --------- | --------------- | --------------------------------------- |
| system    | 定义 AI 的角色、边界与风格 | 您是一名拥有十年经验的程序员。                         |
| user      | 终端用户输入          | 如果服务在模型加载完成之前就启动，缺少了什么配置？               |
| assistant | 用于提供上下文的历史回复或示例 | 存活/就绪探针（liveness/readiness probe）没有配置…… |

提示：按照 `system > user > assistant 历史` 的分层方式组织提示词，通常能让输出更稳定；您也可以根据实际场景尝试不同的提示结构。

***

### 4. 关键参数

* **创造性**：`temperature`（0.0–2.0）、`top_p`（0.0–1.0）。推荐范围 0.2–0.8，以在创造性与稳定性之间取得平衡。
* **输出**：`max_completion_tokens`（限制生成长度）、`stop`（停止序列）、`frequency_penalty`（重复惩罚）、`stream=True`（对于长回复推荐使用，可降低超时风险）。
* **上下文**：不同模型的上下文限制各不相同；请参见 [模型广场](https://console.siflow.cn/maas-api/model_plaza) 查看各模型的具体情况。

**常见问题：** 如果输出出现乱码，可尝试调整 `temperature`、`top_p` 和 `frequency_penalty`；同时建议将 `max_completion_tokens` 控制在最大上下文长度以内，为输入留出空间。如果输出被截断，请设置合理的 `max_completion_tokens`、启用 `stream=True`，并增大客户端超时时间。

***

### 5. 计费与配额

* **公式**：总费用 =（输入 tokens × 输入单价）+（输出 tokens × 输出单价）。
* 各模型价格：[模型广场](https://console.siflow.cn/maas-api/model_plaza) → 模型详情页。
* **建议**：在研发阶段优先使用成本较低或免费的模型；长回复场景建议使用流式输出并合理设置 `max_completion_tokens`；对于高 QPS 负载，请结合并发控制和限流策略使用。

***

### 6. 示例

#### 6.1 多轮对话

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_KEY",
    base_url="https://api.siflow.cn/model-api"
)

response = client.chat.completions.create(
    model="Qwen/Qwen3-32B",
    messages=[
        {"role": "system", "content": "You are a helpful assistant. Keep answers concise."},
        {"role": "user", "content": "What are the main benefits of microservices architecture?"}
    ],
    temperature=0.7,
    max_completion_tokens=1024
)

print(response.choices[0].message.content)
```

#### 6.2 数据分析内容生成

```python theme={null}
from openai import OpenAI

client = OpenAI(api_key="YOUR_KEY", base_url="https://api.siflow.cn/model-api")

response = client.chat.completions.create(
    model="MiniMaxAI/MiniMax-M2.7",
    messages=[
        {"role": "system", "content": "You are a data analysis expert. Output results in Markdown with clear sections and bullet points."},
        {"role": "user", "content": "Summarize typical patterns in SaaS trial-to-paid conversion by cohort (e.g. by signup week). What metrics and recommendations would you highlight? Keep it under 300 words."}
    ],
    temperature=0.5,
    max_completion_tokens=1024
)

print(response.choices[0].message.content)
```

#### 6.3 发布说明 / 更新日志

```python theme={null}
from openai import OpenAI

client = OpenAI(api_key="YOUR_KEY", base_url="https://api.siflow.cn/model-api")

response = client.chat.completions.create(
    model="glm-5.2",
    messages=[
        {"role": "system", "content": "You write concise release notes. Use a short intro and bullet points."},
        {"role": "user", "content": "Draft release notes for v2.0 of a CLI tool. New in this version: added `config` and `run` subcommands, support for env-based config, and a `--dry-run` flag. Keep it under 150 words."}
    ],
    temperature=0.5,
    max_completion_tokens=512
)

print(response.choices[0].message.content)
```

***

* 对于长回复，请设置 `stream=True` 并消费该流，以降低超时风险。
* 关于结构化输出（JSON）或图像理解，请参见 [Response Format](/products/model-inference/function/response-format) 和 [Vision and Multimodal](/products/model-inference/models/vision-and-multimodal)。
