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
Returns
AskOnceAsync(AIService, string)
Performs a one-time question without affecting the conversation history
public static Task<string> AskOnceAsync(this AIService service, string prompt)
Parameters
Returns
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
Returns
BeginMessage(AIService)
Creates a fluent chain for building and sending a message
public static MessageChain BeginMessage(this AIService service)
Parameters
serviceAIService
Returns
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
Returns
GetConversationSummary(AIService)
Gets the conversation summary
public static string GetConversationSummary(this AIService service)
Parameters
serviceAIService
Returns
GetLastAssistantResponse(AIService)
Gets the last assistant response from the conversation
public static string? GetLastAssistantResponse(this AIService service)
Parameters
serviceAIService
Returns
RetryLastMessageAsync(AIService)
Retries the last user message if the previous response was unsatisfactory
public static Task<string> RetryLastMessageAsync(this AIService service)
Parameters
serviceAIService
Returns
StartNewConversation(AIService)
Starts a new conversation, clearing the current history
public static void StartNewConversation(this AIService service)
Parameters
serviceAIService
StartNewConversation(AIService, string)
Starts a new conversation with a different model
public static void StartNewConversation(this AIService service, string model)
Parameters
SwitchModel(AIService, string)
Switches to a different model while preserving conversation history
public static void SwitchModel(this AIService service, string model)
Parameters
WithComplexPolicy(AIService)
๋ณต์กํ ์์ ์ ์ฑ
public static AIService WithComplexPolicy(this AIService service)
Parameters
serviceAIService
Returns
WithFastPolicy(AIService)
๋น ๋ฅธ ์คํ ์ ์ฑ
public static AIService WithFastPolicy(this AIService service)
Parameters
serviceAIService
Returns
WithMaxRounds(AIService, int)
์ปค์คํ ๋ผ์ด๋ ์ ํ
public static AIService WithMaxRounds(this AIService service, int rounds)
Parameters
Returns
WithMaxTokens(AIService, uint)
Configures the max tokens for the current chat
public static AIService WithMaxTokens(this AIService service, uint maxTokens)
Parameters
Returns
WithNoRetryStructuredOutput(AIService)
retry ์์ด 1ํ๋ง ์๋ํ๋ structured output ์ ์ฑ
public static AIService WithNoRetryStructuredOutput(this AIService service)
Parameters
serviceAIService
Returns
WithPolicy(AIService, FunctionCallingPolicy)
์ผํ์ฑ ์ ์ฑ ์ค๋ฒ๋ผ์ด๋ (Fluent ์คํ์ผ)
public static AIService WithPolicy(this AIService service, FunctionCallingPolicy policy)
Parameters
serviceAIServicepolicyFunctionCallingPolicy
Returns
WithStatelessMode(AIService, bool)
Enables or disables stateless mode
public static AIService WithStatelessMode(this AIService service, bool enabled = true)
Parameters
Returns
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
serviceTconfigureAction<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
serviceAIService
Returns
WithStructuredOutputPolicy(AIService, StructuredOutputPolicy)
์ผํ์ฑ structured output ์ ์ฑ ์ค๋ฒ๋ผ์ด๋ (Fluent ์คํ์ผ). ๋ค์ GetCompletionAsync<T>() ํธ์ถ์๋ง ์ ์ฉ๋๋ฉฐ ํธ์ถ ํ ์๋์ผ๋ก ์ด๊ธฐํ๋ฉ๋๋ค.
public static AIService WithStructuredOutputPolicy(this AIService service, StructuredOutputPolicy policy)
Parameters
serviceAIServicepolicyStructuredOutputPolicy
Returns
WithSystemMessage(AIService, string)
Adds a system message to the current chat
public static AIService WithSystemMessage(this AIService service, string systemMessage)
Parameters
Returns
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
serviceAIServiceproviderFunc<AIRequestContext>
Returns
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
serviceAIServiceproviderFunc<CancellationToken, ValueTask<AIRequestContext>>
Returns
WithTemperature(AIService, float)
Configures the temperature for the current chat
public static AIService WithTemperature(this AIService service, float temperature)
Parameters
Returns
WithTimeout(AIService, int)
์ปค์คํ ํ์์์
public static AIService WithTimeout(this AIService service, int seconds)