Text Generation
Text generation allows you to create natural language output from a prompt using powerful large language models (LLMs) like GPT-4o, Gemini, and more.
This is commonly used for answering questions, summarizing content, writing marketing copy, or even creative writing.
✅ Basic Usage
Use the Fluent API to quickly create and execute a text generation task.
💡
GENText()
is an extension method forstring
, turning your prompt into a text generation task.
⚙️ Available Configuration
You can customize the task using the following fluent methods:
SetModel(model)
Choose the model to use (e.g., GPTModel.GPT4o
, GeminiModel.Gemini1_5Pro
).
SetInstruction(text)
Set a system-level instruction (defines tone/role).
SetStartingMessage(text)
Set the first assistant message to guide the response.
SetMaxOutputTokens(int)
Limit the maximum output length (in tokens).
SetTemperature(float)
Control randomness: 0.0
is focused, 1.0
is creative.
SetTopP(float)
Nucleus sampling: limit token selection to top probability P
.
SetTopK(float)
Limit selection to the top K
tokens (used by Gemini).
SetSeed(int)
Use a fixed seed for consistent output.
SetPresencePenalty(float)
Discourage repeated ideas.
SetFrequencyPenalty(float)
Discourage repeated words.
🚀 Streaming Output
For real-time applications like chat or narration, you can stream the output word-by-word:
✅ Supported only on models that support streaming (e.g., OpenAI GPT family).
📦 Example Result
🧠 Tips
You don’t need to manually handle
UniTask
cancellation unless you want to cancel early.The default model is defined in your project settings (
AIDevKitSettings.DefaultTextModel
).You can safely combine this with object generation if you want to extract structured data — see C# Object Generation.
Last updated