text-truncator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese文本截断工具
Text Truncation Tool
功能
Features
智能截断文本,在保持内容完整性和语义连贯性的前提下,将文本截断至指定长度。
Intelligently truncate text to the specified length while maintaining content integrity and semantic coherence.
使用场景
Usage Scenarios
- 对超出长度限制的文本进行预处理,使其符合智能体的输入要求。
- 在展示文本预览或生成摘要时,截取关键部分以提高效率和可读性。
- 辅助内容创作,对生成的长文本进行智能裁剪,避免冗余。
- Preprocess text that exceeds length limits to meet the input requirements of agents.
- Extract key sections when displaying text previews or generating summaries to improve efficiency and readability.
- Assist content creation by intelligently cropping generated long texts to avoid redundancy.
核心能力
Core Capabilities
- 语义优先截断: 优先在自然语义边界(如句号、问号、感叹号)处进行截断,最大限度地保持句子的完整性。
- 段落完整性: 在语义边界不足时,优先考虑在段落末尾或换行符处截断,避免破坏段落结构。
- 精确长度控制: 严格遵守用户指定的最大长度限制,确保输出文本不会超限。
- 截断标记插入(可选): 可以在截断文本的末尾自动添加自定义截断标记(如"..."),以指示内容有删节。
- Semantics-Prioritized Truncation: Prioritize truncation at natural semantic boundaries (such as periods, question marks, exclamation marks) to maximize sentence integrity.
- Paragraph Integrity: When semantic boundaries are insufficient, prioritize truncation at the end of paragraphs or line breaks to avoid disrupting paragraph structure.
- Precise Length Control: Strictly adhere to the user-specified maximum length limit to ensure the output text does not exceed the limit.
- Optional Truncation Marker Insertion: Automatically add a custom truncation marker (such as "...") at the end of the truncated text to indicate omitted content.
输入要求
Input Requirements
- 文本内容: 待截断的原始文本(字符串)。
- 最大长度限制: 文本截断后的最大长度(整数,如字符数或 token 数)。
- 截断标记(可选): 自定义截断标记,如 "..." 或 "[内容已截断]"。
- Text Content: The original text to be truncated (string).
- Maximum Length Limit: The maximum length of the truncated text (integer, such as number of characters or tokens).
- Optional Truncation Marker: Custom truncation marker, such as "..." or "[Content Truncated]".
输出格式
Output Format
【文本截断报告】
- 原始文本长度: [整数] 字/Token
- 截断后长度: [整数] 字/Token
- 截断位置: [位置描述,如 "在第X句末尾"] 或 "未截断"【Text Truncation Report】
- Original Text Length: [Integer] characters/tokens
- Truncated Text Length: [Integer] characters/tokens
- Truncation Position: [Position description, e.g., "At the end of sentence X"] or "Not truncated"截断后的文本
Truncated Text
[截断后的文本内容]
undefined[Truncated text content]
undefined约束条件
Constraints
- 截断后的文本长度必须严格符合最大长度限制。
- 确保截断后的文本在语义上尽可能连贯和完整。
- 如果文本未达到最大长度,则不进行截断,返回原始文本。
- 输出格式必须结构化,清晰展示截断前后的长度信息和截断后的文本内容。
- The length of the truncated text must strictly comply with the maximum length limit.
- Ensure the truncated text is as semantically coherent and complete as possible.
- If the text does not reach the maximum length, no truncation is performed and the original text is returned.
- The output format must be structured, clearly displaying length information before and after truncation and the truncated text content.
示例
Examples
参见 目录获取更多详细示例:
{baseDir}/references/examples.md- - 包含不同长度、不同截断标记和复杂文本结构的截断示例。
examples.md
Refer to the directory for more detailed examples:
{baseDir}/references/examples.md- - Contains truncation examples with different lengths, different truncation markers, and complex text structures.
examples.md
详细文档
Detailed Documentation
参见 获取关于文本截断工具的详细指导与案例。
{baseDir}/references/examples.mdRefer to for detailed guidance and cases regarding the text truncation tool.
{baseDir}/references/examples.md版本历史
Version History
| 版本 | 日期 | 变更 |
|---|---|---|
| 2.1.0 | 2026-01-11 | 优化 description 字段,使其更精简并符合命令式语言规范;模型更改为 opus;优化功能、核心能力、输入要求、输出格式的描述,使其更符合命令式语言规范;添加使用场景、约束条件、示例和详细文档部分。 |
| 2.0.0 | 2026-01-11 | 按官方规范重构 |
| 1.0.0 | 2026-01-10 | 初始版本 |
| Version | Date | Changes |
|---|---|---|
| 2.1.0 | 2026-01-11 | Optimized the description field to be more concise and compliant with imperative language specifications; changed the model to opus; optimized the descriptions of features, core capabilities, input requirements, and output format to comply with imperative language specifications; added sections for usage scenarios, constraints, examples, and detailed documentation. |
| 2.0.0 | 2026-01-11 | Restructured according to official specifications |
| 1.0.0 | 2026-01-10 | Initial version |