Table of Contents

Class AIServiceExtensions

Namespace
Mythosia.AI.Extensions
Assembly
Mythosia.AI.dll

Extension methods for AIService to provide additional convenience features

public static class AIServiceExtensions
Inheritance
AIServiceExtensions
Inherited Members

Methods

AskOnceAsync(AIService, Message)

Performs a one-time multimodal question without affecting the conversation history

public static Task<string> AskOnceAsync(this AIService service, Message message)

Parameters

service AIService
message Message

Returns

Task<string>

AskOnceAsync(AIService, string)

Performs a one-time question without affecting the conversation history

public static Task<string> AskOnceAsync(this AIService service, string prompt)

Parameters

service AIService
prompt string

Returns

Task<string>

AskOnceWithImageAsync(AIService, string, string)

Performs a one-time question with an image

public static Task<string> AskOnceWithImageAsync(this AIService service, string prompt, string imagePath)

Parameters

service AIService
prompt string
imagePath string

Returns

Task<string>

BeginMessage(AIService)

Creates a fluent chain for building and sending a message

public static MessageChain BeginMessage(this AIService service)

Parameters

service AIService

Returns

MessageChain

GetCompletionWithContextAsync(AIService, string, int)

Adds context from previous messages to a new prompt

public static Task<string> GetCompletionWithContextAsync(this AIService service, string prompt, int contextMessages = 5)

Parameters

service AIService
prompt string
contextMessages int

Returns

Task<string>

GetConversationSummary(AIService)

Gets the conversation summary

public static string GetConversationSummary(this AIService service)

Parameters

service AIService

Returns

string

GetLastAssistantResponse(AIService)

Gets the last assistant response from the conversation

public static string? GetLastAssistantResponse(this AIService service)

Parameters

service AIService

Returns

string

RetryLastMessageAsync(AIService)

Retries the last user message if the previous response was unsatisfactory

public static Task<string> RetryLastMessageAsync(this AIService service)

Parameters

service AIService

Returns

Task<string>

StartNewConversation(AIService)

Starts a new conversation, clearing the current history

public static void StartNewConversation(this AIService service)

Parameters

service AIService

StartNewConversation(AIService, string)

Starts a new conversation with a different model

public static void StartNewConversation(this AIService service, string model)

Parameters

service AIService
model string

SwitchModel(AIService, string)

Switches to a different model while preserving conversation history

public static void SwitchModel(this AIService service, string model)

Parameters

service AIService
model string

WithComplexPolicy(AIService)

๋ณต์žกํ•œ ์ž‘์—… ์ •์ฑ…

public static AIService WithComplexPolicy(this AIService service)

Parameters

service AIService

Returns

AIService

WithFastPolicy(AIService)

๋น ๋ฅธ ์‹คํ–‰ ์ •์ฑ…

public static AIService WithFastPolicy(this AIService service)

Parameters

service AIService

Returns

AIService

WithMaxRounds(AIService, int)

์ปค์Šคํ…€ ๋ผ์šด๋“œ ์ œํ•œ

public static AIService WithMaxRounds(this AIService service, int rounds)

Parameters

service AIService
rounds int

Returns

AIService

WithMaxTokens(AIService, uint)

Configures the max tokens for the current chat

public static AIService WithMaxTokens(this AIService service, uint maxTokens)

Parameters

service AIService
maxTokens uint

Returns

AIService

WithNoRetryStructuredOutput(AIService)

retry ์—†์ด 1ํšŒ๋งŒ ์‹œ๋„ํ•˜๋Š” structured output ์ •์ฑ…

public static AIService WithNoRetryStructuredOutput(this AIService service)

Parameters

service AIService

Returns

AIService

WithPolicy(AIService, FunctionCallingPolicy)

์ผํšŒ์„ฑ ์ •์ฑ… ์˜ค๋ฒ„๋ผ์ด๋“œ (Fluent ์Šคํƒ€์ผ)

public static AIService WithPolicy(this AIService service, FunctionCallingPolicy policy)

Parameters

service AIService
policy FunctionCallingPolicy

Returns

AIService

WithStatelessMode(AIService, bool)

Enables or disables stateless mode

public static AIService WithStatelessMode(this AIService service, bool enabled = true)

Parameters

service AIService
enabled bool

Returns

AIService

WithStreamDiagnostics<T>(T, Action<StreamDiagnosticsBuilder>)

Registers diagnostic callbacks for SSE streaming on this service. Useful for observability and post-mortem analysis when a stream dies mid-flight against a self-hosted backend (vLLM, ollama, internal proxy). Each On* method on the builder is independent โ€” only call the ones you need.

Calling this method overwrites any previously registered diagnostics on the service. Pass d => { } to clear all callbacks.

public static T WithStreamDiagnostics<T>(this T service, Action<StreamDiagnosticsBuilder> configure) where T : AIService

Parameters

service T
configure Action<StreamDiagnosticsBuilder>

Returns

T

Type Parameters

T

Examples

// Wire raw SSE lines to Debug logger and aggregate metrics on completion
service.WithStreamDiagnostics(d => d
    .OnRawLine(line => logger.LogDebug("SSE: {Line}", line))
    .OnComplete(diag => metrics.Record(diag.LinesRead, diag.Elapsed)));

WithStrictStructuredOutput(AIService)

์ตœ๋Œ€ 3ํšŒ ์žฌ์‹œ๋„ํ•˜๋Š” ์—„๊ฒฉ structured output ์ •์ฑ…

public static AIService WithStrictStructuredOutput(this AIService service)

Parameters

service AIService

Returns

AIService

WithStructuredOutputPolicy(AIService, StructuredOutputPolicy)

์ผํšŒ์„ฑ structured output ์ •์ฑ… ์˜ค๋ฒ„๋ผ์ด๋“œ (Fluent ์Šคํƒ€์ผ). ๋‹ค์Œ GetCompletionAsync<T>() ํ˜ธ์ถœ์—๋งŒ ์ ์šฉ๋˜๋ฉฐ ํ˜ธ์ถœ ํ›„ ์ž๋™์œผ๋กœ ์ดˆ๊ธฐํ™”๋ฉ๋‹ˆ๋‹ค.

public static AIService WithStructuredOutputPolicy(this AIService service, StructuredOutputPolicy policy)

Parameters

service AIService
policy StructuredOutputPolicy

Returns

AIService

WithSystemMessage(AIService, string)

Adds a system message to the current chat

public static AIService WithSystemMessage(this AIService service, string systemMessage)

Parameters

service AIService
systemMessage string

Returns

AIService

WithSystemMessageProvider(AIService, Func<AIRequestContext?>)

Registers a synchronous AIRequestContext provider that the service invokes automatically before every outbound request (including agent-path calls), so callers do not have to build and pass an AIRequestContext at every entry point. If a call also supplies an explicit context, the two are merged field-by-field (explicit wins on scalar fields; additional messages are concatenated).

public static AIService WithSystemMessageProvider(this AIService service, Func<AIRequestContext?> provider)

Parameters

service AIService
provider Func<AIRequestContext>

Returns

AIService

WithSystemMessageProvider(AIService, Func<CancellationToken, ValueTask<AIRequestContext?>>)

Registers an asynchronous AIRequestContext provider. Use this overload when the baseline context requires IO (database, cache, HTTP) so that the provider does not need to block on .Result or .GetAwaiter().GetResult(). The supplied CancellationToken is the caller's token for the current LLM call (for non-streaming paths it is None). Merge semantics are identical to the synchronous overload.

public static AIService WithSystemMessageProvider(this AIService service, Func<CancellationToken, ValueTask<AIRequestContext?>> provider)

Parameters

service AIService
provider Func<CancellationToken, ValueTask<AIRequestContext>>

Returns

AIService

WithTemperature(AIService, float)

Configures the temperature for the current chat

public static AIService WithTemperature(this AIService service, float temperature)

Parameters

service AIService
temperature float

Returns

AIService

WithTimeout(AIService, int)

์ปค์Šคํ…€ ํƒ€์ž„์•„์›ƒ

public static AIService WithTimeout(this AIService service, int seconds)

Parameters

service AIService
seconds int

Returns

AIService