Table of Contents

Class GoogleAIService

Namespace
Mythosia.AI.Services.Google
Assembly
Mythosia.AI.dll
public class GoogleAIService : AIService, IAIService, IAIRunService, IAIRequestFeatureService, IFunctionRegisterable, IAIProcessingInfoService, IImageGenerationService
Inheritance
GoogleAIService
Implements
Inherited Members
Extension Methods

Constructors

GoogleAIService(string, HttpClient)

public GoogleAIService(string apiKey, HttpClient httpClient)

Parameters

apiKey string
httpClient HttpClient

GoogleAIService(string, string, HttpClient)

Creates a GoogleAIService with a specific model.

public GoogleAIService(string apiKey, string model, HttpClient httpClient)

Parameters

apiKey string
model string
httpClient HttpClient

Properties

DangerousContentSafetyThreshold

Gemini dangerous-content-filter threshold.

public GeminiSafetyThreshold DangerousContentSafetyThreshold { get; set; }

Property Value

GeminiSafetyThreshold

DefaultImageModel

The image model used when a request does not specify one explicitly. This is independent from the chat model exposed by Model.

public string DefaultImageModel { get; }

Property Value

string

HarassmentSafetyThreshold

Gemini harassment-filter threshold.

public GeminiSafetyThreshold HarassmentSafetyThreshold { get; set; }

Property Value

GeminiSafetyThreshold

HateSpeechSafetyThreshold

Gemini hate-speech-filter threshold.

public GeminiSafetyThreshold HateSpeechSafetyThreshold { get; set; }

Property Value

GeminiSafetyThreshold

LastThinkingContent

The most recent non-streaming thought summary returned by Gemini, when requested.

public string? LastThinkingContent { get; }

Property Value

string

Provider

The AI provider for this service

public override string Provider { get; }

Property Value

string

SexuallyExplicitSafetyThreshold

Gemini sexually-explicit-content-filter threshold.

public GeminiSafetyThreshold SexuallyExplicitSafetyThreshold { get; set; }

Property Value

GeminiSafetyThreshold

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

int

ThinkingLevel

Controls the thinking level for Gemini 3 models. Auto uses the selected model's provider default. Gemini 3.8/3.6/3.5 Flash default to Medium, Flash-Lite defaults to Minimal, while 3 Flash Preview and Pro Preview default to High. Note: Do not set both ThinkingLevel and ThinkingBudget.

public GeminiThinkingLevel ThinkingLevel { get; set; }

Property Value

GeminiThinkingLevel

Methods

ApplyCapabilityRequestProfile(AIRequestProfile)

Applies only execution-local profile settings needed to describe capabilities.

protected override void ApplyCapabilityRequestProfile(AIRequestProfile profile)

Parameters

profile AIRequestProfile

Remarks

Common builder overrides are already captured. Custom providers may override this hook with SetExecutionSetting calls for native mode flags. Do not prepare execution, reserve token budgets, invoke callbacks, validate requests, or modify service/caller-owned state. Execution profile hooks are intentionally not called during inspection.

ApplyProviderSpecificRequestProfile(AIRequestProfile)

protected override Action ApplyProviderSpecificRequestProfile(AIRequestProfile profile)

Parameters

profile AIRequestProfile

Returns

Action

ApplyRequestProfile(AIRequestProfile)

protected override Action ApplyRequestProfile(AIRequestProfile profile)

Parameters

profile AIRequestProfile

Returns

Action

CaptureRequestSettings(IDictionary<string, object?>)

Captures provider and common defaults. Overrides copy native mutable option values.

protected override void CaptureRequestSettings(IDictionary<string, object?> settings)

Parameters

settings IDictionary<string, object>

CreateFunctionMessageRequest()

Creates HTTP request with function definitions

protected override HttpRequestMessage CreateFunctionMessageRequest()

Returns

HttpRequestMessage

CreateMessageRequest()

Creates the HTTP request message for the AI service

protected override HttpRequestMessage CreateMessageRequest()

Returns

HttpRequestMessage

CreateMessageWithImageUrl(string, string, CancellationToken)

Downloads an image from URL for Gemini processing

public Task<Message> CreateMessageWithImageUrl(string prompt, string imageUrl, CancellationToken cancellationToken = default)

Parameters

prompt string
imageUrl string
cancellationToken CancellationToken

Returns

Task<Message>

EditImagesAsync(ImageEditRequest, CancellationToken)

Generates one or more images using existing images as references.

public Task<ImageGenerationResult> EditImagesAsync(ImageEditRequest request, CancellationToken cancellationToken = default)

Parameters

request ImageEditRequest
cancellationToken CancellationToken

Returns

Task<ImageGenerationResult>

ExtractFunctionCalls(string)

Extracts every function call from one API response.

protected override (string content, FunctionCallBatch functionCalls) ExtractFunctionCalls(string response)

Parameters

response string

Returns

(string content, FunctionCallBatch functionCalls)

ExtractResponseContent(string)

Extracts the response content from the API response

protected override string ExtractResponseContent(string responseContent)

Parameters

responseContent string

Returns

string

GenerateImagesAsync(ImageGenerationRequest, CancellationToken)

Generates one or more images from a text prompt.

public Task<ImageGenerationResult> GenerateImagesAsync(ImageGenerationRequest request, CancellationToken cancellationToken = default)

Parameters

request ImageGenerationRequest
cancellationToken CancellationToken

Returns

Task<ImageGenerationResult>

GetCompletionAsync(Message)

public override Task<string> GetCompletionAsync(Message message)

Parameters

message Message

Returns

Task<string>

GetCompletionWithImageAsync(string, string, CancellationToken)

public override Task<string> GetCompletionWithImageAsync(string prompt, string imagePath, CancellationToken cancellationToken = default)

Parameters

prompt string
imagePath string
cancellationToken CancellationToken

Returns

Task<string>

GetCompletionWithImageUrlAsync(string, string, CancellationToken)

public override Task<string> GetCompletionWithImageUrlAsync(string prompt, string imageUrl, CancellationToken cancellationToken = default)

Parameters

prompt string
imageUrl string
cancellationToken CancellationToken

Returns

Task<string>

GetImageCapabilities(string?)

Inspects an image generation model independently of the selected chat model, without HTTP.

public override ImageModelCapabilities GetImageCapabilities(string? model = null)

Parameters

model string

Returns

ImageModelCapabilities

Remarks

A null model uses the provider's image default. Unknown does not mean unsupported.

GetInputTokenCountAsync()

Gets the token count for the current conversation

public override Task<uint> GetInputTokenCountAsync()

Returns

Task<uint>

GetInputTokenCountAsync(string)

Gets the token count for a specific prompt

public override Task<uint> GetInputTokenCountAsync(string prompt)

Parameters

prompt string

Returns

Task<uint>

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

uint

ResolveRequestCapabilities()

Resolves adapter support using RequestSetting and CurrentRequestFeatures without side effects.

protected override AIModelCapabilities ResolveRequestCapabilities()

Returns

AIModelCapabilities

Remarks

Custom providers may override this hook. The default preserves compatibility by returning Unknown. Overrides must not send requests, consume options, change history or invoke user callbacks.

ResolveSpeedSupport(InferenceSpeed)

Locally resolves processing-mode support without checking account entitlement or live capacity.

protected override CapabilitySupport ResolveSpeedSupport(InferenceSpeed speed)

Parameters

speed InferenceSpeed

Returns

CapabilitySupport

StreamCompletionAsync(Message, Func<string, Task>)

public override Task StreamCompletionAsync(Message message, Func<string, Task> messageReceivedAsync)

Parameters

message Message
messageReceivedAsync Func<string, Task>

Returns

Task

StreamParseJson(string)

Parses streaming JSON data

protected override string StreamParseJson(string jsonData)

Parameters

jsonData string

Returns

string

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. Pending native asynchronous calls also keep the round loop active until their results have been delivered and the model finishes.

protected override IAsyncEnumerable<StreamingContent> StreamRoundAsync(StreamOptions options, bool useFunctions, FunctionCallingPolicy policy, CancellationToken cancellationToken)

Parameters

options StreamOptions
useFunctions bool
policy FunctionCallingPolicy
cancellationToken CancellationToken

Returns

IAsyncEnumerable<StreamingContent>

ValidateRequestFeatures(AIRequestFeatures)

Reject unsupported features before any network request or history mutation.

protected override void ValidateRequestFeatures(AIRequestFeatures features)

Parameters

features AIRequestFeatures