-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: debug and fix thanks to @JasonWeill in jupyterlab/jupyter-ai#746
- Loading branch information
Showing
3 changed files
with
178 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"execution_count": 3, | ||
"id": "42d67f40-462b-43ba-a63f-fdd9e126a423", | ||
"metadata": {}, | ||
"outputs": [], | ||
|
@@ -78,51 +78,149 @@ | |
"id": "b93d0cb3-9844-4b3d-8778-360ec07b20ac", | ||
"metadata": {}, | ||
"source": [ | ||
"# 3. Recreate example from Readme\n", | ||
"\n", | ||
"https://github.com/jupyterlab/jupyter-ai shows this example: https://github.com/jupyterlab/jupyter-ai/blob/main/docs/source/_static/sample-html-math.png" | ||
"# 3. Test the models" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "9ae14480-b195-4686-9c80-70654bccfd24", | ||
"execution_count": 8, | ||
"id": "af16e864-8beb-4ea2-93d0-c74b6b595f85", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/Users/me/jaanli/language-model-notebooks/.venv/lib/python3.12/site-packages/langchain_anthropic/llms.py:164: UserWarning: This Anthropic LLM is deprecated. Please use `from langchain_anthropic import ChatAnthropic` instead\n", | ||
" warnings.warn(\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\"> \n", | ||
" <rect x=\"0\" y=\"0\" width=\"100\" height=\"100\" style=\"stroke:black;fill:white;\"/> \n", | ||
"</svg>" | ||
"AI generated code inserted below ⬇️" | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.HTML object>" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"execution_count": 8, | ||
"metadata": { | ||
"text/html": { | ||
"jupyter_ai": { | ||
"model_id": "claude-v1.2", | ||
"provider_id": "anthropic" | ||
"model_id": "claude-3-opus-20240229", | ||
"provider_id": "anthropic-chat" | ||
} | ||
} | ||
}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"%%ai anthropic:claude-v1.2 -f html\n", | ||
"Create a square using SVG with a black border and white fill." | ||
"%%ai anthropic-chat:claude-3-opus-20240229 --format code \n", | ||
"Create and visualize an interactive plot of the world's population using python and the altair library." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "a5320525-d508-4de0-abce-e4c776db0d54", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
"<style>\n", | ||
" #altair-viz-3c2dc2fe93674313bc7b8a770e6ca792.vega-embed {\n", | ||
" width: 100%;\n", | ||
" display: flex;\n", | ||
" }\n", | ||
"\n", | ||
" #altair-viz-3c2dc2fe93674313bc7b8a770e6ca792.vega-embed details,\n", | ||
" #altair-viz-3c2dc2fe93674313bc7b8a770e6ca792.vega-embed details summary {\n", | ||
" position: relative;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<div id=\"altair-viz-3c2dc2fe93674313bc7b8a770e6ca792\"></div>\n", | ||
"<script type=\"text/javascript\">\n", | ||
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", | ||
" (function(spec, embedOpt){\n", | ||
" let outputDiv = document.currentScript.previousElementSibling;\n", | ||
" if (outputDiv.id !== \"altair-viz-3c2dc2fe93674313bc7b8a770e6ca792\") {\n", | ||
" outputDiv = document.getElementById(\"altair-viz-3c2dc2fe93674313bc7b8a770e6ca792\");\n", | ||
" }\n", | ||
" const paths = {\n", | ||
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", | ||
" \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n", | ||
" \"vega-lite\": \"https://cdn.jsdelivr.net/npm/[email protected]?noext\",\n", | ||
" \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n", | ||
" };\n", | ||
"\n", | ||
" function maybeLoadScript(lib, version) {\n", | ||
" var key = `${lib.replace(\"-\", \"\")}_version`;\n", | ||
" return (VEGA_DEBUG[key] == version) ?\n", | ||
" Promise.resolve(paths[lib]) :\n", | ||
" new Promise(function(resolve, reject) {\n", | ||
" var s = document.createElement('script');\n", | ||
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n", | ||
" s.async = true;\n", | ||
" s.onload = () => {\n", | ||
" VEGA_DEBUG[key] = version;\n", | ||
" return resolve(paths[lib]);\n", | ||
" };\n", | ||
" s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", | ||
" s.src = paths[lib];\n", | ||
" });\n", | ||
" }\n", | ||
"\n", | ||
" function showError(err) {\n", | ||
" outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", | ||
" throw err;\n", | ||
" }\n", | ||
"\n", | ||
" function displayChart(vegaEmbed) {\n", | ||
" vegaEmbed(outputDiv, spec, embedOpt)\n", | ||
" .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", | ||
" }\n", | ||
"\n", | ||
" if(typeof define === \"function\" && define.amd) {\n", | ||
" requirejs.config({paths});\n", | ||
" require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", | ||
" } else {\n", | ||
" maybeLoadScript(\"vega\", \"5\")\n", | ||
" .then(() => maybeLoadScript(\"vega-lite\", \"5.17.0\"))\n", | ||
" .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n", | ||
" .catch(showError)\n", | ||
" .then(() => displayChart(vegaEmbed));\n", | ||
" }\n", | ||
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"url\": \"https://cdn.jsdelivr.net/npm/[email protected]/data/population.json\"}, \"mark\": {\"type\": \"line\"}, \"encoding\": {\"color\": {\"field\": \"age\", \"type\": \"nominal\"}, \"tooltip\": [{\"field\": \"year\", \"type\": \"ordinal\"}, {\"aggregate\": \"sum\", \"field\": \"people\", \"type\": \"quantitative\"}, {\"field\": \"age\", \"type\": \"nominal\"}], \"x\": {\"field\": \"year\", \"type\": \"ordinal\"}, \"y\": {\"aggregate\": \"sum\", \"field\": \"people\", \"type\": \"quantitative\"}}, \"height\": 400, \"params\": [{\"name\": \"param_2\", \"select\": {\"type\": \"interval\", \"encodings\": [\"x\", \"y\"]}, \"bind\": \"scales\"}], \"title\": \"World Population by Age Group\", \"transform\": [{\"filter\": \"(datum.year >= 1850)\"}], \"width\": 600, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.17.0.json\"}, {\"mode\": \"vega-lite\"});\n", | ||
"</script>" | ||
], | ||
"text/plain": [ | ||
"alt.Chart(...)" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import altair as alt\n", | ||
"from vega_datasets import data\n", | ||
"\n", | ||
"# Load the population data\n", | ||
"pop_data = data.population.url\n", | ||
"\n", | ||
"# Create the interactive plot\n", | ||
"plot = alt.Chart(pop_data).mark_line().encode(\n", | ||
" x='year:O',\n", | ||
" y='sum(people):Q',\n", | ||
" color='age:N',\n", | ||
" tooltip=['year:O', 'sum(people):Q', 'age:N']\n", | ||
").properties(\n", | ||
" width=600,\n", | ||
" height=400,\n", | ||
" title='World Population by Age Group'\n", | ||
").transform_filter(\n", | ||
" alt.datum.year >= 1850\n", | ||
").interactive()\n", | ||
"\n", | ||
"# Display the plot\n", | ||
"plot" | ||
] | ||
} | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
jupyter-ai | ||
jupyterlab | ||
python-dotenv | ||
langchain-anthropic | ||
langchain-anthropic | ||
pandas | ||
ipywidgets | ||
numpy | ||
matplotlib | ||
altair | ||
vega_datasets |
Oops, something went wrong.