.NET AI Samples

repository·main·Indexed 21 days ago

https://github.com/dotnet/ai-samples

A collection of .NET samples demonstrating the integration of AI capabilities (LLMs, SLMs, and embeddings) using unified abstractions and SDKs. It features Microsoft.Extensions.AI for provider-agnostic C# abstractions, Microsoft.Extensions.AI.Evaluation for response quality tooling, and practical implementations using OpenAI, Azure OpenAI, Ollama, and Semantic Kernel. Samples include text summarization, chat applications, function calling, image generation with DALL-E 3, and Semantic Kernel integration in web apps.

Tokens
26.4K
Snippets
76
Records
153
Agent score
74%

What's inside dotnet-ai-samples

  1. Overview of Microsoft.Extensions.AI OpenAI Examples

    main

    This repository provides samples demonstrating how to use the OpenAI reference implementation via the Microsoft.Extensions.AI.OpenAI NuGet package.

    Available sample types include:

    • Console Applications: Found in the OpenAIExamples directory, these provide a set of samples for interacting with the OpenAI implementation.
    • Web API Applications: Found in the OpenAIWebAPI directory, these demonstrate a minimal Web API implementation using the same package.
  2. Overview of Microsoft.Extensions.AI - Ollama Examples

    main
    This repository provides sample implementations demonstrating how to use the Ollama reference implementation via the Microsoft.Extensions.AI.Ollama NuGet package. It includes both console applications and Web API implementations to show how to integrate local LLMs into .NET applications using the Microsoft.Extensions.AI abstractions.
  3. Overview of Microsoft.Extensions.AI.Evaluation Reporting API Examples

    main

    This project provides practical examples of how to use the Microsoft.Extensions.AI.Evaluation ecosystem to perform 'offline' evaluations. It demonstrates how to combine evaluators (Quality, Safety) with reporting concepts like response caching, result storage, and report generation.

    Key capabilities demonstrated include:

    • Orchestrating Offline Evaluations: Using unit testing frameworks and dotnet test to run evaluations locally or in CI/CD pipelines.
    • Response Caching: Using Microsoft.Extensions.AI.Evaluation.Reporting to store LLM responses in a cache. This reduces costs and improves performance by reusing responses for identical request parameters (model, endpoint, prompts, context).
    • Result Storage & Reporting: Storing evaluation results over time and generating reports based on that historical data.
    • Extensibility: Implementing custom storage providers (e.g., using SQLite) for caching and result storage.
  4. Overview of Microsoft.Extensions.AI

    main

    Microsoft.Extensions.AI is a set of core .NET libraries (currently in preview) that provides a unified layer of C# abstractions for interacting with AI services. It is designed to work with the .NET ecosystem, including Semantic Kernel, to provide a consistent way to interact with Small Language Models (SLMs), Large Language Models (LLMs), and embeddings.

    Key benefits include:

    • Unified API: Standardized APIs and conventions for AI service integration.
    • Flexibility: Allows library authors to use AI services without being locked into a specific provider.
    • Ease of Use: Enables developers to switch between different AI packages using the same underlying abstractions.
    • Componentization: Simplifies testing and adding new capabilities to applications.
  5. Overview of the Customer Support Ticket Summarizer sample

    main

    The Customer Support sample is a C# console application designed to demonstrate AI-driven workflows for customer service. It performs three primary tasks:

    1. Ticket Summarization: Uses an AI model to generate concise summaries of customer support tickets.
    2. Manual Ingestion: Extracts data from product manual PDF files, chunks the text, generates embeddings, and saves them to a JSON file.
    3. Semantic Search: Uses embeddings and a vector store to perform semantic searches over product manuals.

    Core Components

    • ManualIngestor.cs: Handles PDF data extraction, text chunking, embedding generation, and JSON storage.
    • ProductManualService.cs: A storage service utilizing an IVectorStore to manage and query product manual embeddings.
    • TicketSummarizer: An AI service that interfaces with models to summarize support tickets.
  6. Overview of OpenAI Semantic Kernel Samples

    main

    These samples demonstrate how to integrate OpenAI models (gpt-3.5-turbo and dall-e-3) into .NET 8.0 console applications using the Semantic Kernel (SK) library. Semantic Kernel is an extensible SDK that allows you to build generative AI solutions and can be used with various model providers including OpenAI, Azure OpenAI, and Hugging Face.

    Available sample scenarios include:

    • Hike Benefits Summary: Summarizing long text.
    • Hiker AI: Chatting with an AI for hike recommendations.
    • Chatting About my Previous Hikes: Contextual chatting about past experiences.
    • Hiker AI Pro: Extending AI models using local functions via Function Tool.
    • Hike Images: Generating images using DALL-E 3.
  7. Overview of Microsoft.Extensions.AI.Evaluation packages

    main

    The Microsoft.Extensions.AI.Evaluation libraries provide tooling to evaluate the quality and efficacy of LLM responses. The ecosystem is divided into the following functional areas:

    • Core Abstractions: Microsoft.Extensions.AI.Evaluation defines the base types and interfaces.
    • Quality Evaluation: Microsoft.Extensions.AI.Evaluation.Quality provides evaluators for metrics like Relevance, Truth, Completeness, Fluency, Coherence, Retrieval, Equivalence, and Groundedness.
    • Safety Evaluation: Microsoft.Extensions.AI.Evaluation.Safety uses Azure AI Foundry Evaluation service to check for Protected Material, Groundedness Pro, Ungrounded Attributes, Hate and Unfairness, Self Harm, Violence, Sexual content, Code Vulnerability, and Indirect Attack.
    • Reporting & Storage: Microsoft.Extensions.AI.Evaluation.Reporting handles caching LLM responses and storing results. Microsoft.Extensions.AI.Evaluation.Reporting.Azure provides an implementation for storing these in Azure Storage containers.
    • CLI Tooling: Microsoft.Extensions.AI.Evaluation.Console is a dotnet tool for managing evaluation data and generating reports.