Mythosia.AI
1.7.0
See the version list below for details.
dotnet add package Mythosia.AI --version 1.7.0
NuGet\Install-Package Mythosia.AI -Version 1.7.0
<PackageReference Include="Mythosia.AI" Version="1.7.0" />
paket add Mythosia.AI --version 1.7.0
#r "nuget: Mythosia.AI, 1.7.0"
// Install Mythosia.AI as a Cake Addin #addin nuget:?package=Mythosia.AI&version=1.7.0 // Install Mythosia.AI as a Cake Tool #tool nuget:?package=Mythosia.AI&version=1.7.0
Mythosia.AI
Package Summary
The Mythosia.AI
library provides an abstraction for various AI models, including support for OpenAI GPT-4, Anthropic Claude, DeepSeek, Sonar, Gemini, and more.
This library allows easy interaction with AI services, enabling both synchronous completion and streaming capabilities for GPT-3.5, GPT-4, Claude, DeepSeek, Sonar, Gemini, etc.
Supported Models
- OpenAI: GPT-4, GPT-3.5 (Turbo), GPT-4o variants
- Anthropic Claude: Claude 3.x (Claude3_5Sonnet, Claude3Opus, etc.)
- DeepSeek: various chat/reasoner models
- Sonar: sonar, sonar-pro, sonar-reasoning
- Gemini: gemini-1.5-flash (and possible future expansions)
Key Features
- Synchronous completion and streaming support for multiple AI providers
- Customizable model selection, temperature, and max tokens
- Single-prompt token counting and entire-conversation token counting built-in
- Unified abstraction over HTTP requests/responses for each service
- Extendable structure for easily adding new AI model integrations
How to Use
Allocation
using Mythosia.AI;
using System.Net.Http;
var httpClient = new HttpClient();
// Example usage for each supported service:
var aiService = new ChatGptService("your_openai_api_key", httpClient);
var aiService = new ClaudeService("your_anthropic_api_key", httpClient);
var aiService = new DeepSeekService("your_deepseek_api_key", httpClient);
var aiService = new SonarService("your_sonar_api_key", httpClient);
var aiService = new GeminiService("your_gemini_api_key", httpClient);
completion
string response = await aiService.GetCompletionAsync("What is AI?");
Token Counting
// Entire conversation token count
uint totalTokens = await aiService.GetInputTokenCountAsync();
// Single-prompt token count
uint promptTokens = await aiService.GetInputTokenCountAsync("One-off prompt to analyze");
Model Switching Example
// Add to existing ChatBlock usage
aiService.ActivateChat.ChangeModel(AIModel.Gpt4oLatest);
aiService.ActivateChat.ChangeModel("o1-2024-12-17"); // change with string
Streaming Responses
await aiService.StreamCompletionAsync("Explain quantum computing", content => {
Console.WriteLine(content);
});
ASP.NET Core Integration
Below is an example of how to register and consume these AI services in an ASP.NET Core application.
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
// Register your AI services with the needed keys
services.AddScoped<ChatGptService>(sp =>
new ChatGptService("openai_key", sp.GetRequiredService<HttpClient>()));
services.AddScoped<ClaudeService>(sp =>
new ClaudeService("claude_key", sp.GetRequiredService<HttpClient>()));
services.AddScoped<DeepSeekService>(sp =>
new DeepSeekService("deepseek_key", sp.GetRequiredService<HttpClient>()));
services.AddScoped<SonarService>(sp =>
new SonarService("sonar_key", sp.GetRequiredService<HttpClient>()));
services.AddScoped<GeminiService>(sp =>
new GeminiService("gemini_key", sp.GetRequiredService<HttpClient>()));
}
Service Usage in Controllers
[ApiController]
[Route("api/[controller]")]
public class AIController : ControllerBase
{
private readonly ChatGptService _chatGptService;
private readonly ClaudeService _claudeService;
private readonly DeepSeekService _deepseekService;
private readonly SonarService _sonarService;
private readonly GeminiService _geminiService;
public AIController(
ChatGptService chatGptService,
ClaudeService claudeService,
DeepSeekService deepseekService,
SonarService sonarService,
GeminiService geminiService)
{
_chatGptService = chatGptService;
_claudeService = claudeService;
_deepseekService = deepseekService;
_sonarService = sonarService;
_geminiService = geminiService;
}
[HttpPost("deepseek-completion")]
public async Task<IActionResult> GetDeepSeekCompletion([FromBody] string prompt)
{
var result = await _deepseekService.GetCompletionAsync(prompt);
return Ok(result);
}
[HttpPost("sonar-completion")]
public async Task<IActionResult> GetSonarCompletion([FromBody] string prompt)
{
var result = await _sonarService.GetCompletionAsync(prompt);
return Ok(result);
}
}
Conclusion
The Mythosia.AI library simplifies integration with multiple AI providers (OpenAI GPT, Anthropic Claude, DeepSeek, Sonar, Gemini) by offering:
- Synchronous and streaming completion methods
- Single-prompt and full-conversation token counting
- Unified HTTP request/response handling
- Extendable model and service structure
It provides a convenient way to switch models, manage prompts, and retrieve results without worrying about each AI provider’s low-level API differences.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Azure.AI.OpenAI (>= 2.1.0-beta.1)
- Azure.AI.OpenAI.Assistants (>= 1.0.0-beta.4)
- Azure.Search.Documents (>= 11.7.0-beta.1)
- Mythosia (>= 1.4.0)
- Mythosia.Azure (>= 1.1.1)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.