Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
578 changes: 578 additions & 0 deletions src/SharpInference.Core/ToolCallAdapter.cs

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/SharpInference.Server/ChatTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,28 @@ public sealed class ChatTemplateRenderer
{
private JinjaChatTemplate? _template;
private string _architecture;
private IToolCallAdapter _toolCallAdapter;

/// <summary>Architecture string used to pick a fallback template when no Jinja is loaded.</summary>
public string Architecture => _architecture;

/// <summary>Compiled Jinja template, if the loaded model shipped one.</summary>
public JinjaChatTemplate? JinjaTemplate => _template;

/// <summary>
/// Tool-call translation layer matched to the loaded model's architecture. Resolved
/// once at <see cref="Configure"/> time from <see cref="ToolCallAdapterRegistry"/>;
/// endpoint code reads this without having to look up by string each request.
/// </summary>
public IToolCallAdapter ToolCallAdapter => _toolCallAdapter;

/// <param name="architecture">Default architecture (used both for fallback and exposed via <see cref="Architecture"/>).</param>
/// <param name="template">Optional compiled Jinja template; null means "use the hardcoded fallback".</param>
public ChatTemplateRenderer(string architecture = "qwen2", JinjaChatTemplate? template = null)
{
_architecture = architecture;
_template = template;
_toolCallAdapter = ToolCallAdapterRegistry.Get(architecture);
}

/// <summary>
Expand All @@ -83,6 +92,7 @@ public void Configure(string architecture, JinjaChatTemplate? template)
{
_architecture = architecture;
_template = template;
_toolCallAdapter = ToolCallAdapterRegistry.Get(architecture);
}

/// <param name="messages">Messages in order (system, user, assistant, ...).</param>
Expand Down
198 changes: 123 additions & 75 deletions src/SharpInference.Server/Endpoints/AnthropicEndpoints.cs

Large diffs are not rendered by default.

Loading