Class GoogleAIService
public class GoogleAIService : AIService, IAIService, IFunctionRegisterable
- Inheritance
-
GoogleAIService
- Implements
- Inherited Members
- Extension Methods
Constructors
GoogleAIService(string, HttpClient)
public GoogleAIService(string apiKey, HttpClient httpClient)
Parameters
apiKeystringhttpClientHttpClient
GoogleAIService(string, string, HttpClient)
Creates a GoogleAIService with a specific model.
public GoogleAIService(string apiKey, string model, HttpClient httpClient)
Parameters
apiKeystringmodelstringhttpClientHttpClient
Properties
Provider
The AI provider for this service
public override string Provider { get; }
Property Value
ThinkingBudget
Controls the thinking token budget for Gemini 2.5 models. Ignored when ThinkingLevel is set (Gemini 3 uses ThinkingLevel instead). -1: Dynamic (model decides automatically, default) 0: Disable thinking (Flash/Lite only, Pro minimum is 128) 128~32768: Specific token budget (Pro max: 32768, Flash/Lite max: 24576)
public int ThinkingBudget { get; set; }
Property Value
ThinkingLevel
Controls the thinking level for Gemini 3 models. Auto: Uses model default (High for Gemini 3). Gemini 3 Pro/Flash shared levels: Low, High (default) Gemini 3 Flash additional levels: Minimal, Medium Note: Do not set both ThinkingLevel and ThinkingBudget.
public GeminiThinkingLevel ThinkingLevel { get; set; }
Property Value
Methods
ApplyProviderSpecificRequestProfile(AIRequestProfile)
protected override Action ApplyProviderSpecificRequestProfile(AIRequestProfile profile)
Parameters
profileAIRequestProfile
Returns
CreateFunctionMessageRequest()
Creates HTTP request with function definitions
protected override HttpRequestMessage CreateFunctionMessageRequest()
Returns
CreateMessageRequest()
Creates the HTTP request message for the AI service
protected override HttpRequestMessage CreateMessageRequest()
Returns
CreateMessageWithImageUrl(string, string)
Downloads an image from URL for Gemini processing
public Task<Message> CreateMessageWithImageUrl(string prompt, string imageUrl)
Parameters
Returns
ExtractFunctionCall(string)
Extracts function call from API response
protected override (string content, FunctionCall functionCall) ExtractFunctionCall(string response)
Parameters
responsestring
Returns
ExtractResponseContent(string)
Extracts the response content from the API response
protected override string ExtractResponseContent(string responseContent)
Parameters
responseContentstring
Returns
GenerateImageAsync(string, string)
Generates an image from a text prompt
public override Task<byte[]> GenerateImageAsync(string prompt, string size = "1024x1024")
Parameters
Returns
GenerateImageUrlAsync(string, string)
Generates an image URL from a text prompt
public override Task<string> GenerateImageUrlAsync(string prompt, string size = "1024x1024")
Parameters
Returns
GetCompletionAsync(Message)
public override Task<string> GetCompletionAsync(Message message)
Parameters
messageMessage
Returns
GetCompletionWithImageAsync(string, string)
public override Task<string> GetCompletionWithImageAsync(string prompt, string imagePath)
Parameters
Returns
GetInputTokenCountAsync()
Gets the token count for the current conversation
public override Task<uint> GetInputTokenCountAsync()
Returns
GetInputTokenCountAsync(string)
Gets the token count for a specific prompt
public override Task<uint> GetInputTokenCountAsync(string prompt)
Parameters
promptstring
Returns
GetModelMaxOutputTokens()
Returns the maximum output tokens allowed for the current model. Override in each service to provide model-specific limits.
protected override uint GetModelMaxOutputTokens()
Returns
StreamCompletionAsync(Message, Func<string, Task>)
public override Task StreamCompletionAsync(Message message, Func<string, Task> messageReceivedAsync)
Parameters
Returns
StreamParseJson(string)
Parses streaming JSON data
protected override string StreamParseJson(string jsonData)
Parameters
jsonDatastring
Returns
StreamRoundAsync(StreamOptions, bool, FunctionCallingPolicy, CancellationToken)
Executes a single streaming round: sends an HTTP request, reads the SSE stream, yields chunks, and handles function execution if detected. Yield a FunctionResult to signal the template to continue to the next round; otherwise the stream ends.
protected override IAsyncEnumerable<StreamingContent> StreamRoundAsync(StreamOptions options, bool useFunctions, FunctionCallingPolicy policy, CancellationToken cancellationToken)
Parameters
optionsStreamOptionsuseFunctionsboolpolicyFunctionCallingPolicycancellationTokenCancellationToken