Interface
public interface IAiContextBuilder

Namespace: Moka.Blazor.AI.Services

Provides domain-specific context for the AI assistant. Implementors extract relevant content from their data source (JSON document, code file, etc.) to include in the AI prompt.

Methods

NameDescription
BuildContext(AiChatOptions options) abstract Builds a context string from the source data, respecting the max context size. Implementations should check IAiContextBuilder.GetScopes to narrow the context when scopes have been set.
ClearScope(string? key) virtual Clears a named scope, or all scopes if key is null.
GetScopes() virtual Returns all currently active scopes.
SetScope(string key, object? data) virtual Sets a named scope to focus context building on specific data. For example, a JSON context builder might accept a "path" scope to return only a subtree instead of the full document.

BuildContext(AiChatOptions options)

string IAiContextBuilder.BuildContext(AiChatOptions options)

Builds a context string from the source data, respecting the max context size. Implementations should check IAiContextBuilder.GetScopes to narrow the context when scopes have been set.

Parameters

NameTypeDescription
optionsMoka.Blazor.AI.Models.AiChatOptionsAI options including AiChatOptions.MaxContextChars.

Returns: Context string to include in the system prompt.

ClearScope(string? key)

void IAiContextBuilder.ClearScope(string? key = null)

Clears a named scope, or all scopes if key is null.

Parameters

NameTypeDescription
keystring?Scope to clear, or null to clear all.

GetScopes()

IReadOnlyDictionary<string, object?> IAiContextBuilder.GetScopes()

Returns all currently active scopes.

SetScope(string key, object? data)

void IAiContextBuilder.SetScope(string key, object? data)

Sets a named scope to focus context building on specific data. For example, a JSON context builder might accept a "path" scope to return only a subtree instead of the full document.

Parameters

NameTypeDescription
keystringScope identifier (e.g. "path", "selection", "object").
dataobject?Scope data whose type depends on the implementation.
View Source
/// <summary>
///     Provides domain-specific context for the AI assistant.
///     Implementors extract relevant content from their data source (JSON document, code file, etc.)
///     to include in the AI prompt.
/// </summary>
public interface IAiContextBuilder
{
    /// <summary>
    ///     Builds a context string from the source data, respecting the max context size.
    ///     Implementations should check <see cref = "GetScopes"/> to narrow the context
    ///     when scopes have been set.
    /// </summary>
    /// <param name = "options">AI options including <see cref = "AiChatOptions.MaxContextChars"/>.</param>
    /// <returns>Context string to include in the system prompt.</returns>
    string BuildContext(AiChatOptions options);
    /// <summary>
    ///     Sets a named scope to focus context building on specific data.
    ///     For example, a JSON context builder might accept a <c>"path"</c> scope
    ///     to return only a subtree instead of the full document.
    /// </summary>
    /// <param name = "key">Scope identifier (e.g. "path", "selection", "object").</param>
    /// <param name = "data">Scope data whose type depends on the implementation.</param>
    void SetScope(string key, object? data)
    {
    }

    /// <summary>
    ///     Clears a named scope, or all scopes if <paramref name = "key"/> is <c>null</c>.
    /// </summary>
    /// <param name = "key">Scope to clear, or <c>null</c> to clear all.</param>
    void ClearScope(string? key = null)
    {
    }

    /// <summary>
    ///     Returns all currently active scopes.
    /// </summary>
    IReadOnlyDictionary<string, object?> GetScopes() => new Dictionary<string, object?>();
}
Was this page helpful?