
DeepSeek-V4 编码格式详解【免费下载链接】DeepSeek-V4-FlashDeepSeek-V4-Flash总参数 284B激活 13B主打极致性价比推理成本仅为前代的十分之一适合高频对话和大规模部署。两个版本均支持 Thinking/Non-Thinking 双模式通过创新的混合注意力架构CSAHCA实现 1M 上下文下 10 倍以上的推理效率提升。项目地址: https://ai.gitcode.com/hf_mirrors/deepseek-ai/DeepSeek-V4-Flash概述DeepSeek-V4 系列模型采用特定的编码格式来处理多轮对话、工具调用、推理过程和快速指令任务。本文档详细介绍了该编码格式的实现细节。快速开始from encoding_dsv4 import encode_messages, parse_message_from_completion_text # 编码对话 messages [ {role: system, content: You are a helpful assistant.}, {role: user, content: What is 22?}, ] prompt encode_messages(messages, thinking_modethinking) # 解析模型输出回结构化消息 completion Simple arithmetic./think2 2 4. parsed parse_message_from_completion_text(completion, thinking_modethinking) # {role: assistant, reasoning_content: Simple arithmetic., content: 2 2 4., tool_calls: []}注意parse_message_from_completion_text函数仅设计用于处理格式良好的模型输出。它不会尝试纠正或恢复模型可能偶尔生成的格式错误的输出。对于生产环境使用建议添加额外的错误处理。消息格式特殊令牌令牌用途begin▁of▁sentence序列开始 (BOS)end▁of▁sentence助手回合结束 (EOS)Human用户回合前缀Assistant助手回合前缀latest_reminder最新提醒日期、区域设置等/think/think推理块分隔符DSMLDSML 标记令牌角色编码支持以下消息角色system、user、assistant、tool、latest_reminder和developer。关于developer角色的说明developer角色专门用于内部搜索代理管道。对于通用聊天或工具调用任务不需要此角色官方 API 也不接受具有此角色的消息。基础聊天简单的多轮对话编码如下begin▁of▁sentenceHuman{user_message}end▁of▁sentenceAssistant{response}end▁of▁sentenceHuman{user_message_2}end▁of▁sentenceAssistant{response_2}end▁of▁sentenceBOS 令牌在对话的最开始添加。在聊天模式thinking_modechat中/think紧接在Assistant之后放置以立即关闭思考块使模型直接生成内容。交错推理模式在推理模式thinking_modethinking中模型在响应之前在/think...think块中产生显式推理。begin▁of▁sentenceHuman{message}end▁of▁sentenceAssistant/think{reasoning}think{response}end▁of▁sentencedrop_thinking参数默认为True控制是否保留先前回合的推理没有工具时drop_thinking生效。从最后一个用户消息之前的助手回合中剥离推理内容。只有最终的助手回合保留其/think...think块。使用工具时在系统或开发者消息上drop_thinking自动禁用。所有回合都保留其推理因为工具调用对话需要完整的上下文来跟踪跨工具调用的多步推理。工具调用DSML 格式工具通过tools字段OpenAI 兼容格式在system或developer消息上定义。当工具存在时以下模式块被注入到系统/用户提示中## Tools You have access to a set of tools to help answer the users question. You can invoke tools by writing a DSMLtool_calls block like the following: DSMLtool_calls DSMLinvoke name$TOOL_NAME DSMLparameter name$PARAMETER_NAME stringtrue|false$PARAMETER_VALUE/DSMLparameter ... /DSMLinvoke DSMLinvoke name$TOOL_NAME2 ... /DSMLinvoke /DSMLtool_calls String parameters should be specified as is and set stringtrue. For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set stringfalse. If thinking_mode is enabled (triggered by /think), you MUST output your complete reasoning inside /think...think BEFORE any tool calls or final response. Otherwise, output directly after think with tool calls or final response. ### Available Tool Schemas {tool_definitions_json} You MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.助手回合中的实际工具调用如下所示DSMLtool_calls DSMLinvoke namefunction_name DSMLparameter nameparam stringtruestring_value/DSMLparameter DSMLparameter namecount stringfalse5/DSMLparameter /DSMLinvoke /DSMLtool_callsstringtrue参数值是原始字符串。stringfalse参数值是 JSON数字、布尔值、数组、对象。工具执行结果包装在用户消息内的tool_result标签中Humantool_result{result_json}/tool_resultend▁of▁sentenceAssistant/think...当存在多个工具结果时它们按照前一个助手消息中相应tool_calls的顺序排序。推理努力程度当设置reasoning_effortmax时在提示的最开始系统消息之前会添加一个特殊前缀指示模型最大化其推理深度Reasoning Effort: Absolute maximum with no shortcuts permitted. You MUST be very thorough in your thinking and comprehensively decompose the problem to resolve the root cause, rigorously stress-testing your logic against all potential paths, edge cases, and adversarial scenarios. Explicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked.快速指令特殊令牌快速指令令牌用于辅助分类和生成任务。它们通过task字段附加到消息中以触发针对单令牌或短格式输出的专门模型行为。特殊令牌描述格式action确定用户提示是否需要网络搜索或可以直接回答。...Human{prompt}end▁of▁sentenceAssistant/thinkactiontitle在第一个助手响应后生成简洁的对话标题。...Assistant{response}end▁of▁sentencetitlequery为用户提示生成搜索查询。...Human{prompt}queryauthority对用户提示对来源权威性的需求进行分类。...Human{prompt}authoritydomain识别用户提示的领域。...Human{prompt}domainextracted_urlread_url确定用户提示中的每个 URL 是否应该被获取和读取。...Human{prompt}extracted_url{url}read_url在消息格式中的使用用户消息上的actionaction令牌放置在助手前缀和思考令牌之后触发路由决策例如Search 或 Answer。用户消息上的其他任务query、authority、domain、read_url任务令牌直接附加在用户内容之后。助手消息上的titletitle令牌附加在助手的 EOS 之后。下一个助手消息提供生成的标题。【免费下载链接】DeepSeek-V4-FlashDeepSeek-V4-Flash总参数 284B激活 13B主打极致性价比推理成本仅为前代的十分之一适合高频对话和大规模部署。两个版本均支持 Thinking/Non-Thinking 双模式通过创新的混合注意力架构CSAHCA实现 1M 上下文下 10 倍以上的推理效率提升。项目地址: https://ai.gitcode.com/hf_mirrors/deepseek-ai/DeepSeek-V4-Flash创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考