MeshWeaver.AI.AzureOpenAI
2.3.0
dotnet add package MeshWeaver.AI.AzureOpenAI --version 2.3.0
NuGet\Install-Package MeshWeaver.AI.AzureOpenAI -Version 2.3.0
<PackageReference Include="MeshWeaver.AI.AzureOpenAI" Version="2.3.0" />
<PackageVersion Include="MeshWeaver.AI.AzureOpenAI" Version="2.3.0" />
<PackageReference Include="MeshWeaver.AI.AzureOpenAI" />
paket add MeshWeaver.AI.AzureOpenAI --version 2.3.0
#r "nuget: MeshWeaver.AI.AzureOpenAI, 2.3.0"
#:package MeshWeaver.AI.AzureOpenAI@2.3.0
#addin nuget:?package=MeshWeaver.AI.AzureOpenAI&version=2.3.0
#tool nuget:?package=MeshWeaver.AI.AzureOpenAI&version=2.3.0
MeshWeaver.AI.AzureOpenAI
Overview
MeshWeaver.AI.AzureOpenAI provides Azure OpenAI integration for the MeshWeaver AI framework, enabling AI-powered agent chats using Azure OpenAI's ChatCompletionAgent. This library is designed for stateless chat completion scenarios without persistent assistant storage.
Features
- Azure OpenAI Integration: Direct integration with Azure OpenAI services
- ChatCompletionAgent Support: Uses Microsoft Semantic Kernel's ChatCompletionAgent for stateless operations
- Factory Pattern: Implements the factory pattern for creating and managing agent chats
- Configuration-Based Setup: Uses
AIConfiguration
for secure credential management - Extensible Architecture: Built on top of MeshWeaver.AI's
ChatCompletionAgentChatFactory
base class
Installation
This package is part of the MeshWeaver solution and should be referenced as a project dependency:
<ProjectReference Include="..\MeshWeaver.AI.AzureOpenAI\MeshWeaver.AI.AzureOpenAI.csproj" />
Configuration
1. Configure AI Credentials
Add the following configuration to your appsettings.json
:
{
"AI": {
"Url": "https://your-azure-openai-endpoint.openai.azure.com/",
"ApiKey": "your-api-key-here",
"Models": ["gpt-4", "gpt-35-turbo"]
}
}
2. Register Services
In your Program.cs
or service configuration:
using MeshWeaver.AI.AzureOpenAI;
// Configure AI credentials
builder.Services.Configure<AIConfiguration>(
builder.Configuration.GetSection("AI"));
// Add Azure OpenAI services
builder.Services.AddAzureOpenAI();
Usage
Basic Implementation
public class MyService
{
private readonly IAgentChatFactory _chatFactory;
public MyService(IAgentChatFactory chatFactory)
{
_chatFactory = chatFactory;
}
public async Task<IAgentChat> CreateChatAsync()
{
var agentChat = await _chatFactory.CreateAsync();
return agentChat;
}
}
Agent Definition
Create custom agents by implementing IAgentDefinition
:
public class MyCustomAgent : IAgentDefinition
{
public string Name => "MyAgent";
public string Description => "A custom AI agent for specific tasks";
public string Instructions => "You are a helpful assistant specialized in...";
}
Architecture
Class Hierarchy
ChatCompletionAgentChatFactory (MeshWeaver.AI)
└── AzureOpenAIChatCompletionAgentChatFactory (MeshWeaver.AI.AzureOpenAI)
Key Components
- AzureOpenAIChatCompletionAgentChatFactory: Main factory class for creating Azure OpenAI-powered agent chats
- AzureOpenAIExtensions: Extension methods for service registration
- AIConfiguration: Configuration model for Azure OpenAI credentials
Security Considerations
- API Key Management: Store API keys securely using Azure Key Vault or similar secure storage
- Environment Variables: Consider using environment variables for sensitive configuration
- Network Security: Ensure secure communication with Azure OpenAI endpoints
Dependencies
- Microsoft.SemanticKernel
- Microsoft.Extensions.Options
- Microsoft.Extensions.DependencyInjection.Abstractions
- MeshWeaver.AI
- MeshWeaver.Messaging.Hub
Troubleshooting
Common Issues
- Missing API Key: Ensure
AIConfiguration.ApiKey
is properly configured - Invalid Endpoint: Verify the
AIConfiguration.Url
format - Model Not Available: Check that the specified models exist in your Azure OpenAI deployment
Logging
Enable detailed logging to troubleshoot issues:
builder.Services.AddLogging(logging =>
{
logging.AddConsole();
logging.SetMinimumLevel(LogLevel.Debug);
});
Related Projects
- MeshWeaver.AI - Core AI services and abstractions
- MeshWeaver.AI.AzureFoundry - Azure AI Foundry integration
- MeshWeaver.Portal.AI - Portal-specific AI implementations
- MeshWeaver.Blazor.Chat - Chat UI components
Contributing
This project is part of the MeshWeaver ecosystem. Please follow the established patterns and conventions when contributing.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- MeshWeaver.AI (>= 2.3.0)
- MeshWeaver.Messaging.Hub (>= 2.3.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Options (>= 9.0.6)
- Microsoft.SemanticKernel (>= 1.57.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.