Empowering AI Development with .NET Aspire and Assemblysoft
Integrating AI capabilities into your applications is now easier than ever with .NET Aspire. Whether you’re experimenting with local AI models or deploying them to the cloud, Assemblysoft can guide your business in leveraging these advanced tools. By combining the flexibility of .NET Aspire with robust frameworks like Ollama, you can create innovative, AI-powered solutions tailored to your needs.
Using Local AI Models in .NET Aspire
Local AI models offer a convenient way to prototype and experiment without relying on cloud resources. By using Ollama’s integration with .NET Aspire, developers can:
- Download and manage AI models locally.
- Interact with models via a web interface for testing.
- Transition seamlessly to cloud-hosted models when ready for deployment.
Here’s how Assemblysoft helps you get started:
Set Up OllamaInstall the Ollama hosting integration from NuGet:
dotnet add package CommunityToolkit.Aspire.Hosting.Ollama
Configure it in Program.cs
to enable local hosting:
var ollama =
builder.AddOllama("ollama")
.WithDataVolume()
.WithOpenWebUI();
This setup ensures that models are downloaded and persisted, saving time on restarts and enabling easy interaction through a web UI.
Run AI Models LocallyAdd your preferred model using the AddModel
method:
var chat = ollama.AddModel("chat", "llama3.2");
You can also include models from the Hugging Face model hub for additional versatility.
Integrate Models into Your ApplicationLink the AI models to your API project with minimal code:
builder.AddProject<Projects.MyApi>("api")
.WithReference(chat)
.WaitFor(chat);
This ensures your application waits until the model is fully downloaded and ready for use, enhancing stability and reliability.
Transitioning to Cloud-Hosted Models
While local models are excellent for development, cloud-hosted AI services like Azure OpenAI provide scalability and performance for production environments. With .NET Aspire’s abstractions, transitioning is seamless. Here’s how you can manage both local and cloud-hosted models:
if (builder.Environment.IsDevelopment())
{
builder.AddKeyedOllamaSharpChatClient("chat");
}
else
{
builder.AddKeyedAzureOpenAIClient("chat");
}
builder.Services.AddChatClient(b => b
.UseFunctionInvocation()
.UseOpenTelemetry(configure: t => t.EnableSensitiveData = true)
.UseLogging()
.Use(b.Services.GetRequiredKeyedService<IChatClient>("chat")));
This approach ensures your development and production environments use the most appropriate resources while maintaining consistent code.
Enhancing Applications with AI Integration
With Assemblysoft’s expertise, your business can:
- Develop AI-driven APIs that leverage the latest in machine learning.
- Utilize Microsoft.Extensions.AI abstractions for seamless transitions between local and cloud models.
- Integrate AI capabilities into existing .NET Aspire solutions with minimal effort.
Why Choose Assemblysoft?
At Assemblysoft, we specialize in empowering businesses to adopt cutting-edge technologies like AI and .NET Aspire. From setting up local AI models to deploying scalable cloud-based solutions, our team provides end-to-end support tailored to your goals.
Get Started Today
Whether you're exploring local AI models or preparing for cloud integration, Assemblysoft can help you navigate the complexities of modern AI development. Contact us today to learn how we can transform your applications with .NET Aspire and advanced AI tools!