<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sakshi Dhama on Medium]]></title>
        <description><![CDATA[Stories by Sakshi Dhama on Medium]]></description>
        <link>https://medium.com/@shiprasakshi?source=rss-fd36b2428285------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8f5Ynu4zlQV6Dg6_</url>
            <title>Stories by Sakshi Dhama on Medium</title>
            <link>https://medium.com/@shiprasakshi?source=rss-fd36b2428285------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:09:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shiprasakshi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From Chaos to Clarity: How Pixi Simplifies Python Dependency Management]]></title>
            <link>https://medium.com/@shiprasakshi/from-chaos-to-clarity-how-pixi-simplifies-python-dependency-management-42b89f033306?source=rss-fd36b2428285------2</link>
            <guid isPermaLink="false">https://medium.com/p/42b89f033306</guid>
            <dc:creator><![CDATA[Sakshi Dhama]]></dc:creator>
            <pubDate>Thu, 26 Dec 2024 22:20:02 GMT</pubDate>
            <atom:updated>2024-12-26T22:20:02.277Z</atom:updated>
            <content:encoded><![CDATA[<p>This year towards the end of 2024 brought significant changes as I delved deeper into transitioning our code from development to production. I hadn’t anticipated the hurdles that even simple tasks would face in production. It wasn’t until I was advised to explore more options for resolving issues with Python virtual environments that things began to improve. A peer introduced me to Pixi, which had gained popularity in the data science community through various podcasts, talks, and conferences. Initially, I was skeptical about its offerings since it was new to me. Having been accustomed to the virtual environments provided by pip, embracing something entirely different and new was personally challenging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKkZ-EGhFNvYWd6zIQBLOA.png" /><figcaption>Pixi as power engine in python projects to build virtual environment</figcaption></figure><p><strong>What is python virtual environment and why do we need it ?</strong></p><p>Before I write more about pixi, I would just briefly recap the purpose of venv without going in much details.</p><p><em>A python virtual environments allow you to isolate project dependencies, ensuring that each project has its own set of libraries and versions. This prevents conflicts between projects and maintains a clean, manageable development environment.</em></p><p>Python dependencies can be managed using virtual environments (venv, virtualenv), Pipenv, Poetry, Conda, or requirements files (requirements.txt). Each tool offers unique features for isolating and handling project dependencies effectively. A good number of sources can be found here <a href="https://realpython.com/python-virtual-environments-a-primer/">[1]</a><a href="https://www.pythonguis.com/tutorials/python-virtual-environments/">[2]</a><a href="https://pyjourney.com/getting-started-with-python/python-virtual-environments-why-and-how-to-use-them/">[3]</a>.</p><p><strong>What’s with conda and venv?</strong></p><p>As part of our work, we had to manage packages, resolve dependencies, and create pre-commit hooks using Venv. Significant difficulties were encountered when integrating with Azure Machine Learning (AML), which uses Conda for virtual environments. Code that was disorganized as a result of switching between the Conda and Venv environments made it clear that a cleaner solution was required.</p><p>&quot;Beautiful is better than ugly,” which is what “The Zen of Python” says, and we needed a coordinated strategy. It was at that point that Pixi became a reliable choice. It ended up being the ideal missing component that we were searching for.</p><p><strong>What is Pixi ?</strong></p><p><em>Based on the Conda ecosystem, Pixi is a package manager and workflow tool that works on multiple platforms and languages. It offers a simplified approach to managing dependencies and development environments, much like well-known package managers like Cargo or Yarn.</em></p><p>Azure Machine Learning (AML) is my go-to platform for training models, but it only accepts conda.yml files for environment creation. This posed a challenge, as a unified setup could provide a way to handle hooks, project configurations, and work across different systems—locally on Windows and on AML’s Linux-based infrastructure. On the projects that I started to work, we needed a solution that could seamlessly integrate both Conda and PyPI packages, as our projects require a mix of dependencies from both sources.</p><p>Combining Pixi with other tools can enhance your development workflow significantly. Here are some tools that work well with Pixi:</p><ul><li><strong>Visual Studio Code (VS Code)</strong>: This popular code editor integrates seamlessly with Pixi. You can use extensions like Python, Jupyter, and Docker to enhance your development experience.</li><li><strong>GitHub Actions</strong>: Automate your workflows with GitHub Actions. Pixi supports automatic caching of environments, making it easy to set up CI/CD pipelines</li><li><strong>Docker:</strong> While Pixi itself aims to reduce the need for Docker by providing reproducible environments, Docker can still be useful for containerizing applications and ensuring consistency across different deployment environments.</li><li><strong>Jupyter Notebooks:</strong> For data science and machine learning projects, Jupyter Notebooks can be combined with Pixi to manage dependencies and create isolated environments for different projects.</li><li><strong>Conda:</strong> Since Pixi is built on top of the Conda ecosystem, using Conda alongside Pixi can help manage complex dependencies and environments more effectively2.</li><li><strong>Mamba</strong>: A fast, cross-platform package manager that can be used with Pixi to speed up environment creation and dependency resolution2.</li><li><strong>Pre-commit Hooks:</strong> Tools like pre-commit can be integrated with Pixi to ensure code quality and consistency by running checks before commits.</li><li><strong>VS Code Remote — Containers</strong>: This extension allows you to use a Docker container as a full-featured development environment, which can be managed by Pixi for consistency.</li></ul><p>By combining these tools with Pixi, you can create a robust and efficient development environment that caters to various needs, from local development to cloud-based deployments.</p><h3><strong>Remarks</strong></h3><p>Switching to Pixi has been a game-changer for my Python development environment. It allows to manage all python dependencies and configurations in one place, ensuring consistency and ease of use across various environments. With Pixi, one can effortlessly switch between local development and cloud-based training on AML, without worrying about compatibility issues or manual adjustments.</p><p>Pixi’s pyproject.toml has been a lifesaver in this regard. This streamlined workflow has significantly boosted my productivity and reduced the complexity of managing multiple environments.</p><p>Now that I’m using Pixi, I can concentrate more on creating and perfecting my models because I know that my environment setup is stable and dependable. Whether I’m working locally or deploying to AML, Pixi makes sure that all dependencies are properly resolved and my projects function without a hitch. My approach to managing my Python environments has been completely changed by this integration, which also makes it simpler for me to scale and maintain my machine learning workflows.</p><h3>“Getting Started with Pixi: A Beginner’s Guide”</h3><p><strong>Installing Pixi using PowerShell.</strong></p><p>You can also use winget, windows MSI installer and directly install from source. As we have PowerShell easily available so we can choose this method of installation.</p><ol><li>Install on windows run in power shell</li></ol><pre>iwr -useb https://pixi.sh/install.ps1 | iex</pre><p>2. To run autocompletion command create a profile first otherwise you will get a failure</p><pre>New-Item -Path $PROFILE -ItemType File -Force</pre><p>3. Run the autocompletion</p><pre>Add-Content -Path $PROFILE -Value &#39;(&amp; pixi completion --shell powershell) | Out-String | Invoke-Expression&#39;</pre><p>4. To choose the location and version of the pixi. There are two environment variables — PIXI_VERSION and PIXI_HOME</p><pre>iwr -useb https://pixi.sh/install.ps1 | iex -Args &quot;-PixiVersion v0.18.0&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*JDzDoz2Iu5j3x0GZoIhKiQ.png" /></figure><p>5. Check if pixi is installed</p><pre># Check version in commandline<br>pixi -V</pre><p>6. Update</p><pre># ignore version to insatll latest pixi<br>pixi self-update --version x.y.z</pre><h3>Understanding Pixi Pyproject.toml</h3><p><strong>Build Systems</strong></p><pre>[build-system]<br><br>requires = [&quot;hatchling&quot;]<br><br>build-backend = &quot;hatchling.build&quot;</pre><p>This section specifies the build backend and its dependencies.</p><p>For example</p><p>requires: Lists the packages needed to build the project.</p><p>build-backend: Specifies the build system to use.</p><p>Hatchling is a modern, lightweight build system for Python projects. This line specifies the build backend, which is the tool that will be used to build the project. Here, it is set to hatchling.build, meaning the hatchling package will handle the build process.</p><p>This includes tasks like compiling code, packaging it, and preparing it for distribution. The build backend takes the source code and other resources and produces the final build artifacts, such as wheels or source distributions.</p><p><strong>Project</strong></p><pre>[project]<br><br>name = &quot;pixi_template&quot;<br><br>description = &quot;&quot;<br><br>version = &quot;1.0&quot;<br><br>readme = &quot;README.md&quot;<br><br>requires-python = &quot;==3.9.*&quot;<br><br>dependencies = []</pre><p>This section contains metadata about the project, such as its name, version, and dependencies.</p><p>This specifies the required resources to run the project. It means the project requires Python 3.9. dependencies = [] This is a list of dependencies that the project needs to run. It’s currently empty, meaning the project doesn’t have any external dependencies at the moment.</p><p><strong>Feature</strong></p><pre>[tool.pixi.feature.training]<br>platforms = [&quot;win-64&quot;]<br>channels = [{ channel = &quot;conda-forge&quot;, priority = 1 }]<br>dependencies = { spacy = &quot;3.7.5&quot;, pandas = &quot;*&quot; }<br><br>[tool.pixi.feature.inference]<br>platforms = [&quot;win-64&quot;]<br>channels = [{ channel = &quot;conda-forge&quot;, priority = 1 }]<br>dependencies = { spacy = &quot;3.7.5&quot;, azure-ai-ml = &quot;*&quot;,azure-identity = &quot;*&quot;,azure-storage-blob = &quot;*&quot;,ftfy = &quot;*&quot;,pandas = &quot;*&quot;,pydantic = &quot;*&quot;,thefuzz = &quot;*&quot;}<br><br>[tool.pixi.feature.features]<br>platforms = [&quot;linux-64&quot;]<br>channels = [{ channel = &quot;conda-forge&quot;, priority = 1 }]<br>dependencies = {spacy=&quot;3.7.5&quot;}<br><br>[tool.pixi.feature.dev]<br>platforms = [&quot;win-64&quot;]<br>channels = [&quot;conda-forge&quot;]<br>dependencies = { spacy = &quot;3.7.5&quot;, pre-commit = &quot;*&quot;, ipykernel = &quot;*&quot;, ipython = &quot;*&quot;, ipywidgets = &quot;*&quot; , numpy = &quot;&gt;=1.26.4,&lt;2&quot; }</pre><p>This sections contains feature, which can contain a collection of dependencies, tasks, channels, and more..</p><p>A “feature” refers to a specific set of functionalities or capabilities that are grouped together within an environment. Each feature represents a collection of dependencies and configurations needed for a particular aspect of the project.</p><p>We have used feature from pixi to create four different environments using one pyproject.toml file. As an environment goes beyond just dependencies the features should be described including the following fields:</p><ul><li>dependencies: The conda package dependencies</li><li>pypi-dependencies: The pypi package dependencies</li><li>system-requirements: The system requirements of the environment</li><li>activation: The activation information for the environment</li><li>platforms: The platforms the environment can be run on.</li><li>channels: The channels used to create the environment. Adding the priority field to the channels to allow concatenation of channels instead of overwriting.</li><li>target: All the above features but also separated by targets.</li><li>tasks: Feature specific tasks, tasks in one environment are selected as default tasks for the environment.</li></ul><p><strong>Tool</strong></p><pre>[tool.pip-tools.compile]<br>generate-hashes = false<br>allow-unsafe = true<br>resolver-name = &quot;backtracking&quot;<br><br>[tool.ruff]<br>line-length = 88<br>indent-width = 4<br>extend-include = [&quot;*.ipynb&quot;]<br><br>[tool.ruff.lint]<br>select = [&quot;E&quot;, &quot;F&quot;, &quot;D&quot;, &quot;I&quot;]<br>ignore = [<br>    &quot;D100&quot;,<br>    &quot;D101&quot;,<br>    &quot;D102&quot;,<br>    &quot;D103&quot;,<br>    &quot;D104&quot;,<br>    &quot;D105&quot;,<br>    &quot;D106&quot;,<br>    &quot;D107&quot;,<br>    &quot;D206&quot;,<br>]<br><br>[tool.ruff.lint.pydocstyle]<br>convention = &quot;google&quot;<br><br>[tool.ruff.format]<br>quote-style = &quot;double&quot;<br>indent-style = &quot;space&quot;<br>docstring-code-format = false<br><br>[tool.sqlfluff.core]<br>dialect = &quot;tsql&quot;<br>templater = &quot;placeholder&quot;<br>exclude_rules = &quot;L016,L031,CP02&quot;<br>max_line_length = 88<br><br>[tool.sqlfluff.templater.placeholder]<br>param-style = &quot;colon&quot;<br>from_date = &quot;0000/00/00&quot;<br>to_date = &quot;0000/00/00&quot;<br>market_id = &quot;0&quot;</pre><p>Using tools you can modify settings of the channels, platforms, linters, formatters etc.</p><p>In the context of the pyproject.toml file, the [tool] sections are used to configure various tools that your project might use. This file supports the full pixi specification with [tool.pixi.nameoftool].</p><p>When building a package, you often need to perform additional steps beyond just running the code, such as formatting, linting, compiling, testing, and benchmarking. Configuring these tools in the pyproject.toml file ensures a streamlined and consistent development environment. Consult the particular tool’s documentation to know what it can contain[2].</p><p><strong>Tasks</strong></p><pre>[tool.pixi.tasks]<br><br>remove_pre_commit_hook = { cmd = &quot;cmd /c del $GIT_PATH&quot;, env = {GIT_PATH =&quot;.git\\hooks\\pre-commit&quot;}}<br><br>install_pre_commit = { cmd = &quot;cmd /c $INSTALL_PATH&quot;, env = {INSTALL_PATH =&quot;.pixi\\envs\\dev\\Scripts\\pre-commit install&quot;}}<br><br>autoupdate_pre_commit = { cmd = &quot;cmd /c $UPDATE&quot;, env = {UPDATE= &quot;.pixi\\envs\\dev\\Scripts\\pre-commit autoupdate&quot;}}<br><br> <br>setup_pre_commit = { cmd = &quot;&quot;&quot;<br><br>pixi run remove_pre_commit_hook &amp;&amp;<br><br>pixi run install_pre_commit &amp;&amp;<br><br>pixi run autoupdate_pre_commit<br><br>&quot;&quot;&quot;}<br><br>setup_all_environments = { cmd = &quot;&quot;&quot;<br><br>pixi install --environment dev &amp;&amp;<br><br>pixi install --environment training &amp;&amp;<br><br>pixi install --environment inference &amp;&amp;<br><br>pixi install --environment features &amp;&amp;<br><br>pixi run setup_pre_commit &amp;&amp;<br><br>pixi project export conda-environment --environment dev &amp;&amp;<br><br>pixi project export conda-environment --environment training mlops/environment/training.yml &amp;&amp;<br><br>pixi project export conda-environment --environment inference mlops/environment/inference.yml &amp;&amp;<br><br>pixi project export conda-environment --environment features mlops/environment/features.yml<br><br>&quot;&quot;&quot;}</pre><p>Tasks enable the execution of CLI commands and python scripts directly from within the pyproject.toml file.</p><p>The purpose of these tasks is to streamline and automate the setup and maintenance of development environments and pre-commit hooks for a project. Here’s a breakdown:</p><p>The [tool.pixi.tasks] section in pyproject.toml file defines tasks for managing pre-commit hooks and setting up various environments. It includes commands to remove, install, and update pre-commit hooks, and a combined task to set them up. Additionally, it automates the installation of dependencies and exports Conda environment configurations for different project stages.</p><ol><li><strong>remove_pre_commit_hook</strong>: Ensures any existing pre-commit hooks are removed to avoid conflicts.</li><li><strong>install_pre_commit</strong>: Sets up the pre-commit hook to enforce code quality checks before commits.</li><li><strong>autoupdate_pre_commit</strong>: Keeps the pre-commit hook updated with the latest configurations and checks.</li><li><strong>setup_pre_commit</strong>: Combines the above tasks to ensure the pre-commit hook is correctly set up and updated.</li><li><strong>setup_all_environments</strong>: Automates the installation of multiple development environments and exports their configurations, ensuring consistency across different stages of the project.</li></ol><p><strong>Environment and Solve Group</strong></p><pre>[tool.pixi.environments]<br><br>dev = {solve-group = &quot;dev&quot;, features = [&quot;dev&quot;]}<br><br>training = {solve-group = &quot;dev&quot;, features = [&quot;training&quot;] }<br><br>inference = {solve-group = &quot;dev&quot;, features = [&quot;inference&quot;]}<br><br>features= {solve-group = &quot;dev&quot;, features = [&quot;features&quot;]} </pre><p>The [tool.pixi.environments] section defines four different environments for our project.</p><p><strong>Same package version in Multiple Environment</strong></p><p><strong>How can we maintain same version across multiple environments i.e. dev, inference, features ?</strong></p><p>Solve groups are a way to group dependencies together and allows to have multiple environments that share the same dependencies.</p><p>By putting dev inference and features in the same solve group, will ensure that the versions in across these are the same [1]</p><p>Each environment (dev, training, inference, features) belongs to the “dev” solve-group and includes specific features relevant to its purpose. This setup helps manage dependencies and configurations tailored to each environment’s needs. It ensures that the right packages and settings are applied for development, training, inference, and feature-specific tasks<strong>.</strong></p><p><strong>Optional Dependencies</strong></p><pre>[project.optional-dependencies]<br>dev = [&quot;ipykernel&quot;]<br>training = [&quot;spacy==3.7.5&quot;]<br>inference = [&quot;azure-ai-ml&quot;]<br>features = [&quot;datasketch&quot;]</pre><p>The optional dependencies install packages from pypi</p><ul><li>When we add optional dependencies to the pyproject.toml, pixi automatically creates a <a href="https://pixi.sh/dev/reference/project_configuration/#the-feature-and-environments-tables">feature</a>, which can contain a collection of dependencies, tasks, channels, and more.</li><li>The optional dependencies defined above are three different environments, which can also be added to pyproject.toml via pixi feature command. The command is : pixi add — pypi — feature inference azure-ai-ml</li><li>We are not using optional dependencies as we do not want to install pypi packages</li></ul><h3>Understanding some more details about Pixi</h3><p><strong>Installation</strong></p><pre>pixi install</pre><p>What Happens on when we install pyproject.toml ?</p><ul><li>We now have a new directory called .pixi in the project root. This location is <strong>not</strong> configurable as it is a specific design decision to keep the environments in the project directory.</li><li>This directory contains the environment that was created when we ran pixi install. The environment is a conda environment that contains the dependencies that we specified in the pyproject.toml file. You can use these environments as such, but you cannot manually edit them, this should always go through the pixi.toml.</li><li>Pixi will always make sure the environment is in sync with the pixi.lock file. If this is not the case then all the commands that use the environment will automatically update the environment, e.g. pixi run, pixi shell.</li><li>We can also install custom environment such as inference environment with -</li></ul><pre>pixi install –environment inference</pre><ul><li>See what all packages are installed: Using pixi list, you can see what’s in the environment, this is essentially a nicer view on the lock file:</li></ul><pre>Pixi list</pre><ul><li>You will see the different conda and Pypi packages listed.</li><li>Every environment in pixi is isolated but reuses files that are hard linked from a central cache directory. This means that you can have multiple environments with the same packages but only have the individual files stored once on disk.</li></ul><p><strong>Multiple platform Installation:</strong></p><pre>Pixi install</pre><ul><li>Running pixi install on a platform that is not configured will warn the user that it is not setup for that platform:</li><li>The project.platforms defines which platforms your project supports. When multiple platforms are defined, pixi determines which dependencies to install for each platform individually. All of this is stored in a lock file.</li><li>Running pixi install on a platform that is not configured will warn the user that it is not setup for that platform:</li></ul><p><strong>Do I still need python to run pyproject.toml ?</strong></p><p>Pixi installs global python</p><p>The Python interpreter is also installed in the environment. This is because the Python interpreter version is read from the requires-python field in the pyproject.toml file. This is used to determine the Python version to install in the environment. This way, pixi automatically manages/bootstraps the Python interpreter for you, so no more brew, apt or other system install steps.</p><p><strong>What is purpose of Pixi.lock ?</strong></p><p>We also have a new file called pixi.lock in the project root. This file contains the exact versions of the dependencies that were installed in the environment across platforms.</p><p>A lock file locks the environment in a specific state. Within pixi a lock file is a description of the packages in an environment. The lock file contains two definitions:</p><ol><li>The environments that are used in the project with their complete set of packages. e.g.:</li><li>The definition of the packages themselves. e.g.:</li></ol><p><strong>Why a lock file ?</strong></p><p>Pixi uses the lock file for the following reasons:</p><ul><li>To save a working installation state, without copying the entire environment’s data.</li><li>To ensure the project configuration is aligned with the installed environment.</li><li>To give the user a file that contains all the information about the environment.</li></ul><p>A lock file is generated when you install a package. Its human readable but not editable by hand</p><p>Running the following commands will check and automatically update the lock file if you changed any dependencies:</p><pre>pixi install<br>pixi run<br>pixi shell<br>pixi shell-hook<br>pixi tree<br>pixi list<br>pixi add<br>pixi remove</pre><p>All the commands that support the interaction with the lock file also include some lock file usage options:</p><ul><li>— frozen: install the environment as defined in the lock file, doesn’t update pixi.lock if it isn’t up-to-date with <a href="https://pixi.sh/dev/reference/project_configuration/">manifest file</a>. It can also be controlled by the PIXI_FROZEN environment variable (example: PIXI_FROZEN=true).</li><li>— locked: only install if the pixi.lock is up-to-date with the <a href="https://pixi.sh/dev/reference/project_configuration/">manifest file</a>[¹]. It can also be controlled by the PIXI_LOCKED environment variable (example: PIXI_LOCKED=true). Conflicts with — frozen.</li></ul><p><strong>Solver</strong></p><p>Pixi solves both the conda and PyPI dependencies.</p><ul><li>Pixi solves both the conda and PyPI dependencies, where the PyPI dependencies use the conda packages as a base, so you can be sure that the packages are compatible with each other.</li><li>These solvers are split between the <a href="https://github.com/mamba-org/rattler">rattler</a> and <a href="https://github.com/astral-sh/uv">uv</a> library, these control the heavy lifting of the solving process, which is executed by our custom SAT solver: <a href="https://github.com/mamba-org/resolvo">resolvo</a>.</li><li>resolve is able to solve multiple ecosystem like conda and PyPI. It implements the lazy solving process for PyPI packages, which means that it only downloads the metadata of the packages that are needed to solve the environment. It also supports the conda way of solving, which means that it downloads the metadata of all the packages at once and then solves in one go.</li><li>For the [pypi-dependencies], uv implements sdist building to retrieve the metadata of the packages, and wheel building to install the packages. For this building step, pixi requires to first install python in the (conda)[dependencies] section of the pixi.toml file. This will always be slower than the pure conda solves. So for the best pixi experience you should stay within the [dependencies] section of the pixi.toml file.</li></ul><p><strong>Environment Variables</strong></p><p>The following environment variables are set by pixi, when using the pixi run, pixi shell, or pixi shell-hook command:</p><ul><li>PIXI_PROJECT_ROOT: The root directory of the project.</li><li>PIXI_PROJECT_NAME: The name of the project.</li><li>PIXI_PROJECT_MANIFEST: The path to the manifest file (pixi.toml).</li><li>PIXI_PROJECT_VERSION: The version of the project.</li><li>PIXI_PROMPT: The prompt to use in the shell, also used by pixi shell itself.</li><li>PIXI_ENVIRONMENT_NAME: The name of the environment, defaults to default.</li><li>PIXI_ENVIRONMENT_PLATFORMS: Comma separated list of platforms supported by the project.</li><li>CONDA_PREFIX: The path to the environment. (Used by multiple tools that already understand conda environments)</li><li>CONDA_DEFAULT_ENV: The name of the environment. (Used by multiple tools that already understand conda environments)</li><li>PATH: We prepend the bin directory of the environment to the PATH variable, so you can use the tools installed in the environment directly.</li><li>INIT_CWD: ONLY IN pixi run: The directory where the command was run from</li></ul><h4>Our task runner: deno_task_shell</h4><p>To support the different OS’s (Windows, OSX and Linux), pixi integrates a shell that can run on all of them. This is deno_task_shell. The task shell is a limited implementation of a bourne-shell interface.</p><p>Note — The facts stated above are taken from the pixi documentation. Some views belong to author. Pls cite them before using.</p><p>References:</p><ol><li><a href="https://realpython.com/python-virtual-environments-a-primer/">Python Virtual Environments: A Primer — Real Python</a></li><li><a href="https://www.pythonguis.com/tutorials/python-virtual-environments/">Setting Your Python Working Environment, the Right Way</a></li><li><a href="https://pyjourney.com/getting-started-with-python/python-virtual-environments-why-and-how-to-use-them/">20. Python Virtual Environments: Why and How to Use Them | PyJourney</a></li><li><a href="https://pixi.sh/latest/features/multi_environment/#feature-environment-set-definitions">https://pixi.sh/latest/features/multi_environment/#feature-environment-set-definitions</a></li><li><a href="https://prefix.dev/">prefix.dev</a></li><li><a href="https://packaging.python.org/en/latest/guides/writing-pyproject-toml/">Writing your pyproject.toml — Python Packaging User Guide</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42b89f033306" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make Your GPT Responses Come Alive with Interactivity]]></title>
            <link>https://medium.com/@shiprasakshi/make-your-gpt-responses-come-alive-with-interactivity-a5d399a91ec3?source=rss-fd36b2428285------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5d399a91ec3</guid>
            <dc:creator><![CDATA[Sakshi Dhama]]></dc:creator>
            <pubDate>Thu, 22 Aug 2024 22:07:59 GMT</pubDate>
            <atom:updated>2024-08-23T10:01:01.713Z</atom:updated>
            <content:encoded><![CDATA[<p>In the rapidly evolving landscape of artificial intelligence and machine learning operations (MLOps), the ability to interact with AI models in real-time is becoming increasingly crucial. The ChatCompletion API, particularly with its streaming responses feature, stands at the forefront of this evolution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w3rO-MfyT9nOLB7lvr-6wA.jpeg" /><figcaption>Engaging users: Are progress bar an old thing ?</figcaption></figure><h3><strong>What is Streaming</strong></h3><p>Streaming provides immediate, incremental outputs as the model processes the input. It involves the continuous transmission data from a server to a client. This method allows the content to be read as it is received, without the need for the data to be downloaded first.</p><pre>[User Input] -&gt; [API Request to ChatCompletion] -&gt; [Stream Initiation]  <br>                                                       |  <br>     +------------+------------+------------+          |  <br>     | Token 1    | Token 2    | Token 3    |  ......  |  <br>     +------------+------------+------------+          |  <br>                                                       |  <br>                                  [Assembling Response]  <br>                                            |  <br>                                  [Final Response to User]</pre><p>Streaming services often rely on centralized servers and deliver content in a sequential manner, tailored to the receiver’s immediate needs.</p><h3><strong>Why do we need Streaming</strong></h3><ul><li><strong>Interactive</strong> streaming is particularly vital in applications requiring real-time feedback, such as conversational AI, live customer support bots, or interactive educational tools.</li><li>The necessity for streaming responses emerges from the need to enhance <strong>user experience</strong>, <strong>reduce latency</strong> in communication, and accommodate the growing demand for more sophisticated and responsive AI-driven applications.</li><li>With streaming responses, developers can create more <strong>engaging and efficient interfaces</strong> that capitalize on the immediacy and accuracy of AI responses, making the technology not just a tool, but a seamless extension of human interaction.</li></ul><p><strong>Summary</strong> — I am impatient and anxious while staring at blank screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yU4cXOqIptx_I4qP--QRwQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*THjXROIsQgziYJuWE66f0w.jpeg" /><figcaption>Courtesy Microsoft CoPilot Dalle 3</figcaption></figure><p><strong>Example</strong> of using streaming mode on Azure Open AI Deployments using streaming model</p><pre>import sys<br>import time<br>from openai import AzureOpenAI<br><br>endpoint = &quot;&quot;<br>key = &quot;&quot;<br>deployment = &quot;gpt-4o-2024-05-13&quot;<br><br>client = AzureOpenAI(<br>    azure_endpoint=endpoint,<br>    azure_deployment=deployment,<br>    api_key=key,<br>    api_version=&quot;2024-05-01-preview&quot;,<br>)<br><br>start_time = time.time()<br><br># ChatCompletion request<br>completion = client.chat.completions.create(<br>    model=deployment,<br>    messages=[<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: &quot;Get 10 countries capitals as json. eg: {&#39;country&#39;: &#39;capital&#39;}&quot;,<br>        }<br>    ],<br>    temperature=0,<br>    stream=True,<br>    response_format={&quot;type&quot;: &quot;json_object&quot;},<br>)<br><br>segment = &quot;&quot;<br><br>final_output = &quot;&quot;<br><br>try:<br>    for idx, chunk in enumerate(completion):<br>        if chunk.choices:<br>            content = chunk.choices[0].delta.content<br>            if content is None:<br>                content = &quot;&quot;<br><br>            final_output = final_output + content<br><br>            segment = segment + content<br><br>            if &quot;,&quot; in content:<br>                print(f&quot;{segment}&quot;)<br><br>                segment = &quot;&quot;<br><br>            sys.stdout.flush()<br><br>            time.sleep(0.05)<br><br>        else:<br>            pass<br><br>except Exception as e:<br>    print(f&quot;Error: {e}&quot;)<br><br>finally:<br>    # print last segment which might not contain ,<br>    print(f&quot;{segment}&quot;)<br>    print(&quot; **** Done ****&quot;)<br><br>print(f&quot;Time taken: {time.time() - start_time}&quot;)<br><br>print(f&quot;{final_output=}&quot;)</pre><h3>Implementation Considerations:</h3><p>While stream mode offers many advantages, it is essential to handle the streaming data appropriately. Developers should ensure that the application can process and display incremental data efficiently. Additionally, managing network latency and handling errors gracefully are critical for maintaining a smooth user experience.</p><p>In summary, leveraging stream mode in chat completion is a powerful approach to building responsive and interactive AI-driven applications. By providing real-time feedback and improving user engagement, streaming can significantly enhance the effectiveness and appeal of conversational interfaces.</p><p><strong>References</strong></p><ul><li><a href="https://platform.openai.com/docs/api-reference/streaming">API Reference — OpenAI API</a> — <strong>ChatCompletion Streaming documentation</strong></li><li><a href="https://learn.microsoft.com/en-us/azure/machine-learning/prompt-flow/how-to-enable-streaming-mode?view=azureml-api-2">How to use streaming endpoints deployed from prompt Flow — Azure Machine Learning | Microsoft Learn</a> — <strong>Streaming in promptflow</strong></li><li><a href="https://docs.python.org/3/library/io.html">io — Core tools for working with streams — Python 3.12.5 documentation</a> — <strong>Package to handle json stream</strong></li><li><a href="https://til.simonwillison.net/gpt3/python-chatgpt-streaming-api">Using the ChatGPT streaming API from Python | Simon Willison’s TILs</a> — <strong>Example of streaming in chatcompletion API</strong></li><li><a href="https://til.simonwillison.net/json/ijson-stream">Processing a stream of chunks of JSON with ijson | Simon Willison’s TILs</a> — <strong>Streaming in JSON Mode</strong></li><li><a href="https://til.simonwillison.net/gpt3/openai-python-functions-data-extraction">Using OpenAI functions and their Python library for data extraction | Simon Willison’s TIL</a> — <strong>Using function and streaming together</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5d399a91ec3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[L1 and L2 Norm]]></title>
            <link>https://medium.com/@shiprasakshi/l1-and-l2-norm-a93b672cfa6c?source=rss-fd36b2428285------2</link>
            <guid isPermaLink="false">https://medium.com/p/a93b672cfa6c</guid>
            <dc:creator><![CDATA[Sakshi Dhama]]></dc:creator>
            <pubDate>Thu, 09 May 2024 07:23:45 GMT</pubDate>
            <atom:updated>2024-05-09T07:23:45.161Z</atom:updated>
            <content:encoded><![CDATA[<p>The norm of a vector in vector space is a real non-negative value representing intuitively the length, size or magnitude of the vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*Kf0A_W0Ojfw5hYffTcTAsg.png" /></figure><p>Here, on right hand side we have a vector of unit length and with same direction as the original vector in the numerator on the left. To understand L1 and L2, one must know that norm is something that indicate the power (1 and 2). <br>Both L1 and L2 norm results in unit length vector. But how the denominator for each is different.</p><p>It can be done in two ways: Manhattan distance and Euclidian distance.<br> <br>1. Calculating L1 norm (Manhattan distance)</p><p>Distance between two points (x1,y1) and (x2,y2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SS74GZG6wI6P27c_R6wlVA.png" /></figure><p>2. Calculating L2 norm (Euclidean distance)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BMYMSOdETkPVjyL5yMcDsw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a93b672cfa6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Yaml]]></title>
            <link>https://medium.com/@shiprasakshi/what-is-yaml-d0ced9f36e41?source=rss-fd36b2428285------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0ced9f36e41</guid>
            <dc:creator><![CDATA[Sakshi Dhama]]></dc:creator>
            <pubDate>Sat, 03 Feb 2024 23:33:10 GMT</pubDate>
            <atom:updated>2024-04-11T09:46:58.746Z</atom:updated>
            <content:encoded><![CDATA[<p>Yaml is a data serialization language commonly used in data science projects for configurations in all programming languages. Yaml presents data in a easier human readable language.</p><p>A yaml file ends with.yaml/.yml extension.</p><p><strong>Why and what of a yaml file ?</strong></p><ul><li>Beside easy to understand and implement Yaml comes with the support of native data structures of agile languages, a consistent model to support generic tools such as Kubernetes, Ansible, Terraform.</li><li>Yaml is parsed linearly in one direction, therefor there are no parsing ambiguity due to absence of forward or backward pointers to deal with.</li><li>Yaml are easier to use to write even complex structures and can be source tracked.</li><li>The commonly found use cases of yaml are configuration files, log files, cross language data sharing etc.</li></ul><p>A YAML format primarily uses 3 node types:</p><ol><li><strong>Maps or Dictionaries</strong> (<em>mapping</em>): Maps consists of unordered set of key-value node pairs where key is unique.</li><li><strong>Arrays or Lists</strong> (<em>sequences</em>): Sequence node is an ordered series of zero or more nodes which can be embedded inside a map using indentation.. Sequences in YAML are represented by using the hyphen (-) and space.</li><li><strong>Literals</strong> (Strings, numbers, boolean, etc.):<br>The content of a <em>scalar</em> node is an opaque datum that can be presented as a series of zero or more <em>Unicode characters</em>.</li></ol><p>Given below is the example of .pre-commit-config.yaml which a file used to install pre-commit hooks in the python’s virtual environments</p><pre># key: value is an array [sequence]<br>repos:<br>-   repo: https://github.com/charliermarsh/ruff-pre-commit<br>    #string [literal]<br>    rev: &#39;v0.1.14&#39;<br>    hooks:<br>        # key: value [mapping]<br>    -   id: ruff<br>        types_or: [ python, pyi, jupyter ]<br>        args: [--fix]<br>    -   id: ruff-format<br>        types_or: [ python, pyi, jupyter ]<br>-   repo: https://github.com/kynan/nbstripout<br>    rev: &#39;0.6.1&#39;<br>    hooks:<br>    -   id: nbstripout<br>-   repo: https://github.com/pre-commit/pre-commit-hooks<br>    rev: &#39;v4.5.0&#39;<br>    hooks:<br>    -   id: check-ast<br>    -   id: end-of-file-fixer<br>        exclude: conda.yml<br>    -   id: trailing-whitespace<br>    -   id: check-yaml<br>        exclude: conda.yml<br>    -   id: check-toml<br>    -   id: check-json<br>-   repo: https://github.com/sqlfluff/sqlfluff<br>    rev: &#39;3.0.0a4&#39;<br>    hooks:<br>    -   id: sqlfluff-fix<br>        args: [&#39;--dialect=tsql&#39;, &#39;--exclude-rules=L016,L031&#39;]<br>    -   id: sqlfluff-lint<br>        args: [&#39;--dialect=tsql&#39;, &#39;--exclude-rules=L016,L031&#39;]<br>-   repo: local<br>    hooks:<br>    -   id: conda-export<br>        name: conda-export<br>        entry: python -m conda<br>        language: python<br>        additional_dependencies: [toml, pyyaml]<br>        pass_filenames: false<br>        always_run: true<br>-   repo: https://github.com/jazzband/pip-tools<br>    rev: &#39;7.3.0&#39;<br>    hooks:<br>    -   id: pip-compile<br>        name: pip-compile-requirements<br>        args: [&#39;--output-file=requirements.txt&#39;, &#39;--allow-unsafe&#39;, &#39;--resolver=backtracking&#39;]<br>        files: ^(pyproject\.toml|requirements\.txt)$<br>    -   id: pip-compile<br>        name: pip-compile-requirements-dev<br>        args: [&#39;--output-file=requirements-dev.txt&#39;, &#39;--allow-unsafe&#39;, &#39;--resolver=backtracking&#39;, &#39;--extra=dev&#39;]<br>        files: ^(pyproject\.toml|requirements-dev\.txt)$</pre><p>References</p><p><a href="https://developer.ibm.com/tutorials/yaml-basics-and-usage-in-kubernetes/">YAML basics in Kubernetes — IBM Developer</a></p><p><a href="https://yaml.org/">The Official YAML Web Site</a></p><p><a href="https://www.educative.io/answers/what-are-the-advantages-of-using-yaml-over-other-data-formats">What are the advantages of using YAML over other data formats? (educative.io)</a></p><p><a href="https://pre-commit.com/">pre-commit</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0ced9f36e41" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>