Skip to content

Commit d87b9e7

Browse files
Gianni CrivelloGianni Crivello
Gianni Crivello
authored and
Gianni Crivello
committed
added examples to index
1 parent 79e4b0d commit d87b9e7

File tree

3 files changed

+145
-16
lines changed

3 files changed

+145
-16
lines changed

lazy_lm/core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
# %% ../nbs/00_core.ipynb 3
77
from dotenv import load_dotenv
8-
import os
98
from anthropic import AnthropicVertex
109
from anthropic.types import (
1110
MessageParam,
@@ -22,6 +21,7 @@
2221
List,
2322
Optional
2423
)
24+
import os
2525
from nbdev.showdoc import show_doc
2626

2727
# %% ../nbs/00_core.ipynb 7
@@ -160,5 +160,5 @@ def lazy(self: AnthropicVertex, problem: str) -> LazyEvaluationClient:
160160
Entry point of the LazyLM Framework for the `AnthropicVertex` client API
161161
"""
162162
state = LazyState(problem=problem)
163-
llm = LLM(client=self, model=model)
163+
llm = LLM(client=self, model="claude-3-5-sonnet@20240620")
164164
return LazyEvaluationClient(llm=llm, state=state)

nbs/00_core.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"#| hide\n",
3838
"#| export\n",
3939
"from dotenv import load_dotenv\n",
40-
"import os\n",
4140
"from anthropic import AnthropicVertex\n",
4241
"from anthropic.types import (\n",
4342
" MessageParam,\n",
@@ -54,6 +53,7 @@
5453
" List,\n",
5554
" Optional\n",
5655
")\n",
56+
"import os\n",
5757
"from nbdev.showdoc import show_doc"
5858
]
5959
},
@@ -96,7 +96,7 @@
9696
],
9797
"source": [
9898
"#| hide\n",
99-
"project_id = os.getenv(\"CLAUDE_PROJECT_ID\")\n",
99+
"project_id = os.getenv(\"PROJECT_ID\")\n",
100100
"location = os.getenv(\"PROJECT_LOCATION\")\n",
101101
"model = os.getenv(\"CLAUDE_MODEL\")\n",
102102
"\n",
@@ -440,7 +440,7 @@
440440
},
441441
{
442442
"cell_type": "code",
443-
"execution_count": 26,
443+
"execution_count": 32,
444444
"metadata": {},
445445
"outputs": [],
446446
"source": [
@@ -559,7 +559,7 @@
559559
},
560560
{
561561
"cell_type": "code",
562-
"execution_count": 30,
562+
"execution_count": 34,
563563
"metadata": {},
564564
"outputs": [],
565565
"source": [
@@ -570,7 +570,7 @@
570570
" Entry point of the LazyLM Framework for the `AnthropicVertex` client API\n",
571571
" \"\"\"\n",
572572
" state = LazyState(problem=problem)\n",
573-
" llm = LLM(client=self, model=model)\n",
573+
" llm = LLM(client=self, model=\"claude-3-5-sonnet@20240620\")\n",
574574
" return LazyEvaluationClient(llm=llm, state=state)"
575575
]
576576
},

nbs/index.ipynb

+138-9
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,147 @@
4949
"\n",
5050
"- **Engagement**: By revealing information gradually, we can maintain student engagement and encourage active participation in the problem-solving process.\n",
5151
"\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",
5360
"\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": [
54190
"## Understanding Lazy Evaluation\n",
55191
"\n",
56-
"## A Note on Lazy Evaluation in Programming\n",
192+
"### A Note on Lazy Evaluation in Programming\n",
57193
"\n",
58194
"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",
59195
"\n",
@@ -184,13 +320,6 @@
184320
"outputs": [],
185321
"source": []
186322
},
187-
{
188-
"cell_type": "code",
189-
"execution_count": null,
190-
"metadata": {},
191-
"outputs": [],
192-
"source": []
193-
},
194323
{
195324
"cell_type": "code",
196325
"execution_count": null,

0 commit comments

Comments
 (0)