Generative AI for Beginners (.NET)

repository·main·Indexed 25 days ago

https://github.com/microsoft/generative-ai-for-beginners-dotnet

A hands-on course for .NET developers to build Generative AI applications. It covers core concepts, the Microsoft.Extensions.AI (MEAI) abstraction layer for providers like Azure OpenAI and Ollama, and the Microsoft Agent Framework (MAF). Key topics include text completions, streaming, function calling, RAG, semantic search, vision processing, and responsible AI practices including content safety and bias mitigation.

Tokens
95.7K
Snippets
230
Records
430
Agent score
83%

What's inside generative-ai-for-beginners-dotnet

  1. Overview of AI Patterns and Applications in .NET

    main

    Lesson 3 focuses on applying AI patterns to solve real-world problems by combining techniques like chat, streaming, and function calling. You will learn to build applications that understand meaning through embeddings, ground responses using Retrieval-Augmented Generation (RAG), process visual/document content, and run models locally.

    Key patterns covered:

    • Semantic Search: Finding information by intent rather than just keywords.
    • RAG (Retrieval-Augmented Generation): Answering questions using specific, private, or external data.
    • Vision Processing: Extracting information from images.
    • Document Understanding: Analyzing and processing document content (e.g., PDFs).
    • Local Model Runners: Running AI models privately and offline on local hardware.
  2. Overview of Microsoft.Extensions.AI (MEAI) layers

    main

    The project uses a layered approach to AI development:

    1. Microsoft.Extensions.AI (MEAI): The foundation providing IChatClient for text, IEmbeddingGenerator for vector search, and built-in support for caching, telemetry, and retries.
    2. AI Models: The 'brains' (e.g., Ollama for local, Azure OpenAI for enterprise).
    3. Microsoft Agent Framework (MAF): Used for building intelligent agents that can use tools, maintain state, and collaborate.
  3. Overview of AI Agent Concepts

    main

    In this framework, an Agent is distinguished from a Chatbot by its ability to accomplish objectives rather than just responding to questions.

    Key Agent Components:

    • LLM (Reasoning Engine): Understands context, plans next steps, and decides which tools to use.
    • Tools: Allows the agent to interact with external systems (APIs, databases, code execution).
    • Memory: Maintains context and state across interactions.
    • Context: Provides the necessary information for reasoning.

    Core Capabilities:

    • Tools & Actions: Function calling to interact with external systems.
    • Multi-Agent Workflows: Orchestrating multiple specialized agents (sequential pipelines, handoffs, or group collaboration).
    • Model Context Protocol (MCP): Extending capabilities using standardized tool servers.
  4. Overview of Generative AI for .NET

    main

    This course teaches the fundamentals of Generative AI (GenAI) and how to build applications using .NET tools. Key concepts covered include:

    • GenAI Capabilities: Text generation (chatbots, content completion), image generation/analysis, and code generation.
    • Model Types: Small Language Models (SLMs) for text generation and Large Language Models (LLMs) for complex tasks like code or image analysis.
    • Prompt Engineering: The practice of designing effective inputs using clarity, context, and constraints. Key prompt types include System Prompts (rules/context), User Prompts (user input), and Assistant Prompts (model responses).
    • Core Terminology:
      • Tokens: The smallest text units (words, characters, or sub-words) used by models.
      • Embeddings: Vector representations of tokens that capture semantic meaning.
      • Vector Databases: Collections of embeddings used to retrieve contextually relevant data.
      • Agents: AI components (like chatbots) that interact with models to perform tasks.
  5. Overview of Microsoft Agent Framework (MAF) Samples

    main

    The Microsoft Agent Framework (MAF) v1.0 GA samples demonstrate how to build intelligent agents using .NET 10 and Microsoft.Extensions.AI.

    Key capabilities showcased include:

    • Simple agents: Single-shot and conversational AI.
    • Multi-agent workflows: Sequential and parallel orchestration.
    • Tool integration: Function calling and tool use.
    • Persistence: Saving and resuming conversation state.
    • Web applications: Blazor Server chat interfaces.
    • Hosted deployment: Docker containerization for Azure Foundry Agent Service.
    • Multi-provider support: Azure OpenAI, Ollama, Claude, and Microsoft Foundry.
  6. Overview of RAG Simple - MEAI Vectors Memory implementation

    main

    This sample demonstrates semantic search and Retrieval-Augmented Generation (RAG) building blocks. It performs the following workflow:

    1. Creates a local sqlite-vec backed vector collection.
    2. Loads a collection of movies with descriptions.
    3. Generates embeddings for each movie using the Azure OpenAI text-embedding-3-small model.
    4. Performs a vector search based on a user query.
    5. Returns the most relevant movies.

    It utilizes the following libraries:

    • Microsoft.Extensions.AI: For embeddings generation.
    • Azure.AI.OpenAI: For connecting to Azure OpenAI / Microsoft Foundry.
    • Microsoft.Extensions.VectorData: For official record/search abstractions.
    • ElBruno.Connectors.SqliteVec: For the local sqlite-vec store implementation.
  7. Overview of Generative AI for Beginners .NET Course

    main

    This is a practical, hands-on course designed for .NET developers to learn how to build Generative AI applications. The course focuses on real-world applications and live coding rather than just theory.

    Key learning components include:

    • Short Videos: 5-10 minute overviews of key concepts.
    • Full Code Samples: Ready-to-run .NET code.
    • Step-by-Step Guidance: Instructions to help implement concepts.
    • Deep References: Links to theoretical foundations when needed.
  8. SpaceAINet Solution Structure

    main

    The SpaceAINet solution is composed of the following projects:

    • SpaceAINet.Console: The main console game project. It manages game logic, rendering, user/AI input, and the main game loop.
    • SpaceAINet.GameActionProcessor: A library used to integrate AI models (Ollama or Microsoft Foundry) to analyze game frames and suggest actions.
    • SpaceAINet.Screenshot: Provides functionality to capture screenshots of the game screen.
    • SpaceAINet.ServiceDefaults: Contains shared configuration and service defaults.
  9. Use Microsoft.Extensions.AI (MEAI) for provider-agnostic AI abstractions

    main

    Use the Microsoft.Extensions.AI (MEAI) library to add intelligence to C# applications using provider-agnostic abstractions. This allows you to swap AI providers (e.g., moving from Azure OpenAI to a local Ollama instance) without changing your application logic. Key abstractions include:

    • IChatClient: Used to interact with chat models.
    • IEmbeddingGenerator: Used to create embeddings.
  10. Core Generative AI Techniques Course Overview

    main
    This course provides practical lessons on building AI-driven .NET applications using various generative AI techniques. The curriculum covers LLM completions, chat functionality, Retrieval-Augmented Generation (RAG), vision and audio analysis, image generation, and AI agents. It also includes instructions for running models locally using AI Toolkit and Docker.
  11. Use Microsoft Agent Framework v1.0 Features

    main

    The Microsoft Agent Framework v1.0 provides several production-ready capabilities for building .NET agents:

    • Multi-agent workflows: Orchestrate collaboration between multiple agents for complex scenarios.
    • Streaming support: Enable real-time responses from agents.
    • Persistence: Manage state through persistence capabilities.
    • Model Context Protocol (MCP): Integration for standardized tool and context access.
  12. A2A Protocol Implementation Details

    main

    The sample utilizes preview versions of the Microsoft Agent Framework A2A packages. The communication flow follows this pattern:

    [ A2AClient ] --(A2A protocol)--> [ /a2a/writer-agent ] --> [ writer-agent (Azure OpenAI) ]

    Key components:

    • Server Role: Uses app.MapA2A(writerAgent, "/a2a/writer-agent") to expose an agent over A2A.
    • Client Role: Uses A2AClient to connect to the endpoint, wrapping it as a standard AIAgent to invoke RunAsync(...) without needing knowledge of the agent's internal implementation.
    • Required Packages: Microsoft.Agents.AI.A2A and Microsoft.Agents.AI.Hosting.A2A.AspNetCore (Preview).