Search Results for

    Show / Hide Table of Contents

    Class GenerativeRequest<TSelf, TPrompt, TResult, TOptions>

    Abstract base class for all generative AI tasks. Provides common properties and methods for handling prompts, models, outputs, and execution.

    Inheritance
    object
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>
    GenerativeRequest<TSelf, TPrompt, TResult, TOptions>
    CountTokensRequest
    DetokenizationRequest
    EmbeddingRequest
    ModerationRequest
    OcrRequest
    PixelArtRequest<TSelf, TInput, TOptions>
    PixelRemoveBgRequest
    PixelSkeletonEstimationRequest
    StreamingGenerativeRequest<TSelf, TWire, TResult, TEvent, TOptions>
    TokenizationRequest
    Implements
    IGenerativeRequest
    Inherited Members
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.m_Api
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.Api
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.RequestType
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.HttpOptions
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.DownloadOptions
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.Sender
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.LogOptions
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ContentType
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ResponseType
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.IsCanceled
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.Stream
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SafetyIdentifier
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ServiceTier
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.Metadata
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ProviderOptions
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.Options
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetSender(string)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetLogOptions(CurlLogOptions)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetOutputPath(string)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetOutputPath(string, string)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetOutputDirectory(string)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetDownloadOptions(DownloadOptions)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetRequestMimeType(MimeType)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetResponseMimeType(MimeType)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetStream(bool)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetMetadata(ServerDictionary)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetSafetyIdentifier(string)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetProviderOptions(TOptions)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetSpecificOptions(TOptions)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ValidateRequest()
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.GetConfig<T>()
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.SetApi(Api)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ExecuteAsync(CancellationToken)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.Cancel()
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ExecuteAsyncInternal()
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ResolveDownloadOptions(DownloadOptions)
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.GenerateDefaultFileName()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Glitch9.AIDevKit
    Assembly: Glitch9.AIDevKit.dll
    Syntax
    public abstract class GenerativeRequest<TSelf, TPrompt, TResult, TOptions> : UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>, IGenerativeRequest where TSelf : GenerativeRequest<TSelf, TPrompt, TResult, TOptions> where TPrompt : IPrompt where TResult : class where TOptions : IProviderRequestOptions
    Type Parameters
    Name Description
    TSelf
    TPrompt
    TResult
    TOptions

    Constructors

    | Edit this page View Source

    GenerativeRequest()

    Declaration
    protected GenerativeRequest()
    | Edit this page View Source

    GenerativeRequest(TPrompt)

    Declaration
    protected GenerativeRequest(TPrompt prompt)
    Parameters
    Type Name Description
    TPrompt prompt

    Properties

    | Edit this page View Source

    Api

    The cloud service provider associated with this task. Automatically resolved from the selected model if not explicitly set.

    Declaration
    public override Api Api { get; }
    Property Value
    Type Description
    Api
    Overrides
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.Api
    | Edit this page View Source

    FallbackModel

    Declaration
    protected virtual string FallbackModel { get; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    FileNameKey

    Declaration
    protected virtual string FileNameKey { get; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    MeasureLatency

    Gets whether latency should be measured for this request.

    Declaration
    public bool MeasureLatency { get; set; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    Model

    Gets or sets the model identifier. It can be a provider model ID or deployment name.

    Declaration
    public string Model { get; set; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    ModelType

    Declaration
    public abstract ModelType ModelType { get; }
    Property Value
    Type Description
    ModelType
    | Edit this page View Source

    N

    The number of responses to generate. Must be between 1 and 10.

    Declaration
    public NCount N { get; set; }
    Property Value
    Type Description
    NCount
    | Edit this page View Source

    OnLatencyMeasured

    Gets callback invoked with measured latency (seconds).

    Declaration
    public Action<double> OnLatencyMeasured { get; set; }
    Property Value
    Type Description
    Action<double>
    | Edit this page View Source

    Prompt

    The prompt used for generation. Can be a text, audio, or custom prompt type.

    Declaration
    public virtual TPrompt Prompt { get; set; }
    Property Value
    Type Description
    TPrompt
    | Edit this page View Source

    RecordOptions

    Gets generation-record behavior and callbacks.

    Declaration
    public GenerationRecordOptions RecordOptions { get; }
    Property Value
    Type Description
    GenerationRecordOptions
    | Edit this page View Source

    RecordedContext

    Gets recorded curl/request context for diagnostics.

    Declaration
    public CurlContext RecordedContext { get; }
    Property Value
    Type Description
    CurlContext
    | Edit this page View Source

    RequestedAt

    Gets the request timestamp captured when dispatch starts.

    Declaration
    public DateTime RequestedAt { get; }
    Property Value
    Type Description
    DateTime
    | Edit this page View Source

    Seed

    Random seed for deterministic sampling (when supported):

    • Purpose — Reproduce the same output across runs with identical inputs.
    • Scope — Holds only if provider, model/deployment, version, and all params are unchanged.
    • null — Lets the service choose a random seed (non-deterministic).
    • Range — 0–9,223,372,036,854,775,807 (signed 64-bit long).
    • Support — Some models/services ignore seeds; if unsupported, this has no effect.
    Declaration
    public Seed Seed { get; set; }
    Property Value
    Type Description
    Seed

    Methods

    | Edit this page View Source

    ExecuteAsync(CancellationToken)

    Executes the task and returns the output of type TResult. This is the main entry point for executing the task.

    Declaration
    public override sealed UniTask<Generated<TResult>> ExecuteAsync(CancellationToken ct = default)
    Parameters
    Type Name Description
    CancellationToken ct
    Returns
    Type Description
    UniTask<Generated<TResult>>
    Overrides
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ExecuteAsync(CancellationToken)
    | Edit this page View Source

    ExecuteAsyncT<T>(CancellationToken)

    Executes the request and casts the generated asset to T.

    Declaration
    public UniTask<Generated<T>> ExecuteAsyncT<T>(CancellationToken ct = default) where T : class
    Parameters
    Type Name Description
    CancellationToken ct

    Cancellation token.

    Returns
    Type Description
    UniTask<Generated<T>>
    Type Parameters
    Name Description
    T

    Target generated asset type.

    | Edit this page View Source

    GenerateDefaultFileName()

    Generates a default file name for downloaded content. Override in derived classes to provide type-specific file naming.

    Declaration
    protected override string GenerateDefaultFileName()
    Returns
    Type Description
    string
    Overrides
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.GenerateDefaultFileName()
    | Edit this page View Source

    GetPrompt()

    Gets the prompt payload used to build this request.

    Declaration
    public IPrompt GetPrompt()
    Returns
    Type Description
    IPrompt
    | Edit this page View Source

    GetPromptStringToRecord()

    Gets a prompt string suitable for history/recording.

    Declaration
    public string GetPromptStringToRecord()
    Returns
    Type Description
    string
    | Edit this page View Source

    PrepareRequestAsync()

    Declaration
    protected UniTask PrepareRequestAsync()
    Returns
    Type Description
    UniTask
    | Edit this page View Source

    ProcessPostRequestTasks(IResult)

    Processes post-request tasks for raw results.

    Declaration
    public void ProcessPostRequestTasks(IResult result)
    Parameters
    Type Name Description
    IResult result

    Request result.

    | Edit this page View Source

    ProcessPostRequestTasks<T>(Generated<T>)

    Processes post-request tasks for generated outputs.

    Declaration
    public void ProcessPostRequestTasks<T>(Generated<T> result) where T : class
    Parameters
    Type Name Description
    Generated<T> result
    Type Parameters
    Name Description
    T

    Generated asset type.

    | Edit this page View Source

    ResolveDownloadOptions(DownloadOptions)

    Resolves download options for this

    Declaration
    protected override sealed DownloadOptions ResolveDownloadOptions(DownloadOptions options = null)
    Parameters
    Type Name Description
    DownloadOptions options
    Returns
    Type Description
    DownloadOptions
    Overrides
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ResolveDownloadOptions(DownloadOptions)
    | Edit this page View Source

    SetCount(int)

    Sets the number of outputs to generate (e.g., number of images or responses).

    Declaration
    public TSelf SetCount(int count)
    Parameters
    Type Name Description
    int count
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    SetMeasureLatency(Action<double>)

    Declaration
    public TSelf SetMeasureLatency(Action<double> onLatencyMeasured)
    Parameters
    Type Name Description
    Action<double> onLatencyMeasured
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    SetMeasureLatency(bool, Action<double>)

    Declaration
    public TSelf SetMeasureLatency(bool measureLatency = true, Action<double> onLatencyMeasured = null)
    Parameters
    Type Name Description
    bool measureLatency
    Action<double> onLatencyMeasured
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    SetModel(Api, string)

    Sets the AI model with Provider API and model ID.

    • Added new on 2025.07.17
    Declaration
    public TSelf SetModel(Api api, string modelId)
    Parameters
    Type Name Description
    Api api
    string modelId
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    SetModel(ModelBase)

    Sets the AI model to be used for generation.

    Declaration
    public TSelf SetModel(ModelBase model)
    Parameters
    Type Name Description
    ModelBase model
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    SetN(int)

    Sets the number of outputs to generate (e.g., number of images or responses).

    Declaration
    public TSelf SetN(int n)
    Parameters
    Type Name Description
    int n
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    SetPlaygroundSettings(string, string, string, bool, Action<double>, Action<GenerationRecord>)

    Applies editor playground settings used for generation history and diagnostics.

    Declaration
    public void SetPlaygroundSettings(string sender, string fileName, string selectedPath, bool measureLatency = true, Action<double> onLatencyMeasured = null, Action<GenerationRecord> onRecordCreated = null)
    Parameters
    Type Name Description
    string sender

    Playground sender identifier.

    string fileName

    Requested output file name.

    string selectedPath

    Selected output directory path.

    bool measureLatency

    Whether to force latency measurement.

    Action<double> onLatencyMeasured

    Latency callback.

    Action<GenerationRecord> onRecordCreated

    Record-created callback.

    | Edit this page View Source

    SetRecordOptions(GenerationRecordOptions)

    Declaration
    public TSelf SetRecordOptions(GenerationRecordOptions recordOptions)
    Parameters
    Type Name Description
    GenerationRecordOptions recordOptions
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    SetRecordOptions(bool?, bool?, string, string, GenerationRecord, RecordMerger, Action<GenerationRecord>)

    Enables or disables prompt history for this task.

    Declaration
    public TSelf SetRecordOptions(bool? write = null, bool? archive = null, string recordId = null, string prompt = null, GenerationRecord recordToMerge = null, RecordMerger merger = null, Action<GenerationRecord> onCreated = null)
    Parameters
    Type Name Description
    bool? write
    bool? archive
    string recordId
    string prompt
    GenerationRecord recordToMerge
    RecordMerger merger
    Action<GenerationRecord> onCreated
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    SetSeed(long)

    Sets a fixed seed to make generation deterministic and repeatable.

    Declaration
    public TSelf SetSeed(long seed)
    Parameters
    Type Name Description
    long seed
    Returns
    Type Description
    TSelf
    | Edit this page View Source

    ValidateRequest()

    Validates the request before execution. Override in derived classes to implement request validation logic.

    Declaration
    protected override void ValidateRequest()
    Overrides
    UnifiedApiRequestBase<TSelf, Generated<TResult>, TOptions>.ValidateRequest()

    Implements

    IGenerativeRequest

    Extension Methods

    ArrayExtensions.ToArrayOrEmpty<T>(T)
    ArrayExtensions.ToArrayOrNull<T>(T)
    EventExtensions.ToDelta<T>(T, string, int, string, bool)
    EventExtensions.ToDone<T>(T, string, int, string)
    EventExtensions.ToEvent<T>(T)
    EventExtensions.UpcastDelta<T1, T2>(T1, string, int, string, bool)
    FallbackExtensions.IsOr<TParent, TChild>(TParent, TChild)
    ResponseCastingExtensions.GetResult<T>(T)
    SystemExtensions.GetName(object)
    • Edit this page
    • View Source
    In this article
    Back to top AI DevKit Documentation