Class GenerativeRequest<TSelf, TInput, TOutput, TChunk, TEvent>
Abstract base class for all generative AI tasks. Provides common properties and methods for handling prompts, models, outputs, and execution.
public abstract class GenerativeRequest<TSelf, TInput, TOutput, TChunk, TEvent> : FluentApiRequest<TSelf, TOutput>, IGenerativeRequest, ISequentialRequest where TSelf : GenerativeRequest<TSelf, TInput, TOutput, TChunk, TEvent> where TInput : IPrompt where TOutput : IGeneratedOutput where TEvent : IGenerativeEvent<TChunk, TOutput>
Type Parameters
TSelfTInputTOutputTChunkTEvent
- Inheritance
-
objectFluentApiRequest<TSelf, TOutput>GenerativeRequest<TSelf, TInput, TOutput, TChunk, TEvent>
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
GenerativeRequest()
protected GenerativeRequest()
GenerativeRequest(TInput)
protected GenerativeRequest(TInput prompt)
Parameters
promptTInput
Properties
Api
The cloud service provider associated with this task. Automatically resolved from the selected model if not explicitly set.
public override Api Api { get; set; }
Property Value
ArchiveHistory
If true, the prompt and output history will be archived (hidden) after saving.
public bool ArchiveHistory { get; set; }
Property Value
- bool
MaxN
The maximum number of outputs allowed for the selected model.
Added new on 2025.07.17
public int MaxN { get; }
Property Value
- int
MeasureLatency
If true, the system will measure the elapsed time from when the request is sent until the response is received.
public bool MeasureLatency { get; set; }
Property Value
- bool
Model
The identifier of the model to use for this task. Matches the model deployment name or model ID provided by the API.
public string Model { get; set; }
Property Value
- string
ModelType
public abstract ModelType ModelType { get; }
Property Value
N
The number of responses to generate. Must be between 1 and 10.
public NCount N { get; set; }
Property Value
OnLatencyMeasured
public Action<double> OnLatencyMeasured { get; set; }
Property Value
- Action<double>
OnRecordCreated
The event listener that will be called when a new prompt record is created for this request.
public Action<AIRequestRecord> OnRecordCreated { get; set; }
Property Value
- Action<AIRequestRecord>
OutputFileNote
public string OutputFileNote { get; set; }
Property Value
- string
Prompt
The prompt used for generation. Can be a text, audio, or custom prompt type.
public virtual TInput Prompt { get; set; }
Property Value
- TInput
RecordHistory
Whether prompt history should be recorded for this task. Default is controlled by SavePromptHistoryOnRuntime.
public bool RecordHistory { get; set; }
Property Value
- bool
RecordId
A fixed seed value to make generation deterministic and repeatable.
public string RecordId { get; set; }
Property Value
- string
RecordMergeOptions
The record merge settings for this request.
- Added new on 2025.11.27
public RecordMergeOptions RecordMergeOptions { get; set; }
Property Value
RequestedAt
The timestamp when the request was initiated.
Only set when CountdownTimer is true.
public DateTime RequestedAt { get; }
Property Value
- DateTime
SaveOutputs
Whether generated outputs should be saved to disk.
public bool SaveOutputs { get; set; }
Property Value
- bool
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–4,294,967,295 (32-bit).
- Support – Some models/services ignore seeds; if unsupported, this has no effect.
public Seed Seed { get; set; }
Property Value
Methods
CreateStreamAsync()
public UniTask<IRESTStream<TEvent>> CreateStreamAsync()
Returns
- UniTask<IRESTStream<TEvent>>
CreateStreamAsyncInternal()
protected abstract UniTask<IRESTStream<TEvent>> CreateStreamAsyncInternal()
Returns
- UniTask<IRESTStream<TEvent>>
ExecuteAsync(CancellationToken)
Executes the task and returns the output of type TOutput.
This is the main entry point for executing the task.
public override sealed UniTask<TOutput> ExecuteAsync(CancellationToken ct = default)
Parameters
ctCancellationToken
Returns
- UniTask<TOutput>
ExecuteAsyncT<T>(CancellationToken)
public UniTask<T> ExecuteAsyncT<T>(CancellationToken ct = default) where T : IGeneratedOutput
Parameters
ctCancellationToken
Returns
- UniTask<T>
Type Parameters
T
GetPromptToRecord()
public IPrompt GetPromptToRecord()
Returns
GetRequestParameters()
public virtual Dictionary<string, object> GetRequestParameters()
Returns
- Dictionary<string, object>
ProcessPostRequestTasks(IGeneratedOutput)
public void ProcessPostRequestTasks(IGeneratedOutput output)
Parameters
outputIGeneratedOutput
ResolveOutputPath(string)
protected override sealed string ResolveOutputPath(string rawOutputPath = null)
Parameters
rawOutputPathstring
Returns
- string
SetCount(int)
Sets the number of outputs to generate (e.g., number of images or responses).
public TSelf SetCount(int count)
Parameters
countint
Returns
- TSelf
SetGeneratorWindowSettings(string, string, bool, Action<double>)
public void SetGeneratorWindowSettings(string sender, string outputPath, bool measureLatency = true, Action<double> onLatencyMeasured = null)
Parameters
senderstringoutputPathstringmeasureLatencyboolonLatencyMeasuredAction<double>
SetMeasureLatency(Action<double>)
public TSelf SetMeasureLatency(Action<double> onLatencyMeasured)
Parameters
onLatencyMeasuredAction<double>
Returns
- TSelf
SetMeasureLatency(bool, Action<double>)
public TSelf SetMeasureLatency(bool measureLatency = true, Action<double> onLatencyMeasured = null)
Parameters
measureLatencyboolonLatencyMeasuredAction<double>
Returns
- TSelf
SetModel(Api, string)
Sets the AI model with Provider API and model ID.
- Added new on 2025.07.17
public TSelf SetModel(Api api, string modelId)
Parameters
apiApimodelIdstring
Returns
- TSelf
SetModel(Model)
Sets the AI model to be used for generation.
public TSelf SetModel(Model model)
Parameters
modelModel
Returns
- TSelf
SetOutputPath(string, string)
Sets the download path for the generated content(s). This is the path where the generated content(s) will be saved.
public TSelf SetOutputPath(string outputPath = null, string outputNote = null)
Parameters
outputPathstringThe path where the generated content(s) will be saved.
outputNotestring
Returns
- TSelf
SetRecordHistoryOptions(bool?, bool?, string, TInput)
Enables or disables prompt history for this task.
public TSelf SetRecordHistoryOptions(bool? record = null, bool? archive = null, string recordId = null, TInput promptToRecord = default)
Parameters
recordbool?archivebool?recordIdstringpromptToRecordTInput
Returns
- TSelf
SetRecordMergeOptions(AIRequestRecord, Func<AIRequestRecord, AIRequestRecord, AIRequestRecord>)
public TSelf SetRecordMergeOptions(AIRequestRecord recordToMerge, Func<AIRequestRecord, AIRequestRecord, AIRequestRecord> mergeFunction)
Parameters
recordToMergeAIRequestRecordmergeFunctionFunc<AIRequestRecord, AIRequestRecord, AIRequestRecord>
Returns
- TSelf
SetRecordMergeOptions(RecordMergeOptions)
public TSelf SetRecordMergeOptions(RecordMergeOptions recordMergeOptions)
Parameters
recordMergeOptionsRecordMergeOptions
Returns
- TSelf
SetSeed(long)
Sets a fixed seed to make generation deterministic and repeatable.
public TSelf SetSeed(long seed)
Parameters
seedlong
Returns
- TSelf