Table of Contents

Class DeepSeekService

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

Constructors

DeepSeekService(string, HttpClient)

public DeepSeekService(string apiKey, HttpClient httpClient)

Parameters

apiKey string
httpClient HttpClient

DeepSeekService(string, string, HttpClient)

Creates a DeepSeekService with a specific model.

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

Parameters

apiKey string
model string
httpClient HttpClient

Properties

Provider

The AI provider for this service

public override string Provider { get; }

Property Value

string

ReasoningEffort

Persistent thinking effort. Auto leaves the provider's High default intact.

public DeepSeekReasoning ReasoningEffort { get; set; }

Property Value

DeepSeekReasoning

ThinkingEnabled

Enables server-side thinking before the final answer. Disabled by default.

public bool ThinkingEnabled { get; set; }

Property Value

bool

UseResponsesApi

Uses the stateless Responses endpoint for completion, streaming and tool rounds. False preserves the default Chat Completions transport. Captured per logical request.

public bool UseResponsesApi { get; set; }

Property Value

bool

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

CaptureProviderRequestOptions(Message)

Captures and consumes provider-specific per-request options before execution starts.

protected override object? CaptureProviderRequestOptions(Message message)

Parameters

message Message

Returns

object

Remarks

Framework delegation and tool rounds reuse the returned snapshot; new public calls capture independently. Internal summary and rewrite work do not call this hook and do not inherit these options.

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>

CloneProviderRequestOptions(object?)

Creates fresh provider execution state when a prepared request is executed again.

protected override object? CloneProviderRequestOptions(object? options)

Parameters

options object

Returns

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

DeleteFileAsync(string, CancellationToken)

Deletes the specified stored image and returns the server's acknowledgement.

public Task<DeepSeekFileDeletion> DeleteFileAsync(string fileId, CancellationToken cancellationToken = default)

Parameters

fileId string
cancellationToken CancellationToken

Returns

Task<DeepSeekFileDeletion>

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

GetCompletionAsync(Message)

public override Task<string> GetCompletionAsync(Message message)

Parameters

message Message

Returns

Task<string>

GetCompletionWithCoTAsync(string, CancellationToken)

Gets completion with Chain of Thought prompting

public Task<string> GetCompletionWithCoTAsync(string prompt, CancellationToken cancellationToken = default)

Parameters

prompt string
cancellationToken CancellationToken

Returns

Task<string>

GetCompletionWithImageAsync(string, string, CancellationToken)

Reads an image and sends it with the prompt to a vision-capable DeepSeek model.

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

Parameters

prompt string
imagePath string
cancellationToken CancellationToken

Returns

Task<string>

GetConversationCompactionBlockReason()

Returns a reason when protocol state requires retaining the original conversation prefix.

protected override string? GetConversationCompactionBlockReason()

Returns

string

GetFileAsync(string, CancellationToken)

Gets metadata for an uploaded image. The Files API does not document a content download endpoint.

public Task<DeepSeekFile> GetFileAsync(string fileId, CancellationToken cancellationToken = default)

Parameters

fileId string
cancellationToken CancellationToken

Returns

Task<DeepSeekFile>

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

GetRequestMessageOverrideTargetId()

Identifies the user input replaced by request context while tool rounds append messages.

protected override string? GetRequestMessageOverrideTargetId()

Returns

string

ListFilesAsync(DeepSeekFileListOptions?, CancellationToken)

Lists one page of uploaded images. Use the returned LastId as After to read the next page.

public Task<DeepSeekFileList> ListFilesAsync(DeepSeekFileListOptions? options = null, CancellationToken cancellationToken = default)

Parameters

options DeepSeekFileListOptions
cancellationToken CancellationToken

Returns

Task<DeepSeekFileList>

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.

StreamCompletionAsync(Message, Func<string, Task>)

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

Parameters

message Message
messageReceivedAsync Func<string, Task>

Returns

Task

StreamCoreAsync(Message, StreamOptions, CancellationToken)

Core streaming loop. Override this method to replace the full streaming pipeline (round loop, StatelessMode, summary policy). Most providers should override StreamRoundAsync(StreamOptions, bool, FunctionCallingPolicy, CancellationToken) instead.

protected override IAsyncEnumerable<StreamingContent> StreamCoreAsync(Message message, StreamOptions options, CancellationToken cancellationToken = default)

Parameters

message Message
options StreamOptions
cancellationToken CancellationToken

Returns

IAsyncEnumerable<StreamingContent>

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>

UploadFileAsync(Stream, string, int?, CancellationToken)

Uploads an image from the stream's current position. The caller retains ownership of the stream.

public Task<DeepSeekFile> UploadFileAsync(Stream image, string fileName, int? expiresAfterSeconds = null, CancellationToken cancellationToken = default)

Parameters

image Stream
fileName string
expiresAfterSeconds int?
cancellationToken CancellationToken

Returns

Task<DeepSeekFile>

Remarks

Reads at most 64 MiB into a temporary buffer before sending. The actual image signature determines its format.

UploadFileAsync(string, int?, CancellationToken)

Uploads a JPEG, PNG, GIF or WebP image for reuse by its file ID.

public Task<DeepSeekFile> UploadFileAsync(string imagePath, int? expiresAfterSeconds = null, CancellationToken cancellationToken = default)

Parameters

imagePath string

Local image file to upload.

expiresAfterSeconds int?

Lifetime from 3600 to 2592000 seconds, or null to keep permanently.

cancellationToken CancellationToken

Cancels local file reading, upload and response reading.

Returns

Task<DeepSeekFile>

UseReasonerModel()

Uses the current Flash model with thinking enabled for complex reasoning tasks.

public DeepSeekService UseReasonerModel()

Returns

DeepSeekService

ValidateProviderRequestOptions(object?, Message)

Validates captured native options against the completed request before history or HTTP changes.

protected override void ValidateProviderRequestOptions(object? options, Message message)

Parameters

options object
message Message

ValidateRequestFeatures(AIRequestFeatures)

Reject unsupported features before any network request or history mutation.

protected override void ValidateRequestFeatures(AIRequestFeatures features)

Parameters

features AIRequestFeatures

WithCodeGenerationMode(string)

Sets DeepSeek-specific parameters for code generation

public DeepSeekService WithCodeGenerationMode(string language = "python")

Parameters

language string

Returns

DeepSeekService

WithDeepSeekReasoning(DeepSeekReasoning)

Enables thinking and sets its persistent effort. Auto uses the provider default.

public DeepSeekService WithDeepSeekReasoning(DeepSeekReasoning effort = DeepSeekReasoning.High)

Parameters

effort DeepSeekReasoning

Returns

DeepSeekService

WithMathMode()

Optimizes settings for mathematical reasoning

public DeepSeekService WithMathMode()

Returns

DeepSeekService