Class PerplexityService
- Namespace
- Mythosia.AI.Services.Perplexity
- Assembly
- Mythosia.AI.dll
public class PerplexityService : AIService, IAIService, IFunctionRegisterable
- Inheritance
-
PerplexityService
- Implements
- Inherited Members
- Extension Methods
Constructors
PerplexityService(string, HttpClient)
public PerplexityService(string apiKey, HttpClient httpClient)
Parameters
apiKeystringhttpClientHttpClient
PerplexityService(string, string, HttpClient)
Creates a PerplexityService with a specific model.
public PerplexityService(string apiKey, string model, HttpClient httpClient)
Parameters
apiKeystringmodelstringhttpClientHttpClient
Properties
Provider
The AI provider for this service
public override string Provider { get; }
Property Value
Methods
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
ExtractFunctionCall(string)
Extracts function call from API response
protected override (string content, FunctionCall functionCall) ExtractFunctionCall(string response)
Parameters
responsestring
Returns
ExtractResponseContent(string)
Extracts the response content from the API response
protected override string ExtractResponseContent(string responseContent)
Parameters
responseContentstring
Returns
GenerateImageAsync(string, string)
Perplexity doesn't support image generation
public override Task<byte[]> GenerateImageAsync(string prompt, string size = "1024x1024")
Parameters
Returns
GenerateImageUrlAsync(string, string)
Perplexity doesn't support image generation
public override Task<string> GenerateImageUrlAsync(string prompt, string size = "1024x1024")
Parameters
Returns
GetCompletionAsync(Message)
public override Task<string> GetCompletionAsync(Message message)
Parameters
messageMessage
Returns
GetCompletionWithImageAsync(string, string)
Perplexity doesn't support multimodal inputs
public override Task<string> GetCompletionWithImageAsync(string prompt, string imagePath)
Parameters
Returns
GetCompletionWithSearchAsync(string, string[]?, string)
Gets a completion with web search and citations
public Task<PerplexityService.SonarSearchResponse> GetCompletionWithSearchAsync(string prompt, string[]? domainFilter = null, string recencyFilter = "month")
Parameters
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
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
UseSonarPro()
Switches to Sonar Pro model for enhanced capabilities
public PerplexityService UseSonarPro()
Returns
UseSonarReasoning()
Switches to Sonar Reasoning model for complex reasoning tasks
public PerplexityService UseSonarReasoning()
Returns
WithSearchParameters(bool, string, params string[])
Configures search parameters for the service
public PerplexityService WithSearchParameters(bool returnCitations = true, string recencyFilter = "month", params string[] domainFilter)