|
| 1 | + |
| 2 | +<div align="center"> |
| 3 | + <h1>Generative AI Fundamentals for .NET</h1> |
| 4 | + <h2>Lesson 2: Setting Up the Environment</h2> |
| 5 | + <p><em>Transform GitHub Codespaces into a powerful .NET development machine</em></p> |
| 6 | +</div> |
| 7 | + |
| 8 | +> 💡 **Quick Summary**: Follow this comprehensive guide to deploy your ideal .NET + AI development environment. Whether you're a seasoned developer or just starting out, we'll help you build a robust setup for creating amazing applications. |
| 9 | +
|
| 10 | +--- |
| 11 | + |
| 12 | +**What you'll achieve:** |
| 13 | +- ⚡ Lightning-fast development environment with GitHub Codepaces |
| 14 | +- 🛠️ Industry-standard tools configuration with .devcontainer |
| 15 | +- 🎯 Everything ready for immediate coding |
| 16 | + |
| 17 | +Let's dive in and set up your development environment! 🏃♂️ |
| 18 | + |
| 19 | +**Index** |
| 20 | + |
| 21 | +1. [Lesson Intro video](#intro-video) |
| 22 | +1. [Understanding GitHub Codespaces](#understanding-github-codespaces) |
| 23 | +1. [Pre-Flight Check: Setting up GitHub Access Tokens](#pre-flight-check-setting-up-github-access-tokens) |
| 24 | +1. [Taking Off with AI 🚀](#taking-off-with-ai-) |
| 25 | +1. [Running the Solution in Your Codespace](#running-the-solution-in-your-codespace) |
| 26 | +1. [Conclusions and Resources](#conclusions-and-resources) |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## Intro Video |
| 31 | + |
| 32 | +[](https://microsoft-my.sharepoint.com/:v:/p/brunocapuano/ERTkzBSAfKJEiLw2HLnzHnkBMEbpk17hniaVfr8lCm6how?e=gWOr33&nav=eyJyZWZlcnJhbEluZm8iOnsicmVmZXJyYWxBcHAiOiJTdHJlYW1XZWJBcHAiLCJyZWZlcnJhbFZpZXciOiJTaGFyZURpYWxvZy1MaW5rIiwicmVmZXJyYWxBcHBQbGF0Zm9ybSI6IldlYiIsInJlZmVycmFsTW9kZSI6InZpZXcifX0%3D) |
| 33 | + |
| 34 | +## Understanding GitHub Codespaces and Models |
| 35 | + |
| 36 | +GitHub is an Platform for Developers, with world-leading tooling, integration, and AI Capabilities, for this course, we are going to use GitHub Codespaces and GitHub Models. |
| 37 | + |
| 38 | +GitHub Codespaces is a cloud-powered development environment that enables developers to code from anywhere. Allowing you to seamlessly integrates with GitHub repositories, providing an effortless way to develop, commit, and deploy code. |
| 39 | + |
| 40 | +GitHub Models is an easy alternative to deploy, integrate, and frictionless way to add Generative Artificial Intelligence into your projects. With multiple families of models, like GPT from OpenAI and Phi Family from Microsoft Research, allowing for quick prototyping for projects in the GitHub ecosystem. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +### Infrastructure and Performance |
| 45 | + |
| 46 | +At its core, each codespace operates on a dedicated virtual machine, ensuring isolated and reproducible development environments. These environments are engineered for rapid bootup times and can be extensively customized through devcontainer configurations, allowing developers to maintain their preferred tools and settings. |
| 47 | + |
| 48 | +The platform operates on a transparent pricing model based on compute and storage consumption. For developers using GitHub Free accounts, the service includes [120 core-hours monthly and 15GB of storage](https://github.blog/changelog/2022-11-09-codespaces-for-free-and-pro-accounts/) at no cost. Premium tiers offer expanded resources to match growing development needs. |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +### Configure any environment with .devcontainer |
| 53 | + |
| 54 | +The **.devcontainer configuration** in GitHub Codespaces acts as your environment's blueprint, defining everything from the base Docker image to Visual Studio Code extensions and settings. This allows that every developer working on your project has identical tools, dependencies, and configurations, effectively eliminating the "it works on my machine" syndrome. Through simple JSON configuration files, you can specify your preferred development environment, including specific versions of .NET, runtime dependencies, and essential VS Code extensions. |
| 55 | + |
| 56 | +A .devcontainer setup involves defining a `devcontainer.json` file and, optionally, a Dockerfile. The configuration file supports a wide range of customization options, from port forwarding rules to post-creation commands, enabling you to automate environment setup tasks and maintain consistency across your development team. This approach not only streamlines the development process but also ensures that your environment remains reproducible and version-controlled alongside your codebase. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +> 💡 **Pro Tip**: Configure your devcontainer with your most-used tools and extensions to create a consistent development experience across all your projects. [Learn more about devcontainers here!](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers) |
| 61 | +
|
| 62 | +### Learn and Test AI Models with GitHub Models |
| 63 | + |
| 64 | +**GitHub Models** provides an intuitive way to experiment with various AI models directly within your development environment. This feature allows developers to test and interact with different models, understanding their capabilities and limitations before implementation. Through a simple interface, you can explore model responses, evaluate performance, and determine the best fit for your application requirements. Hosted within GitHub's infrastructure, these models offer reliable access and consistent performance, making them ideal for development and testing phases. |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Pre-Flight Check: Setting Up GitHub Access Tokens |
| 71 | + |
| 72 | +Before diving into generative AI development, we need to configure essential security credentials that will enable our Codespace to interact with GitHub Models and execute our applications securely. |
| 73 | + |
| 74 | +### Creating a Personal Access Token |
| 75 | + |
| 76 | +1. Navigate to GitHub Settings: |
| 77 | + |
| 78 | + - Click your profile picture in the top-right corner |
| 79 | + - Select **Settings** from the dropdown menu |
| 80 | + |
| 81 | +  |
| 82 | + |
| 83 | +2. Access Developer Settings: |
| 84 | + |
| 85 | + - Scroll down the left sidebar |
| 86 | + - Click on **Developer settings** (usually at the bottom) |
| 87 | + |
| 88 | +  |
| 89 | + |
| 90 | +3. Generate a New Token: |
| 91 | + |
| 92 | + - Select **Personal access tokens** → **Tokens (classic)** |
| 93 | + |
| 94 | +  |
| 95 | + |
| 96 | + - Click **Generate new token (classic)** |
| 97 | + |
| 98 | +  |
| 99 | + |
| 100 | + - Under "Note", provide a descriptive name (e.g., "AI-Development-Token") |
| 101 | + - Set an expiration date (recommended: 7 days for security best practices) |
| 102 | + - There is no need adding any permissions to this token. |
| 103 | + |
| 104 | +> 💡 **Security Tip**: Always use the minimum required scope and shortest practical expiration time for your access tokens. This follows the principle of least privilege and helps maintain your account's tokens safe. |
| 105 | +
|
| 106 | +## Taking Off with AI 🚀 |
| 107 | + |
| 108 | +Let's dive into practical implementations with three powerful AI demonstrations that showcase different approaches to AI integration. |
| 109 | + |
| 110 | +### Demo Overview |
| 111 | + |
| 112 | +1. **AI API Answer with Phi 3.5** |
| 113 | + - Experience Microsoft's Phi 3.5 language model |
| 114 | + - See real-time AI responses in action and the API integration patterns |
| 115 | + |
| 116 | +2. **Semantic Kernel Implementation** |
| 117 | + - Learn Microsoft's powerful AI orchestration framework |
| 118 | + - Explore complex AI patterns and workflows in the next lessons |
| 119 | + |
| 120 | +3. **Local Llama Integration** |
| 121 | + - Experience edge computing with AI running in your Codespace |
| 122 | + - Understand local vs. cloud AI tradeoffs |
| 123 | + |
| 124 | +### Setting Up Your Development Environment |
| 125 | + |
| 126 | +Let's create your AI-powered workspace using GitHub Codespaces: |
| 127 | + |
| 128 | +1. Navigate to the repository's main page |
| 129 | +2. Click the "Code" dropdown button |
| 130 | +3. Access "Codespaces" |
| 131 | +4. Select "..." (three dots) and choose "New with options" |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +### Choosing Your Development Container |
| 136 | + |
| 137 | +Select from two optimized configurations: |
| 138 | + |
| 139 | +**Option 1: Standard .NET Environment** : With a Faster startup time and with the core .NET development tools. This environment does not include Ollama capabilities. |
| 140 | + |
| 141 | +**Option 2: .NET with Ollama**: It has a slowet start-up time, five minutes on average, however, you will be able to run all the demos and experiment with Ollama. |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +> 💡 **Pro Tip**: Choose the Ollama configuration if you plan to experiment with local model execution. |
| 146 | +
|
| 147 | +## Running the Solution in Your Codespace |
| 148 | + |
| 149 | +Once your Codespace is fully loaded and configured, follow these steps to execute the demo applications: |
| 150 | + |
| 151 | +1. **Access the Solution Explorer** |
| 152 | + |
| 153 | + - Locate the Solution Explorer in the left sidebar |
| 154 | + - If collapsed, click the Explorer icon (usually the top icon) |
| 155 | + - The solution structure should be visible, containing all projects |
| 156 | + |
| 157 | +  |
| 158 | + |
| 159 | +2. **Launch the Debug Session** |
| 160 | + |
| 161 | + - Right-click on the Solution node to be run, in the Explorer |
| 162 | + - Navigate to "Debug" in the context menu |
| 163 | + - Select "Start New Instance" |
| 164 | + |
| 165 | +  |
| 166 | + |
| 167 | +> ⚠️ **Note**: If you encounter any build errors, ensure all required dependencies are properly restored by running `dotnet restore` in the terminal. |
| 168 | +
|
| 169 | +## Conclusions and resources |
| 170 | + |
| 171 | +### Additional Resources |
| 172 | + |
| 173 | +> ⚠️ **Note**: If you encounter any issues, open an issue in the repository. |
| 174 | +
|
| 175 | +- [GitHub Codespaces Documentation](https://docs.github.com/en/codespaces) |
| 176 | +- [GitHub Models Documentation](https://docs.github.com/en/github-models/prototyping-with-ai-models) |
| 177 | + |
| 178 | +### Next Steps |
| 179 | + |
| 180 | +Next, we'll explore how to create your first AI application using these tools. |
| 181 | + |
| 182 | +<p align="center"> |
| 183 | + <a href="../03-CoreGenerativeAITechniques/readme.md">Go to Chapter 3</a> |
| 184 | +</p> |
0 commit comments