Mythosia.AI
1.0.0
See the version list below for details.
dotnet add package Mythosia.AI --version 1.0.0
NuGet\Install-Package Mythosia.AI -Version 1.0.0
<PackageReference Include="Mythosia.AI" Version="1.0.0" />
paket add Mythosia.AI --version 1.0.0
#r "nuget: Mythosia.AI, 1.0.0"
// Install Mythosia.AI as a Cake Addin #addin nuget:?package=Mythosia.AI&version=1.0.0 // Install Mythosia.AI as a Cake Tool #tool nuget:?package=Mythosia.AI&version=1.0.0
Mythosia.AI
Package Summary
The Mythosia.AI
library provides an abstraction for various AI models, including support for OpenAI GPT-4 and Anthropic Claude models. This library allows easy interaction with AI services, enabling both synchronous completion and streaming capabilities for models like GPT-3.5, GPT-4, Claude, and more.
This library abstracts the HTTP requests required to communicate with the APIs and provides a unified interface for various AI models, making it easier to integrate into any C# or ASP.NET Core project.
Supported Models
- OpenAI GPT-4 and GPT-4 Turbo
- OpenAI GPT-3.5 Turbo
- Claude 3.x variants (Claude3_5Sonnet, Claude3Opus, Claude3Haiku)
Key Features
- Synchronous completion and streaming support for AI models
- Customizable model selection, temperature, and max tokens
- Abstraction over the complexity of managing HTTP requests and responses
- Extendable structure for adding support for new AI models
How to Use
To use this library, create an instance of either ChatGptService
or ClaudeService
depending on the AI model you're working with. Here's an example:
using Mythosia.AI;
using System.Net.Http;
// Create HttpClient (best if injected via DI in ASP.NET Core)
var httpClient = new HttpClient();
// For GPT-based completion
var chatGptService = new ChatGptService("your_openai_api_key", httpClient);
string gptResponse = await chatGptService.GetCompletionAsync("What is the weather today?");
Console.WriteLine(gptResponse);
// For Claude-based completion
var claudeService = new ClaudeService("your_anthropic_api_key", httpClient);
string claudeResponse = await claudeService.GetCompletionAsync("What is the weather today?");
Console.WriteLine(claudeResponse);
Streaming Responses
The library also supports streaming responses for real-time interaction. Here's an example of how to use the streaming feature:
await chatGptService.StreamCompletionAsync("Tell me a joke", content =>
{
Console.WriteLine(content); // Streamed content in real time
});
ASP.NET Core Integration
To use this service in an ASP.NET Core application, you can register the services in the Startup.cs or Program.cs file as follows:
using Mythosia.AI;
public void ConfigureServices(IServiceCollection services)
{
// Add HttpClient for dependency injection
services.AddHttpClient();
// Register the AI services
services.AddScoped<ChatGptService>(sp =>
{
var httpClient = sp.GetRequiredService<HttpClient>();
return new ChatGptService("your_openai_api_key", httpClient);
});
services.AddScoped<ClaudeService>(sp =>
{
var httpClient = sp.GetRequiredService<HttpClient>();
return new ClaudeService("your_anthropic_api_key", httpClient);
});
}
Service Usage in Controllers
Once the services are registered, you can inject them into your controllers or other services:
public class AIController : ControllerBase
{
private readonly ChatGptService _chatGptService;
private readonly ClaudeService _claudeService;
public AIController(ChatGptService chatGptService, ClaudeService claudeService)
{
_chatGptService = chatGptService;
_claudeService = claudeService;
}
[HttpPost("chatgpt-completion")]
public async Task<IActionResult> GetChatGptCompletion([FromBody] string prompt)
{
var result = await _chatGptService.GetCompletionAsync(prompt);
return Ok(result);
}
[HttpPost("claude-completion")]
public async Task<IActionResult> GetClaudeCompletion([FromBody] string prompt)
{
var result = await _claudeService.GetCompletionAsync(prompt);
return Ok(result);
}
}
Conclusion
The Mythosia.AI library simplifies integration with AI services, offering a unified API for OpenAI's GPT and Anthropic's Claude models. It provides support for real-time streaming and synchronous completion, making it an ideal choice for applications requiring conversational AI capabilities.
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. |
.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.0.0-beta.5)
- Azure.AI.OpenAI.Assistants (>= 1.0.0-beta.4)
- Azure.Search.Documents (>= 11.6.0)
- Mythosia.Azure (>= 1.1.0)
- Newtonsoft.Json (>= 13.0.3)
- OpenAI (>= 2.0.0-beta.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.