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
GenerativeRequest<TSelf, TPrompt, TResult, TOptions>
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
Overrides
|
Edit this page
View Source
FallbackModel
Declaration
protected virtual string FallbackModel { get; }
Property Value
|
Edit this page
View Source
FileNameKey
Declaration
protected virtual string FileNameKey { get; }
Property Value
|
Edit this page
View Source
MeasureLatency
Gets whether latency should be measured for this request.
Declaration
public bool MeasureLatency { get; set; }
Property Value
|
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
|
Edit this page
View Source
ModelType
Declaration
public abstract ModelType ModelType { get; }
Property Value
|
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
|
Edit this page
View Source
OnLatencyMeasured
Gets callback invoked with measured latency (seconds).
Declaration
public Action<double> OnLatencyMeasured { get; set; }
Property Value
|
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
|
Edit this page
View Source
RecordOptions
Gets generation-record behavior and callbacks.
Declaration
public GenerationRecordOptions RecordOptions { get; }
Property Value
|
Edit this page
View Source
RecordedContext
Gets recorded curl/request context for diagnostics.
Declaration
public CurlContext RecordedContext { get; }
Property Value
|
Edit this page
View Source
RequestedAt
Gets the request timestamp captured when dispatch starts.
Declaration
public DateTime RequestedAt { get; }
Property Value
|
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
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
Returns
Overrides
|
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
Returns
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
Overrides
|
Edit this page
View Source
GetPrompt()
Gets the prompt payload used to build this request.
Declaration
public IPrompt GetPrompt()
Returns
|
Edit this page
View Source
GetPromptStringToRecord()
Gets a prompt string suitable for history/recording.
Declaration
public string GetPromptStringToRecord()
Returns
|
Edit this page
View Source
PrepareRequestAsync()
Declaration
protected UniTask PrepareRequestAsync()
Returns
|
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 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
Returns
Overrides
|
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
|
Edit this page
View Source
SetMeasureLatency(Action<double>)
Declaration
public TSelf SetMeasureLatency(Action<double> onLatencyMeasured)
Parameters
Returns
|
Edit this page
View Source
SetMeasureLatency(bool, Action<double>)
Declaration
public TSelf SetMeasureLatency(bool measureLatency = true, Action<double> onLatencyMeasured = null)
Parameters
Returns
|
Edit this page
View Source
SetModel(Api, string)
Sets the AI model with Provider API and model ID.
Declaration
public TSelf SetModel(Api api, string modelId)
Parameters
Returns
|
Edit this page
View Source
SetModel(ModelBase)
Sets the AI model to be used for generation.
Declaration
public TSelf SetModel(ModelBase model)
Parameters
Returns
|
Edit this page
View Source
SetN(int)
Sets the number of outputs to generate (e.g., number of images or responses).
Declaration
Parameters
| Type |
Name |
Description |
| int |
n |
|
Returns
|
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
Returns
|
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
Returns
|
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
|
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
Implements
Extension Methods