Class DeepSeekService
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
apiKeystringhttpClientHttpClient
DeepSeekService(string, string, HttpClient)
Creates a DeepSeekService with a specific model.
public DeepSeekService(string apiKey, string model, HttpClient httpClient)
Parameters
apiKeystringmodelstringhttpClientHttpClient
Properties
Provider
The AI provider for this service
public override string Provider { get; }
Property Value
ReasoningEffort
Persistent thinking effort. Auto leaves the provider's High default intact.
public DeepSeekReasoning ReasoningEffort { get; set; }
Property Value
ThinkingEnabled
Enables server-side thinking before the final answer. Disabled by default.
public bool ThinkingEnabled { get; set; }
Property Value
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
Methods
ApplyCapabilityRequestProfile(AIRequestProfile)
Applies only execution-local profile settings needed to describe capabilities.
protected override void ApplyCapabilityRequestProfile(AIRequestProfile profile)
Parameters
profileAIRequestProfile
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
profileAIRequestProfile
Returns
CaptureProviderRequestOptions(Message)
Captures and consumes provider-specific per-request options before execution starts.
protected override object? CaptureProviderRequestOptions(Message message)
Parameters
messageMessage
Returns
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
settingsIDictionary<string, object>
CloneProviderRequestOptions(object?)
Creates fresh provider execution state when a prepared request is executed again.
protected override object? CloneProviderRequestOptions(object? options)
Parameters
optionsobject
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
DeleteFileAsync(string, CancellationToken)
Deletes the specified stored image and returns the server's acknowledgement.
public Task<DeepSeekFileDeletion> DeleteFileAsync(string fileId, CancellationToken cancellationToken = default)
Parameters
fileIdstringcancellationTokenCancellationToken
Returns
ExtractFunctionCalls(string)
Extracts every function call from one API response.
protected override (string content, FunctionCallBatch functionCalls) ExtractFunctionCalls(string response)
Parameters
responsestring
Returns
ExtractResponseContent(string)
Extracts the response content from the API response
protected override string ExtractResponseContent(string responseContent)
Parameters
responseContentstring
Returns
GetCompletionAsync(Message)
public override Task<string> GetCompletionAsync(Message message)
Parameters
messageMessage
Returns
GetCompletionWithCoTAsync(string, CancellationToken)
Gets completion with Chain of Thought prompting
public Task<string> GetCompletionWithCoTAsync(string prompt, CancellationToken cancellationToken = default)
Parameters
promptstringcancellationTokenCancellationToken
Returns
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
promptstringimagePathstringcancellationTokenCancellationToken
Returns
GetConversationCompactionBlockReason()
Returns a reason when protocol state requires retaining the original conversation prefix.
protected override string? GetConversationCompactionBlockReason()
Returns
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
fileIdstringcancellationTokenCancellationToken
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
GetRequestMessageOverrideTargetId()
Identifies the user input replaced by request context while tool rounds append messages.
protected override string? GetRequestMessageOverrideTargetId()
Returns
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
optionsDeepSeekFileListOptionscancellationTokenCancellationToken
Returns
ResolveRequestCapabilities()
Resolves adapter support using RequestSetting and CurrentRequestFeatures without side effects.
protected override AIModelCapabilities ResolveRequestCapabilities()
Returns
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
Returns
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
messageMessageoptionsStreamOptionscancellationTokenCancellationToken
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. 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
optionsStreamOptionsuseFunctionsboolpolicyFunctionCallingPolicycancellationTokenCancellationToken
Returns
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
imageStreamfileNamestringexpiresAfterSecondsint?cancellationTokenCancellationToken
Returns
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
imagePathstringLocal image file to upload.
expiresAfterSecondsint?Lifetime from 3600 to 2592000 seconds, or null to keep permanently.
cancellationTokenCancellationTokenCancels local file reading, upload and response reading.
Returns
UseReasonerModel()
Uses the current Flash model with thinking enabled for complex reasoning tasks.
public DeepSeekService UseReasonerModel()
Returns
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
ValidateRequestFeatures(AIRequestFeatures)
Reject unsupported features before any network request or history mutation.
protected override void ValidateRequestFeatures(AIRequestFeatures features)
Parameters
featuresAIRequestFeatures
WithCodeGenerationMode(string)
Sets DeepSeek-specific parameters for code generation
public DeepSeekService WithCodeGenerationMode(string language = "python")
Parameters
languagestring
Returns
WithDeepSeekReasoning(DeepSeekReasoning)
Enables thinking and sets its persistent effort. Auto uses the provider default.
public DeepSeekService WithDeepSeekReasoning(DeepSeekReasoning effort = DeepSeekReasoning.High)
Parameters
effortDeepSeekReasoning
Returns
WithMathMode()
Optimizes settings for mathematical reasoning
public DeepSeekService WithMathMode()