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
7 changes: 4 additions & 3 deletions src/LLTSharp/ITemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public interface ITemplate : IMetadataProvider
/// Renders the template with the given context.
/// </summary>
/// <param name="context">The context to use for rendering the template. Can be null.</param>
/// <param name="functions">Optional set of functions to use during rendering. Can be null.</param>
/// <returns>The result of rendering the template.</returns>
object Render(object? context = null);
object Render(object? context = null, TemplateFunctionSet? functions = null);
}

/// <summary>
Expand All @@ -22,8 +23,8 @@ public interface ITemplate : IMetadataProvider
/// <typeparam name="TResult">The type of result produced by the template.</typeparam>
public interface ITemplate<TResult> : ITemplate
{
/// <inheritdoc cref="ITemplate.Render(object?)"/>
new TResult Render(object? context = null);
/// <inheritdoc cref="ITemplate.Render(object?, TemplateFunctionSet?)"/>
new TResult Render(object? context = null, TemplateFunctionSet? functions = null);
}

/// <summary>
Expand Down
13 changes: 4 additions & 9 deletions src/LLTSharp/MessagesTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,15 @@ public MessagesTemplate(MessagesTemplateNode mainNode, IMetadataCollection metad
LocalLibrary = localLibrary ?? throw new ArgumentNullException(nameof(localLibrary));
}

/// <summary>
/// Renders the messages template using the provided data accessor.
/// </summary>
/// <param name="context">The context accessor to use for rendering.</param>
/// <returns>The rendered prompt as a collection of messages.</returns>
public IEnumerable<Message> Render(object? context = null)
public IEnumerable<Message> Render(object? context = null, TemplateFunctionSet? functions = null)
{
var ctx = new TemplateContextAccessor(TemplateDataAccessor.Create(context), Metadata, library: LocalLibrary);
var ctx = new TemplateContextAccessor(TemplateDataAccessor.Create(context), Metadata, functions: functions, library: LocalLibrary);
return _node.Render(ctx);
}

object ITemplate.Render(object? context)
object ITemplate.Render(object? context, TemplateFunctionSet? functions)
{
var ctx = new TemplateContextAccessor(TemplateDataAccessor.Create(context), Metadata, library: LocalLibrary);
var ctx = new TemplateContextAccessor(TemplateDataAccessor.Create(context), Metadata, functions: functions, library: LocalLibrary);
return _node.Render(ctx);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/LLTSharp/PlaintextTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public PlaintextTemplate(string content, IMetadataCollection metadata)
Metadata = new MetadataCollection(metadata) ?? throw new ArgumentNullException(nameof(metadata));
}

public string Render(object? context = null)
public string Render(object? context = null, TemplateFunctionSet? functions = null)
{
return Content;
}

object ITemplate.Render(object? context)
object ITemplate.Render(object? context, TemplateFunctionSet? functions)
{
return Render(context);
return Render(context, functions);
}
}
}
13 changes: 4 additions & 9 deletions src/LLTSharp/TextTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,15 @@ public TextTemplate(TextTemplateNode mainNode, IMetadataCollection metadata, Tem
LocalLibrary = localLibrary ?? throw new ArgumentNullException(nameof(localLibrary));
}

/// <summary>
/// Renders the text template using the provided data accessor.
/// </summary>
/// <param name="context">The context accessor to use for rendering.</param>
/// <returns>The rendered text as a string.</returns>
public string Render(object? context = null)
public string Render(object? context = null, TemplateFunctionSet? functions = null)
{
var ctx = new TemplateContextAccessor(TemplateDataAccessor.Create(context), Metadata, library: LocalLibrary);
var ctx = new TemplateContextAccessor(TemplateDataAccessor.Create(context), Metadata, functions: functions, library: LocalLibrary);
return _node.Render(ctx);
}

object ITemplate.Render(object? context)
object ITemplate.Render(object? context, TemplateFunctionSet? functions)
{
var ctx = new TemplateContextAccessor(TemplateDataAccessor.Create(context), Metadata, library: LocalLibrary);
var ctx = new TemplateContextAccessor(TemplateDataAccessor.Create(context), Metadata, functions: functions, library: LocalLibrary);
return _node.Render(ctx);
}
}
Expand Down
Loading