less than 1 minute read

Experimenting with DSPy, Pt. I

As part of me learning more about LLMs, I’m working through different use cases, tools, and examples that I find online. Right now, I’m learning about DSPy. This notebook will walk through the intro “Hello World” example from the DSPy Github repo. My own version is in this notebook.

Overview of DSPy

[more setup]

DSPy

Working through a “Hello World” example from the DSPy docs

We’ll be following the example notebook from the DSPy docs. Here is my version of the notebook.

Setup

First, we’ll install the necessary packages:

%load_ext autoreload
%autoreload 2

import sys
import os

try: # When on google Colab, let's clone the notebook so we download the cache.
    import google.colab
    repo_path = 'dspy'
    !git -C $repo_path pull origin || git clone https://github.com/stanfordnlp/dspy $repo_path
except:
    repo_path = '.'

if repo_path not in sys.path:
    sys.path.append(repo_path)

# Set up the cache for this notebook
os.environ["DSP_NOTEBOOK_CACHEDIR"] = os.path.join(repo_path, 'cache')

import pkg_resources # Install the package if it's not installed
if not "dspy-ai" in {pkg.key for pkg in pkg_resources.working_set}:
    !pip install -U pip
    !pip install dspy-ai
    !pip install openai~=0.28.1
    # !pip install -e $repo_path

import dspy