|
49 | 49 | "\n",
|
50 | 50 | "- **Engagement**: By revealing information gradually, we can maintain student engagement and encourage active participation in the problem-solving process.\n",
|
51 | 51 | "\n",
|
52 |
| - "- **Real-world Problem Solving**: In many real-world scenarios, solutions are not immediately apparent and must be approached incrementally. Training students to think in this way prepares them for challenges beyond the classroom.\n", |
| 52 | + "- **Real-world Problem Solving**: In many real-world scenarios, solutions are not immediately apparent and must be approached incrementally. Training students to think in this way prepares them for challenges beyond the classroom.\n" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "markdown", |
| 57 | + "metadata": {}, |
| 58 | + "source": [ |
| 59 | + "Installing LazyLM\n", |
53 | 60 | "\n",
|
| 61 | + "`pip install lazy_lm`" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "markdown", |
| 66 | + "metadata": {}, |
| 67 | + "source": [ |
| 68 | + "Using LazyLM" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "code", |
| 73 | + "execution_count": 1, |
| 74 | + "metadata": {}, |
| 75 | + "outputs": [], |
| 76 | + "source": [ |
| 77 | + "from dotenv import load_dotenv\n", |
| 78 | + "import os\n", |
| 79 | + "from anthropic import AnthropicVertex\n", |
| 80 | + "from lazy_lm.core import lazy\n", |
| 81 | + "\n", |
| 82 | + "load_dotenv()\n", |
| 83 | + "project_id = os.getenv(\"PROJECT_ID\")\n", |
| 84 | + "location = os.getenv(\"PROJECT_LOCATION\")\n" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "execution_count": 8, |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [], |
| 92 | + "source": [ |
| 93 | + "# Initalize the Anthropic client\n", |
| 94 | + "client = AnthropicVertex(project_id=project_id, region=location)\n", |
| 95 | + "lazy_lm = client.lazy(\"What is the derivative of `2x^3 + x^2 + 2x + 1`? Give me the solution step-by-step\")" |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "code", |
| 100 | + "execution_count": 9, |
| 101 | + "metadata": {}, |
| 102 | + "outputs": [ |
| 103 | + { |
| 104 | + "name": "stdout", |
| 105 | + "output_type": "stream", |
| 106 | + "text": [ |
| 107 | + "What is the derivative of `2x^3 + x^2 + 2x + 1`? Give me the solution step-by-step\n" |
| 108 | + ] |
| 109 | + } |
| 110 | + ], |
| 111 | + "source": [ |
| 112 | + "# Get the current step\n", |
| 113 | + "print(lazy_lm.get_current_step())" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "execution_count": 10, |
| 119 | + "metadata": {}, |
| 120 | + "outputs": [ |
| 121 | + { |
| 122 | + "name": "stdout", |
| 123 | + "output_type": "stream", |
| 124 | + "text": [ |
| 125 | + "To find the derivative of the given function, we'll use the power rule and the constant rule of differentiation. Let's start with the first term:\n", |
| 126 | + "\n", |
| 127 | + "Step 1: Find the derivative of 2x^3\n", |
| 128 | + "\n", |
| 129 | + "The power rule states that for a term ax^n, the derivative is nax^(n-1).\n", |
| 130 | + "For 2x^3, we have:\n", |
| 131 | + "a = 2, n = 3\n", |
| 132 | + "So, the derivative of 2x^\n" |
| 133 | + ] |
| 134 | + } |
| 135 | + ], |
| 136 | + "source": [ |
| 137 | + "# Get the next step\n", |
| 138 | + "print(lazy_lm.get_next_step())" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "code", |
| 143 | + "execution_count": 11, |
| 144 | + "metadata": {}, |
| 145 | + "outputs": [ |
| 146 | + { |
| 147 | + "name": "stdout", |
| 148 | + "output_type": "stream", |
| 149 | + "text": [ |
| 150 | + "I apologize for any confusion. I'd be happy to explain this step in more detail without advancing to the next step.\n", |
| 151 | + "\n", |
| 152 | + "In this step, we're focusing on finding the derivative of the first term in the given expression, which is 2x^3.\n", |
| 153 | + "\n", |
| 154 | + "To do this, we're using the power rule of differentiation. The power rule states that for a term in the form ax^n (where 'a' is a constant and 'n' is the power\n" |
| 155 | + ] |
| 156 | + } |
| 157 | + ], |
| 158 | + "source": [ |
| 159 | + "# Query the current step\n", |
| 160 | + "print(lazy_lm.ask_question(\"I don't understand this step\"))" |
| 161 | + ] |
| 162 | + }, |
| 163 | + { |
| 164 | + "cell_type": "code", |
| 165 | + "execution_count": 12, |
| 166 | + "metadata": {}, |
| 167 | + "outputs": [ |
| 168 | + { |
| 169 | + "name": "stdout", |
| 170 | + "output_type": "stream", |
| 171 | + "text": [ |
| 172 | + "Step 2: Complete the derivative of 2x^3\n", |
| 173 | + "\n", |
| 174 | + "Continuing from the previous step, we apply the power rule to 2x^3:\n", |
| 175 | + "\n", |
| 176 | + "The derivative of 2x^3 is:\n", |
| 177 | + "3 · 2x^(3-1) = 3 · 2x^2 = 6x^2\n" |
| 178 | + ] |
| 179 | + } |
| 180 | + ], |
| 181 | + "source": [ |
| 182 | + "# Get the next step\n", |
| 183 | + "print(lazy_lm.get_next_step())" |
| 184 | + ] |
| 185 | + }, |
| 186 | + { |
| 187 | + "cell_type": "markdown", |
| 188 | + "metadata": {}, |
| 189 | + "source": [ |
54 | 190 | "## Understanding Lazy Evaluation\n",
|
55 | 191 | "\n",
|
56 |
| - "## A Note on Lazy Evaluation in Programming\n", |
| 192 | + "### A Note on Lazy Evaluation in Programming\n", |
57 | 193 | "\n",
|
58 | 194 | "The concept of lazy evaluation is well-established in functional programming languages, where the evaluation of an expression is only done when the value of the expression is needed. This is also known as call-by-need. The contrast to this evaluation strategy is what's called \"eager\" or strict evaluation.\n",
|
59 | 195 | "\n",
|
|
184 | 320 | "outputs": [],
|
185 | 321 | "source": []
|
186 | 322 | },
|
187 |
| - { |
188 |
| - "cell_type": "code", |
189 |
| - "execution_count": null, |
190 |
| - "metadata": {}, |
191 |
| - "outputs": [], |
192 |
| - "source": [] |
193 |
| - }, |
194 | 323 | {
|
195 | 324 | "cell_type": "code",
|
196 | 325 | "execution_count": null,
|
|
0 commit comments