Skip to main content
The GeneratorParams class controls the behavior of text generation, including search strategies, sampling parameters, and output constraints.

Constructor

GeneratorParams(Model model)

Creates a new generator parameters instance.
Model
required
The model to create parameters for
GeneratorParams.cs:15-18

Search Option Methods

SetSearchOption(string searchOption, double value)

Sets a numeric search option (e.g., temperature, top_p, max_length).
string
required
The name of the search option to set
double
required
The numeric value for the option
GeneratorParams.cs:22-25

SetSearchOption(string searchOption, bool value)

Sets a boolean search option (e.g., do_sample).
string
required
The name of the search option to set
bool
required
The boolean value for the option
GeneratorParams.cs:27-30

GetSearchNumber(string searchOption)

Retrieves the value of a numeric search option.
string
required
The name of the search option to retrieve
Returns: double - The current value of the option
GeneratorParams.cs:37-41

GetSearchBool(string searchOption)

Retrieves the value of a boolean search option.
string
required
The name of the search option to retrieve
Returns: bool - The current value of the option
GeneratorParams.cs:43-47

Guidance Methods

SetGuidance(string type, string data, bool enableFFTokens = false)

Sets structured output guidance (JSON schema or grammar) to constrain the model’s output.
string
required
The type of guidance: “json_schema” or “lark_grammar”
string
required
The guidance specification (JSON schema or LARK grammar string)
bool
default:"false"
Whether to enable fast-forward tokens
GeneratorParams.cs:32-35

Common Search Options

Here are the most commonly used search options:

Generation Length

int
Minimum number of tokens to generate (including prompt)
int
Maximum number of tokens to generate (including prompt)

Sampling Parameters

bool
Enable random sampling. When false, uses greedy or beam search
double
Controls randomness. Higher values (e.g., 1.0) make output more random, lower values (e.g., 0.1) make it more deterministic
double
Nucleus sampling: only sample from tokens with cumulative probability mass of top_p
int
Only sample from the top K most likely tokens

Penalty Parameters

double
Penalty for repeating tokens. Values > 1.0 discourage repetition

Beam Search Parameters

int
Number of beams for beam search. 1 means greedy search
int
Number of sequences to return (must be ≤ num_beams)

Batch Parameters

int
Batch size for processing multiple prompts

Complete Examples

Basic Generation Configuration

Creative vs Deterministic Generation

Beam Search Configuration

Structured Output with JSON Schema

examples/csharp/ModelChat/Program.cs:166-170

Complete Example from Source

examples/csharp/Common/Common.cs:134-159

See Also