Skip to content

Commit

Permalink
added examples to index
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianni Crivello authored and Gianni Crivello committed Aug 21, 2024
1 parent 79e4b0d commit d87b9e7
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lazy_lm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# %% ../nbs/00_core.ipynb 3
from dotenv import load_dotenv
import os
from anthropic import AnthropicVertex
from anthropic.types import (
MessageParam,
Expand All @@ -22,6 +21,7 @@
List,
Optional
)
import os
from nbdev.showdoc import show_doc

# %% ../nbs/00_core.ipynb 7
Expand Down Expand Up @@ -160,5 +160,5 @@ def lazy(self: AnthropicVertex, problem: str) -> LazyEvaluationClient:
Entry point of the LazyLM Framework for the `AnthropicVertex` client API
"""
state = LazyState(problem=problem)
llm = LLM(client=self, model=model)
llm = LLM(client=self, model="claude-3-5-sonnet@20240620")
return LazyEvaluationClient(llm=llm, state=state)
10 changes: 5 additions & 5 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"#| hide\n",
"#| export\n",
"from dotenv import load_dotenv\n",
"import os\n",
"from anthropic import AnthropicVertex\n",
"from anthropic.types import (\n",
" MessageParam,\n",
Expand All @@ -54,6 +53,7 @@
" List,\n",
" Optional\n",
")\n",
"import os\n",
"from nbdev.showdoc import show_doc"
]
},
Expand Down Expand Up @@ -96,7 +96,7 @@
],
"source": [
"#| hide\n",
"project_id = os.getenv(\"CLAUDE_PROJECT_ID\")\n",
"project_id = os.getenv(\"PROJECT_ID\")\n",
"location = os.getenv(\"PROJECT_LOCATION\")\n",
"model = os.getenv(\"CLAUDE_MODEL\")\n",
"\n",
Expand Down Expand Up @@ -440,7 +440,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -559,7 +559,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -570,7 +570,7 @@
" Entry point of the LazyLM Framework for the `AnthropicVertex` client API\n",
" \"\"\"\n",
" state = LazyState(problem=problem)\n",
" llm = LLM(client=self, model=model)\n",
" llm = LLM(client=self, model=\"claude-3-5-sonnet@20240620\")\n",
" return LazyEvaluationClient(llm=llm, state=state)"
]
},
Expand Down
147 changes: 138 additions & 9 deletions nbs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,147 @@
"\n",
"- **Engagement**: By revealing information gradually, we can maintain student engagement and encourage active participation in the problem-solving process.\n",
"\n",
"- **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",
"- **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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Installing LazyLM\n",
"\n",
"`pip install lazy_lm`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using LazyLM"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv\n",
"import os\n",
"from anthropic import AnthropicVertex\n",
"from lazy_lm.core import lazy\n",
"\n",
"load_dotenv()\n",
"project_id = os.getenv(\"PROJECT_ID\")\n",
"location = os.getenv(\"PROJECT_LOCATION\")\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# Initalize the Anthropic client\n",
"client = AnthropicVertex(project_id=project_id, region=location)\n",
"lazy_lm = client.lazy(\"What is the derivative of `2x^3 + x^2 + 2x + 1`? Give me the solution step-by-step\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"What is the derivative of `2x^3 + x^2 + 2x + 1`? Give me the solution step-by-step\n"
]
}
],
"source": [
"# Get the current step\n",
"print(lazy_lm.get_current_step())"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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",
"\n",
"Step 1: Find the derivative of 2x^3\n",
"\n",
"The power rule states that for a term ax^n, the derivative is nax^(n-1).\n",
"For 2x^3, we have:\n",
"a = 2, n = 3\n",
"So, the derivative of 2x^\n"
]
}
],
"source": [
"# Get the next step\n",
"print(lazy_lm.get_next_step())"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I apologize for any confusion. I'd be happy to explain this step in more detail without advancing to the next step.\n",
"\n",
"In this step, we're focusing on finding the derivative of the first term in the given expression, which is 2x^3.\n",
"\n",
"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"
]
}
],
"source": [
"# Query the current step\n",
"print(lazy_lm.ask_question(\"I don't understand this step\"))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Step 2: Complete the derivative of 2x^3\n",
"\n",
"Continuing from the previous step, we apply the power rule to 2x^3:\n",
"\n",
"The derivative of 2x^3 is:\n",
"3 · 2x^(3-1) = 3 · 2x^2 = 6x^2\n"
]
}
],
"source": [
"# Get the next step\n",
"print(lazy_lm.get_next_step())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Understanding Lazy Evaluation\n",
"\n",
"## A Note on Lazy Evaluation in Programming\n",
"### A Note on Lazy Evaluation in Programming\n",
"\n",
"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",
"\n",
Expand Down Expand Up @@ -184,13 +320,6 @@
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit d87b9e7

Please sign in to comment.