easydel.inference.tools.parsers.deepseekv3_tool_parser#
- class easydel.inference.tools.parsers.deepseekv3_tool_parser.DeepSeekV3ToolParser(tokenizer: AutoTokenizer)[source]#
Bases:
ToolParserTool parser for DeepSeek V3 models.
This parser handles the specific tool call format used by DeepSeek V3 models, which uses custom delimiters for tool calls and arguments. The format includes: - Tool calls wrapped in <|tool▁calls▁begin|> and <|tool▁calls▁end|> - Individual calls wrapped in <|tool▁call▁begin|> and <|tool▁call▁end|> - Tool type and name separated by <|tool▁sep|> - Arguments in JSON format wrapped in ```json blocks
- current_tool_name_sent#
Tracks if tool name has been sent in streaming
- Type
bool
- prev_tool_call_arr#
Previous tool calls for comparison in streaming
- Type
list
- current_tool_id#
Index of current tool being processed
- Type
int
- streamed_args_for_tool#
Arguments streamed so far for each tool
- Type
list
- tool_calls_start_token#
Token marking start of tool calls section
- Type
str
- tool_calls_end_token#
Token marking end of tool calls section
- Type
str
- tool_call_start_token#
Token marking start of individual tool call
- Type
str
- tool_call_end_token#
Token marking end of individual tool call
- Type
str
- extract_tool_calls(model_output: str, request: ChatCompletionRequest) ExtractedToolCallInformation[source]#
Extract tool calls from complete model output.
Parses the DeepSeek V3 format to extract function names and arguments from the model’s response. Handles the specific token structure with tool type, separator, and JSON argument blocks.
- Parameters
model_output – Complete text output from the model
request – Original chat completion request with tool definitions
- Returns
tools_called: Whether any tools were invoked
tool_calls: List of ToolCall objects with function details
content: Text content before tool calls (if any)
- Return type
ExtractedToolCallInformation containing
- extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int], current_token_ids: Sequence[int], delta_token_ids: Sequence[int], request: ChatCompletionRequest) easydel.inference.openai_api_modules.DeltaMessage | None[source]#
Extract tool calls from streaming model output.
Handles incremental parsing of DeepSeek V3 tool call format during streaming generation. Maintains state across chunks to properly identify tool boundaries and stream arguments progressively.
- Parameters
previous_text – Text generated up to previous chunk
current_text – All text generated so far
delta_text – New text in this chunk
previous_token_ids – Token IDs up to previous chunk
current_token_ids – All token IDs so far
delta_token_ids – New token IDs in this chunk
request – Original request with tool definitions
- Returns
DeltaMessage with incremental tool call information, or None if more data needed for parsing