Concrete base class for chat format adapters (80% logic).
More...
#include <entropic/inference/adapters/adapter_base.h>
|
| | ChatAdapter (std::string tier_name, std::string identity_prompt) |
| | Construct adapter with tier identity.
|
| |
| std::string | format_system_prompt (const std::string &base_prompt, const std::vector< std::string > &tool_jsons) const |
| | Assemble system prompt: identity + context + tools.
|
| |
| virtual ParseResult | parse_tool_calls (const std::string &content) const =0 |
| | Parse tool calls from model output.
|
| |
| virtual Message | format_tool_result (const ToolCall &tool_call, const std::string &result) const |
| | Format a tool result as a user message.
|
| |
| virtual std::string | format_tools (const std::vector< std::string > &tool_jsons) const |
| | Format tool definitions for injection into system prompt.
|
| |
| bool | is_response_complete (const std::string &content, const std::vector< ToolCall > &tool_calls) const |
| | Check if response represents task completion.
|
| |
| virtual std::string | chat_format () const =0 |
| | Chat format identifier (e.g.
|
| |
| virtual std::string | format_system_with_vision (const std::string &base_system, bool has_vision) const |
| | Format system prompt with optional vision context.
|
| |
| virtual std::string | format_content_parts (const std::vector< ContentPart > &parts) const |
| | Convert multimodal content parts to adapter-specific format.
|
| |
Concrete base class for chat format adapters (80% logic).
Provides shared parsing primitives, think-block handling, JSON recovery, and system prompt assembly. Subclasses override parse_tool_calls() and optionally format_tools()/format_tool_result().
- Version
- 1.8.2
Definition at line 58 of file adapter_base.h.
◆ ChatAdapter()
| entropic::ChatAdapter::ChatAdapter |
( |
std::string |
tier_name, |
|
|
std::string |
identity_prompt |
|
) |
| |
Construct adapter with tier identity.
- Parameters
-
| tier_name | Identity tier (e.g. "eng", "lead"). |
| identity_prompt | Assembled identity prompt. |
- Version
- 1.8.2
- Parameters
-
| tier_name | Identity tier name. |
| identity_prompt | Assembled identity prompt. |
- Version
- 1.8.2
Definition at line 102 of file adapter_base.cpp.
◆ chat_format()
| virtual std::string entropic::ChatAdapter::chat_format |
( |
| ) |
const |
|
pure virtual |
◆ extract_thinking()
| std::string entropic::ChatAdapter::extract_thinking |
( |
const std::string & |
content | ) |
const |
|
protected |
Extract <think>...</think> content.
Extract content from <think>...</think> blocks.
- Version
- 1.8.2
- Parameters
-
- Returns
- Concatenated thinking content, or empty string.
Definition at line 325 of file adapter_base.cpp.
◆ format_content_parts()
| std::string ChatAdapter::format_content_parts |
( |
const std::vector< ContentPart > & |
parts | ) |
const |
|
virtual |
Convert multimodal content parts to adapter-specific format.
Default: OpenAI-format content array JSON.
- Parameters
-
| parts | Content parts from a message. |
- Returns
- JSON string in the format expected by the model's chat template.
- Version
- 1.9.11
Default: OpenAI-format content array. Adapters override if the model expects a different image reference format.
- Parameters
-
| parts | Content parts from a message. |
- Returns
- JSON array string with text/image objects.
Reimplemented in entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
Definition at line 497 of file adapter_base.cpp.
◆ format_system_prompt()
| std::string entropic::ChatAdapter::format_system_prompt |
( |
const std::string & |
base_prompt, |
|
|
const std::vector< std::string > & |
tool_jsons |
|
) |
| const |
Assemble system prompt: identity + context + tools.
- Parameters
-
| base_prompt | Application context. |
| tool_jsons | Tool definitions as JSON strings. |
- Returns
- Assembled system prompt.
- Version
- 1.8.2
- Parameters
-
| base_prompt | Application context. |
| tool_jsons | Tool definitions as JSON strings. |
- Returns
- Assembled system prompt string.
Definition at line 118 of file adapter_base.cpp.
◆ format_system_with_vision()
| std::string ChatAdapter::format_system_with_vision |
( |
const std::string & |
base_system, |
|
|
bool |
has_vision |
|
) |
| const |
|
virtual |
Format system prompt with optional vision context.
Default: return system prompt unchanged regardless of vision.
- Parameters
-
| base_system | Base system prompt text. |
| has_vision | Whether the model has vision capability. |
- Returns
- Formatted system prompt.
- Version
- 1.9.11
Default implementation returns base_system unchanged. Vision-capable adapters override to append vision instructions.
- Parameters
-
| base_system | Base system prompt text. |
| has_vision | Whether vision is available. |
- Returns
- base_system unchanged.
Reimplemented in entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
Definition at line 484 of file adapter_base.cpp.
◆ format_tool_result()
| Message entropic::ChatAdapter::format_tool_result |
( |
const ToolCall & |
tool_call, |
|
|
const std::string & |
result |
|
) |
| const |
|
virtual |
Format a tool result as a user message.
Format tool result as user message (default).
- Parameters
-
| tool_call | The tool call that was executed. |
| result | Tool execution result text. |
- Returns
- Formatted message.
- Version
- 1.8.2
- Parameters
-
| tool_call | The executed tool call. |
| result | Execution result text. |
- Returns
- Formatted user message.
Reimplemented in entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
Definition at line 158 of file adapter_base.cpp.
◆ format_tools()
| std::string ChatAdapter::format_tools |
( |
const std::vector< std::string > & |
tool_jsons | ) |
const |
|
virtual |
Format tool definitions for injection into system prompt.
Default tool formatting: markdown headings + JSON schema.
- Parameters
-
| tool_jsons | Tool definition JSON strings. |
- Returns
- Adapter-formatted tool prompt string.
- Version
- 2.0.4
- Parameters
-
| tool_jsons | Tool definitions as JSON strings. |
- Returns
- Formatted tool section string.
Reimplemented in entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
Definition at line 428 of file adapter_base.cpp.
◆ is_response_complete()
| bool entropic::ChatAdapter::is_response_complete |
( |
const std::string & |
content, |
|
|
const std::vector< ToolCall > & |
tool_calls |
|
) |
| const |
Check if response represents task completion.
- Parameters
-
| content | Response content. |
| tool_calls | Parsed tool calls. |
- Returns
- true if complete.
- Version
- 1.8.2
Think-aware: think-only content without tool calls = still working.
- Parameters
-
| content | Response content. |
| tool_calls | Parsed tool calls. |
- Returns
- true if complete.
Definition at line 182 of file adapter_base.cpp.
◆ parse_bare_json_tool_calls()
| std::vector< ToolCall > entropic::ChatAdapter::parse_bare_json_tool_calls |
( |
const std::string & |
content | ) |
const |
|
protected |
Parse bare JSON lines containing "name" key.
Parse bare JSON tool calls from lines.
- Version
- 1.8.2
- Parameters
-
- Returns
- Vector of tool calls from bare JSON lines.
Definition at line 284 of file adapter_base.cpp.
◆ parse_single_tool_call()
| std::optional< ToolCall > ChatAdapter::parse_single_tool_call |
( |
const std::string & |
json_str | ) |
const |
|
protected |
Parse a single JSON tool call string.
- Parameters
-
| json_str | JSON from tagged block. |
- Returns
- Parsed ToolCall or nullopt.
- Version
- 1.8.2
- Parameters
-
| json_str | JSON string from tagged block. |
- Returns
- Parsed ToolCall or nullopt.
Definition at line 460 of file adapter_base.cpp.
◆ parse_tagged_tool_calls()
| std::vector< ToolCall > entropic::ChatAdapter::parse_tagged_tool_calls |
( |
const std::string & |
content | ) |
const |
|
protected |
Parse <tool_call>JSON</tool_call> tagged blocks.
- Version
- 1.8.2
- Parameters
-
| content | Model output content. |
- Returns
- Vector of parsed tool calls.
Definition at line 212 of file adapter_base.cpp.
◆ parse_tool_calls()
| virtual ParseResult entropic::ChatAdapter::parse_tool_calls |
( |
const std::string & |
content | ) |
const |
|
pure virtual |
◆ strip_think_blocks()
| std::string entropic::ChatAdapter::strip_think_blocks |
( |
const std::string & |
content | ) |
const |
|
protected |
Strip all <think>...</think> blocks from content.
- Version
- 1.8.2
- Parameters
-
- Returns
- Content with think blocks removed.
Definition at line 346 of file adapter_base.cpp.
◆ try_recover_json()
| std::optional< ToolCall > entropic::ChatAdapter::try_recover_json |
( |
const std::string & |
json_str | ) |
const |
|
protected |
Attempt JSON recovery on malformed tool call string.
- Version
- 1.8.2
◆ identity_prompt_
| std::string entropic::ChatAdapter::identity_prompt_ |
|
protected |
◆ tier_name_
| std::string entropic::ChatAdapter::tier_name_ |
|
protected |
◆ tool_prefixes_
| std::unordered_set<std::string> entropic::ChatAdapter::tool_prefixes_ |
|
mutableprotected |
The documentation for this class was generated from the following files: