LLMatie/chatbot_example.ipynb

816 lines
51 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "7acc51ac-8514-4e77-99d6-cfe31e74c2f1",
"metadata": {},
"outputs": [],
"source": [
"import uuid\n",
"from typing import Tuple\n",
"\n",
"import openai # replace with your favorite LLM client library\n",
"\n",
"from burr.core import action, State, ApplicationBuilder, when, persistence"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "4231194b-17f3-4aae-b6af-b6d7c2806625",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Due to travel restrictions resulting from COVID-19, Major League Baseball opted for a regular season division format instead of the traditional home and away schedule across two different cities during that year's World Series tournament in September/October. The series remained hotly contested between the Los Angeles Dodgers and Houston Astros with decisive victory to LA by 5-3, clinching their fifth title since moving from Brooklyn before they eventually moved back home after a hiatus of nearly three decades.\n"
]
}
],
"source": [
"# adding ollama\n",
"client = openai.OpenAI(\n",
" base_url = 'http://192.168.20.30:7869/v1',\n",
" api_key='ollama', # required, but unused\n",
")\n",
"model=\"phi3:3.8b\"\n",
"\n",
"\n",
"response = client.chat.completions.create(\n",
" model=model,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n",
" {\"role\": \"user\", \"content\": \"Who won the world series in 2020?\"},\n",
" {\"role\": \"assistant\", \"content\": \"The LA Dodgers won in 2020.\"},\n",
" {\"role\": \"user\", \"content\": \"Where was it played?\"}\n",
" ]\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "90ec821c-34ef-447d-a822-eccd25d694a8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"```json\n",
"\n",
"{\n",
"\n",
" \"function\": \"get_local_weather_update\",\n",
"\n",
" \"args\": [\"Australia\", \"Northern Territory\"],\n",
"\n",
" \"ai_notes\": {\n",
"\n",
" \"clarification\": \"The function is called with the country and state parameters for Uluru, ensuring that local weather conditions are accurately represented.\"\n",
"\n",
" }\n",
"\n",
"}\n",
"\n",
"```\n"
]
}
],
"source": [
"# adding ollama\n",
"client = openai.OpenAI(\n",
" base_url = 'http://192.168.20.30:7869/v1',\n",
" api_key='ollama', # required, but unused\n",
")\n",
"model=\"phi3:3.8b\"\n",
"\n",
"system = \"\"\"You are a helpful assistent, that only comunicates using JSON files.\n",
"The expected output from you has to be: \n",
" {\n",
" \"function\": {function_name},\n",
" \"args\": [],\n",
" \"ai_notes\": {explanation}\n",
" }\n",
"The INST block will always be a json string:\n",
" {\n",
" \"prompt\": {the user request}\n",
" }\n",
"Here are the functions available to you:\n",
" function_name=get_local_weather_update\n",
" args=[{country}, {state}]\n",
"\"\"\"\n",
"user = \"what is the weather in uluru now?\"\n",
"\n",
"\n",
"response = client.chat.completions.create(\n",
" model=model,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": system },\n",
" {\"role\": \"user\", \"content\": user},\n",
" ]\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "c8cc674d-21b3-4c30-8239-b0368fa21087",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"```json\n",
"\n",
"{\n",
"\n",
" \"business_type\": \"bar/restaurant\",\n",
" \n",
" \"location\": \"near Uluru, Alice Springs region in Northern Territory of Australia.\",\n",
" \n",
" \"ai_notes\": \"Uluru is a popular tourist destination; suitable options for dining might require travel from the immediate area or specific accommodations with such amenities.\"\n",
"\n",
"} \n",
"\n",
"```\n"
]
}
],
"source": [
"# adding ollama\n",
"client = openai.OpenAI(\n",
" base_url = 'http://192.168.20.30:7869/v1',\n",
" api_key='ollama', # required, but unused\n",
")\n",
"model=\"phi3:3.8b\"\n",
"\n",
"system = \"\"\"You are a helpful assistent, that only comunicates using JSON files.\n",
"The expected output from you has to be: \n",
" {\n",
" \"business_type\": {type},\n",
" \"location\": {location},\n",
" \"ai_notes\": {explanation}\n",
" }\n",
"\n",
"Limit the ai_notes to 200 characters or less.\n",
"Use the folowing text to inform your response:\n",
"\"\"\"\n",
"user = \"pizza and beers near uluru?\"\n",
"\n",
"\n",
"response = client.chat.completions.create(\n",
" model=model,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": system },\n",
" {\"role\": \"user\", \"content\": user},\n",
" ]\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "98aeaadc-1d08-49e0-967f-0c132bd5fba7",
"metadata": {},
"outputs": [],
"source": [
"# https://www.google.com/maps/search/Bars+and+pubs/@-37.7164557,145.0221223,3065m/\n",
"#"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "a2cf6272-9b48-42fc-885e-107461337ac9",
"metadata": {},
"outputs": [],
"source": [
"@action(reads=[], writes=[\"prompt\", \"chat_history\"])\n",
"def human_input(state: State, prompt: str) -> Tuple[dict, State]:\n",
" \"\"\"Pulls human input from the outside world and massages it into a standard chat format.\n",
" Note we're adding it into the chat history (with an `append` operation). This \n",
" is just for convenience of reference -- we could easily just store the chat history\n",
" and access it.\n",
" \"\"\"\n",
" \n",
" chat_item = {\n",
" \"content\": prompt,\n",
" \"role\": \"user\"\n",
" }\n",
" # return the prompt as the result\n",
" # put the prompt in state and update the chat_history\n",
" return (\n",
" {\"prompt\": prompt}, \n",
" state.update(prompt=prompt).append(chat_history=chat_item)\n",
" )\n",
"\n",
"@action(reads=[\"chat_history\"], writes=[\"response\", \"chat_history\"])\n",
"def ai_response(state: State) -> Tuple[dict, State]:\n",
" \"\"\"Queries OpenAI with the chat. You could easily use langchain, etc... to handle this,\n",
" but we wanted to keep it simple to demonstrate\"\"\"\n",
" # client = openai.Client() # replace with your favorite LLM client library\n",
" client = openai.OpenAI(\n",
" base_url = 'http://192.168.20.30:7869/v1',\n",
" api_key='ollama', # required, but unused\n",
" )\n",
" content = client.chat.completions.create(\n",
" # model=\"gpt-3.5-turbo\",\n",
" model=model,\n",
" messages=state[\"chat_history\"],\n",
" ).choices[0].message.content\n",
" chat_item = {\n",
" \"content\": content,\n",
" \"role\": \"assistant\"\n",
" }\n",
" # return the response as the result\n",
" # put the response in state and update the chat history\n",
" return (\n",
" {\"response\": content}, \n",
" state.update(response=content).append(chat_history=chat_item)\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "89c470aa-4ffd-4a7d-a271-b808836a2b2c",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"110pt\" height=\"177pt\"\n",
" viewBox=\"0.00 0.00 110.00 177.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 173)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-173 106,-173 106,4 -4,4\"/>\n",
"<!-- human_input -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>human_input</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M89.5,-103C89.5,-103 12.5,-103 12.5,-103 6.5,-103 0.5,-97 0.5,-91 0.5,-91 0.5,-78 0.5,-78 0.5,-72 6.5,-66 12.5,-66 12.5,-66 89.5,-66 89.5,-66 95.5,-66 101.5,-72 101.5,-78 101.5,-78 101.5,-91 101.5,-91 101.5,-97 95.5,-103 89.5,-103\"/>\n",
"<text text-anchor=\"middle\" x=\"51\" y=\"-80.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">human_input</text>\n",
"</g>\n",
"<!-- ai_response -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>ai_response</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M87,-37C87,-37 15,-37 15,-37 9,-37 3,-31 3,-25 3,-25 3,-12 3,-12 3,-6 9,0 15,0 15,0 87,0 87,0 93,0 99,-6 99,-12 99,-12 99,-25 99,-25 99,-31 93,-37 87,-37\"/>\n",
"<text text-anchor=\"middle\" x=\"51\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">ai_response</text>\n",
"</g>\n",
"<!-- human_input&#45;&gt;ai_response -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>human_input&#45;&gt;ai_response</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M44.88,-65.67C44.34,-59.99 44.15,-53.55 44.3,-47.33\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"47.8,-47.42 44.89,-37.23 40.81,-47.01 47.8,-47.42\"/>\n",
"</g>\n",
"<!-- input__prompt -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>input__prompt</title>\n",
"<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"102,-169 0,-169 0,-132 102,-132 102,-169\"/>\n",
"<text text-anchor=\"middle\" x=\"51\" y=\"-146.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: prompt</text>\n",
"</g>\n",
"<!-- input__prompt&#45;&gt;human_input -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>input__prompt&#45;&gt;human_input</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M51,-131.67C51,-125.99 51,-119.55 51,-113.33\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"54.5,-113.23 51,-103.23 47.5,-113.23 54.5,-113.23\"/>\n",
"</g>\n",
"<!-- ai_response&#45;&gt;human_input -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>ai_response&#45;&gt;human_input</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M57.11,-37.23C57.66,-42.91 57.85,-49.34 57.7,-55.57\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"54.2,-55.49 57.12,-65.67 61.19,-55.89 54.2,-55.49\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x79ff54e74050>"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"app = (\n",
" ApplicationBuilder().with_actions(\n",
" human_input=human_input,\n",
" ai_response=ai_response\n",
" ).with_transitions(\n",
" (\"human_input\", \"ai_response\"),\n",
" (\"ai_response\", \"human_input\")\n",
" ).with_state(chat_history=[])\n",
" .with_entrypoint(\"human_input\")\n",
" .build()\n",
")\n",
"app.visualize(output_file_path=\"digraph_initial\", format=\"png\")"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "5046b1bd-3d85-48d7-8bab-04533018dd64",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Aaron Burr was an American politician and Revolutionary War officer. Born in Cuthbert, New Jersey on February 6, 1756, he became a significant figure within the early political landscape of America as one of President Thomas Jefferson's original Cabinet members under the presidency of John Adams during his term from 1797 to 1801. Burr is perhaps best known for serving as Vice President under Thomas Jefferson and his subsequent role in what became historys most infamous duel - a conflict with Alexander Hamilton, where he fatally shot him on July 11, 1804 at the age of 48; an act that ended Burr's political career. His remains rest next to those of his wife, Theodosia Frances Lewis Barclay in honor of their shared love for science and exploration across continents - yet he was posthumously charged with treason but never tried due to the expiration of Congresss term at the end of Adams' presidency. After being elected as a Senator from New York, Burr pursued several business ventures, some financially unsuccessful leading up to his tragic duel; he spent his final years in seclusion on various islands without political ties or public stature that once marked him during the formative period of American nation-building.\n"
]
}
],
"source": [
"final_action, result, state = app.run(\n",
" halt_after=[\"ai_response\"], \n",
" inputs={\"prompt\" : \"Who was Aaron Burr?\"}\n",
")\n",
"print(state['response'])"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "d79c3cbf-431b-41cf-a9a8-c7a491f13d9e",
"metadata": {},
"outputs": [],
"source": [
"@action(reads=[\"prompt\"], writes=[\"safe\"])\n",
"def safety_check(state: State) -> Tuple[dict, State]:\n",
" safe = \"unsafe\" not in state[\"prompt\"]\n",
" return {\"safe\": safe}, state.update(safe=safe)\n",
"\n",
"\n",
"@action(reads=[], writes=[\"response\", \"chat_history\"])\n",
"def unsafe_response(state: State) -> Tuple[dict, State]:\n",
" content = \"I'm sorry, my overlords have forbidden me to respond.\"\n",
" new_state = (\n",
" state\n",
" .update(response=content)\n",
" .append(\n",
" chat_history={\"content\": content, \"role\": \"assistant\"})\n",
" )\n",
" return {\"response\": content}, new_state"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "7d996be8-ecfd-4e50-86ad-0bcd57a2e119",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"268pt\" height=\"263pt\"\n",
" viewBox=\"0.00 0.00 268.00 263.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 259)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-259 264,-259 264,4 -4,4\"/>\n",
"<!-- human_input -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>human_input</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M163.5,-187C163.5,-187 86.5,-187 86.5,-187 80.5,-187 74.5,-181 74.5,-175 74.5,-175 74.5,-162 74.5,-162 74.5,-156 80.5,-150 86.5,-150 86.5,-150 163.5,-150 163.5,-150 169.5,-150 175.5,-156 175.5,-162 175.5,-162 175.5,-175 175.5,-175 175.5,-181 169.5,-187 163.5,-187\"/>\n",
"<text text-anchor=\"middle\" x=\"125\" y=\"-164.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">human_input</text>\n",
"</g>\n",
"<!-- safety_check -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>safety_check</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M163.5,-119C163.5,-119 86.5,-119 86.5,-119 80.5,-119 74.5,-113 74.5,-107 74.5,-107 74.5,-94 74.5,-94 74.5,-88 80.5,-82 86.5,-82 86.5,-82 163.5,-82 163.5,-82 169.5,-82 175.5,-88 175.5,-94 175.5,-94 175.5,-107 175.5,-107 175.5,-113 169.5,-119 163.5,-119\"/>\n",
"<text text-anchor=\"middle\" x=\"125\" y=\"-96.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">safety_check</text>\n",
"</g>\n",
"<!-- human_input&#45;&gt;safety_check -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>human_input&#45;&gt;safety_check</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M125,-149.81C125,-143.6 125,-136.45 125,-129.6\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"128.5,-129.24 125,-119.24 121.5,-129.24 128.5,-129.24\"/>\n",
"</g>\n",
"<!-- input__prompt -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>input__prompt</title>\n",
"<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"176,-255 74,-255 74,-218 176,-218 176,-255\"/>\n",
"<text text-anchor=\"middle\" x=\"125\" y=\"-232.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: prompt</text>\n",
"</g>\n",
"<!-- input__prompt&#45;&gt;human_input -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>input__prompt&#45;&gt;human_input</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M125,-217.81C125,-211.6 125,-204.45 125,-197.6\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"128.5,-197.24 125,-187.24 121.5,-197.24 128.5,-197.24\"/>\n",
"</g>\n",
"<!-- ai_response -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>ai_response</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M84,-37C84,-37 12,-37 12,-37 6,-37 0,-31 0,-25 0,-25 0,-12 0,-12 0,-6 6,0 12,0 12,0 84,0 84,0 90,0 96,-6 96,-12 96,-12 96,-25 96,-25 96,-31 90,-37 84,-37\"/>\n",
"<text text-anchor=\"middle\" x=\"48\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">ai_response</text>\n",
"</g>\n",
"<!-- ai_response&#45;&gt;human_input -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>ai_response&#45;&gt;human_input</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M47.37,-37.31C47.41,-58.27 50.03,-93.45 65,-119 70.49,-128.37 78.52,-136.67 86.94,-143.64\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"84.99,-146.56 95.05,-149.9 89.27,-141.02 84.99,-146.56\"/>\n",
"</g>\n",
"<!-- safety_check&#45;&gt;ai_response -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>safety_check&#45;&gt;ai_response</title>\n",
"<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M93.8,-81.89C87.49,-77.51 81.2,-72.48 76,-67 70.16,-60.85 65.01,-53.26 60.77,-45.98\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"63.76,-44.15 55.91,-37.04 57.61,-47.49 63.76,-44.15\"/>\n",
"<text text-anchor=\"middle\" x=\"104\" y=\"-55.8\" font-family=\"Times,serif\" font-size=\"14.00\">safe=True</text>\n",
"</g>\n",
"<!-- unsafe_response -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>unsafe_response</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M248,-37C248,-37 146,-37 146,-37 140,-37 134,-31 134,-25 134,-25 134,-12 134,-12 134,-6 140,0 146,0 146,0 248,0 248,0 254,0 260,-6 260,-12 260,-12 260,-25 260,-25 260,-31 254,-37 248,-37\"/>\n",
"<text text-anchor=\"middle\" x=\"197\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">unsafe_response</text>\n",
"</g>\n",
"<!-- safety_check&#45;&gt;unsafe_response -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>safety_check&#45;&gt;unsafe_response</title>\n",
"<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M129.58,-81.83C132.73,-72.22 137.69,-60.58 145,-52 147.72,-48.81 150.83,-45.83 154.15,-43.07\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"156.28,-45.85 162.19,-37.05 152.09,-40.25 156.28,-45.85\"/>\n",
"<text text-anchor=\"middle\" x=\"174.5\" y=\"-55.8\" font-family=\"Times,serif\" font-size=\"14.00\">safe=False</text>\n",
"</g>\n",
"<!-- unsafe_response&#45;&gt;human_input -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>unsafe_response&#45;&gt;human_input</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M201.54,-37.27C202.56,-42.02 203.49,-47.18 204,-52 207.28,-82.78 203,-93.82 185,-119 178.44,-128.18 169.7,-136.56 160.93,-143.69\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"158.71,-140.98 152.93,-149.86 162.98,-146.53 158.71,-140.98\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x79ff54eae140>"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"safe_app = (\n",
" ApplicationBuilder().with_actions(\n",
" human_input=human_input,\n",
" ai_response=ai_response,\n",
" safety_check=safety_check,\n",
" unsafe_response=unsafe_response\n",
" ).with_transitions(\n",
" (\"human_input\", \"safety_check\"),\n",
" (\"safety_check\", \"unsafe_response\", when(safe=False)),\n",
" (\"safety_check\", \"ai_response\", when(safe=True)),\n",
" ([\"unsafe_response\", \"ai_response\"], \"human_input\"),\n",
" ).with_state(chat_history=[])\n",
" .with_entrypoint(\"human_input\")\n",
" .build()\n",
")\n",
"safe_app.visualize(output_file_path=\"digraph_safe\", include_conditions=True)\n"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "bb0bb883-a13f-4258-b4d9-d4302cc39813",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I'm sorry, my overlords have forbidden me to respond.\n"
]
}
],
"source": [
"action, result, state = safe_app.run(\n",
" halt_after=[\"ai_response\", \"unsafe_response\"], \n",
" inputs={\"prompt\": \"Who was Aaron Burr, sir (unsafe)?\"}\n",
")\n",
"print(state[\"response\"])"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "0a5c92fe-a0dc-40a2-a5c5-ac997b8244b7",
"metadata": {},
"outputs": [],
"source": [
"app_with_tracker = (\n",
" ApplicationBuilder().with_actions(\n",
" human_input=human_input,\n",
" ai_response=ai_response,\n",
" safety_check=safety_check,\n",
" unsafe_response=unsafe_response\n",
" ).with_transitions(\n",
" (\"human_input\", \"safety_check\"),\n",
" (\"safety_check\", \"unsafe_response\", when(safe=False)),\n",
" (\"safety_check\", \"ai_response\", when(safe=True)),\n",
" ([\"unsafe_response\", \"ai_response\"], \"human_input\"),\n",
" ).with_state(chat_history=[])\n",
" .with_entrypoint(\"human_input\")\n",
" .with_tracker(\n",
" \"local\", project=\"demo_getting_started\"\n",
" ).build()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "84bb56d5-9148-41f4-9b97-409f797e96ac",
"metadata": {},
"outputs": [],
"source": [
"for prompt in [\n",
" \"Who was Aaron Burr, sir?\",\n",
" \"Who was Aaron Burr, sir (unsafe)?\",\n",
" \"If you had ml/ai libraries called 'Hamilton' and 'Burr', what would they do?\",\n",
" \"Who was Aaron Burr, sir?\",\n",
" \"Who was Aaron Burr, sir (unsafe)?\",\n",
" \"If you had ml/ai libraries called 'Hamilton' and 'Burr', what would they do?\",\n",
"]:\n",
" action_we_ran, result, state = app_with_tracker.run(\n",
" halt_after=[\"ai_response\", \"unsafe_response\"], \n",
" inputs={\"prompt\": prompt}\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "54f1d1f9-9365-4a71-bf7a-01057c5a5cad",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"[Link to UI](http://localhost:7241/project/demo_getting_started/ed84cc8b-1f2f-46c0-aee4-c36c2a73040b)"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import Markdown\n",
"url = f\"[Link to UI](http://localhost:7241/project/demo_getting_started/{app_with_tracker.uid})\"\n",
"Markdown(url)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "57266663-f9e2-41a1-9a1c-c865d6b7b55d",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/casey/anaconda3/envs/burr/lib/python3.13/site-packages/IPython/core/display.py:475: UserWarning: Consider using IPython.display.IFrame instead\n",
" warnings.warn(\"Consider using IPython.display.IFrame instead\")\n"
]
},
{
"data": {
"text/html": [
"<iframe src=\"http://localhost:7241/project/demo_getting_started/ed84cc8b-1f2f-46c0-aee4-c36c2a73040b\" width=\"100%\" height=\"1000px\"></iframe>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import os\n",
"import time\n",
"from IPython.display import HTML\n",
"get_ipython().system = os.system\n",
"!burr --no-open > /dev/null 2>&1 &\n",
"time.sleep(3) # quick trick to wait for the server to start\n",
"url = f\"http://localhost:7241/project/demo_getting_started/{app_with_tracker.uid}\"\n",
"iframe = f'<iframe src=\"{url}\" width=\"100%\" height=\"1000px\"></iframe>'\n",
"display(HTML(iframe))"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "37e43430-1719-448d-8203-6696cebcf642",
"metadata": {},
"outputs": [],
"source": [
"app_id = f\"unique_app_id_{uuid.uuid4()}\" # unique app ID -- we create it here but this will be generated for you\n",
"partition_key = \"new_burr_user\" # this can be anything. In a chatbot it will "
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "6bb4a525-5fb5-462e-8026-ada055ad0c61",
"metadata": {},
"outputs": [],
"source": [
"# we're going to be creating this multiple times to demonstrate so let's stick it in a function\n",
"def create_persistable_app():\n",
" sqllite_persister = persistence.SQLLitePersister(db_path=\"./sqlite.db\", table_name=\"burr_state\")\n",
" sqllite_persister.initialize()\n",
" return (\n",
" ApplicationBuilder().with_actions(\n",
" human_input=human_input,\n",
" ai_response=ai_response,\n",
" safety_check=safety_check,\n",
" unsafe_response=unsafe_response\n",
" ).with_transitions(\n",
" (\"human_input\", \"safety_check\"),\n",
" (\"safety_check\", \"unsafe_response\", when(safe=False)),\n",
" (\"safety_check\", \"ai_response\", when(safe=True)),\n",
" ([\"unsafe_response\", \"ai_response\"], \"human_input\"),\n",
" ).initialize_from(\n",
" initializer=sqllite_persister,\n",
" resume_at_next_action=True,\n",
" default_state={\"chat_history\": []},\n",
" default_entrypoint=\"human_input\"\n",
" ).with_state_persister(sqllite_persister)\n",
" .with_identifiers(app_id=app_id, partition_key=partition_key)\n",
" .with_tracker(\n",
" \"local\", project=\"demo_getting_started\"\n",
" ).build()\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "7ef3c466-a79c-4144-9cc2-8f3ceeb44416",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"user:Who was Aaron Burr, sir?\n",
"\n",
"assistant:Aaron Burr was a prominent political figure in the early United States. Born on February 6, 1756, he served as an attorney and politician who became the third Vice President of the United States under President Thomas Jefferson from 1801 to 1self-imprisonment after his term ended due to accusations related to treason conspiracy.\n",
"\n",
"Burr was a member of one of America's early political dynasties, alongside his brothers James Burr and Philip Pierre. He started practicing law before becoming involved in politics during the American Revolutionary War as an officer for several Continental Army battalions against British occupation forces. After receiving commissions from General George Washington himself to help defend West Florida during a brief insurrection attempt there, he became known within New York society due largely to his military service and political ambition.\n",
"\n",
"After serving in the House of Representatives as an Anti-Federalist before joining the Democratic-Republican Party led by Thomas Jefferson, Burr sought election for governor but was unsuccessful multiple times against Philip Schuyler's sons DeWitt Tracy and Morgan Lewis. Despite this setback, he continued to gain national prominence as a politician through appointments made possible under the early U.S government structure that allowed such positions without having prior Senate experience or representation by constituents directly; Burr took roles including Attorney General for New York (1803-1806) and Senator from his home state of New York, with whom he was reelected twice before running unsuccessfully for vice president in the 1804 election against Jefferson.\n",
"\n",
"His defeat marked one part of a broader political tension between Aaron Burr's Democratic-Republican Party and Andrew Jacksons populist views (which were increasingly Republican leaning). As opposition grew stronger, President Thomas Jefferson considered replacing him with George Clinton but never did so. Instead when Alexander Hamilton became first Secretary of the Treasury in 1789 under Washington's administration he offered Burr an influential position as a clerk to his son John as part of their ongoing political feud - something which eventually led Aaron Pendleton, another significant associate and frequent target for slanderous attack stories during the time.\n",
"\n",
"Later that year (December 23), Hamilton met with Burr at Federal Hall in New York City where they had a lengthy conversation about politics notably one of three times throughout their lives when they discussed forming an alliance against Thomas Jefferson but both agreed only through political maneuverings rather than overt hostility. It may have been this cordial yet strained relationship between the two men that later contributed to Burr's infamous duel with Alexander Hamilton in 1804 just six months after he had lost his bid for vice president of the U.S.\n",
"\n",
"While serving as Vice President, Aaron Burr sought re-election multiple times but was repeatedly defeated by Thomas Jefferson and other prominent TJ/Jacksonian Democratic candidates along with growing animosity within both parties; particularly regarding political patronage involving John Marshall's appointments including Benjamin H. Wythe II who would become his future mentor as Professor of Law at the College Of New Jersey (present-day University of Virginia). In fact, according to most accounts Burr was a proponent for educational expansion with support from Congress which had led him back into public service and politics under President Jefferson's patronage. This involvement helped further cement his reputation as an opportunist whose political fortunes could benefit personally perhaps leading directly towards the treason accusations against us that ended short of trial conviction but resulted in a life-long scandal affecting Burrs legacy far beyond even death itself.\n",
"\n",
"His notorious feud with Hamilton continued to grow, particularly after Jefferson retired from office and Alexander moved on other political pursuits namely seeking reappointment as Secretary at War under John Adams' presidency which included a conflict of interest between the two politicians regarding land rights given Aaron Burr sought control over lands that he believed could help fulfill his ambitions in New Lands (modern-day West Virginia). In 1807, tension continued as they met several times at Hamilton's Albany home although initially friendly these meetings would turn into contentious discussions focused primarily on Aaron Burrs personal fortune which he believed might be threatened by the future expansion of governmental power following Napoleon Bonaparte's failed schemes in Europe.\n",
"\n",
"In 1806, an alliance was formed while many contemporary Americans were distracted from news concerning war and tension between France (and her European powers) involving England as President Adams attempted his own path towards reconciliation this effort included the establishment of a U.S consulate in Madrid amidst rumors that Burr himself led an ambitious expedition into Spanish territories using political means with assistance from sympathizer William Hull among notable others (which would soon become known as \"Burr's Conspiracy\"). This venture ended when Aaron Burrs supporters were largely discredited for spreading false accusations that aimed at slandering members of Spanish government in order to divert attention from the original allegation, all while other political figures became more hostile towards him as a personal competitor and perceived traitor leading ultimately without charges being formally filed.\n",
"\n",
"Burr faced trial twice for treason but was never convicted - primarily due lacking sufficient evidence beyond his name alone coupled with accusations regarding land speculation in Louisiana which had been made years before the alleged conspiracy itself; although Burr remained a respected legal advisor amongst some circles, he ultimately decided to resign from federal positions wherein Aaron Burr continued pursuing personal and business ventures at home including running for governor of New York twice more unsuccessful attempts. \n",
"\n",
"A final attempt would have him seek the presidency but instead focused his efforts in expanding westward territories under U.S jurisdiction with assistance from Louisiana Territory Governor George Izard, an effort which failed leading Burr to retreat back into private life only sporadically appearing within legal and political circles until passing away on September 14th 1836 after suffering a series of strokes while still relatively young for his age.\n",
"\n",
"Fabio Amelong\n",
"\n"
]
}
],
"source": [
"app_initial = create_persistable_app()\n",
"action, result, state = app_initial.run(\n",
" halt_after=[\"ai_response\", \"unsafe_response\"], \n",
" inputs={\"prompt\": \"Who was Aaron Burr, sir?\"}\n",
")\n",
"for item in state['chat_history']:\n",
" print(item['role'] + ':' + item['content'] + '\\n')"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "fca76e6c-c832-42b5-96ca-796df29ec84c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"user:Who was Aaron Burr, sir?\n",
"\n",
"assistant:Aaron Burr was a prominent political figure in the early United States. Born on February 6, 1756, he served as an attorney and politician who became the third Vice President of the United States under President Thomas Jefferson from 1801 to 1self-imprisonment after his term ended due to accusations related to treason conspiracy.\n",
"\n",
"Burr was a member of one of America's early political dynasties, alongside his brothers James Burr and Philip Pierre. He started practicing law before becoming involved in politics during the American Revolutionary War as an officer for several Continental Army battalions against British occupation forces. After receiving commissions from General George Washington himself to help defend West Florida during a brief insurrection attempt there, he became known within New York society due largely to his military service and political ambition.\n",
"\n",
"After serving in the House of Representatives as an Anti-Federalist before joining the Democratic-Republican Party led by Thomas Jefferson, Burr sought election for governor but was unsuccessful multiple times against Philip Schuyler's sons DeWitt Tracy and Morgan Lewis. Despite this setback, he continued to gain national prominence as a politician through appointments made possible under the early U.S government structure that allowed such positions without having prior Senate experience or representation by constituents directly; Burr took roles including Attorney General for New York (1803-1806) and Senator from his home state of New York, with whom he was reelected twice before running unsuccessfully for vice president in the 1804 election against Jefferson.\n",
"\n",
"His defeat marked one part of a broader political tension between Aaron Burr's Democratic-Republican Party and Andrew Jacksons populist views (which were increasingly Republican leaning). As opposition grew stronger, President Thomas Jefferson considered replacing him with George Clinton but never did so. Instead when Alexander Hamilton became first Secretary of the Treasury in 1789 under Washington's administration he offered Burr an influential position as a clerk to his son John as part of their ongoing political feud - something which eventually led Aaron Pendleton, another significant associate and frequent target for slanderous attack stories during the time.\n",
"\n",
"Later that year (December 23), Hamilton met with Burr at Federal Hall in New York City where they had a lengthy conversation about politics notably one of three times throughout their lives when they discussed forming an alliance against Thomas Jefferson but both agreed only through political maneuverings rather than overt hostility. It may have been this cordial yet strained relationship between the two men that later contributed to Burr's infamous duel with Alexander Hamilton in 1804 just six months after he had lost his bid for vice president of the U.S.\n",
"\n",
"While serving as Vice President, Aaron Burr sought re-election multiple times but was repeatedly defeated by Thomas Jefferson and other prominent TJ/Jacksonian Democratic candidates along with growing animosity within both parties; particularly regarding political patronage involving John Marshall's appointments including Benjamin H. Wythe II who would become his future mentor as Professor of Law at the College Of New Jersey (present-day University of Virginia). In fact, according to most accounts Burr was a proponent for educational expansion with support from Congress which had led him back into public service and politics under President Jefferson's patronage. This involvement helped further cement his reputation as an opportunist whose political fortunes could benefit personally perhaps leading directly towards the treason accusations against us that ended short of trial conviction but resulted in a life-long scandal affecting Burrs legacy far beyond even death itself.\n",
"\n",
"His notorious feud with Hamilton continued to grow, particularly after Jefferson retired from office and Alexander moved on other political pursuits namely seeking reappointment as Secretary at War under John Adams' presidency which included a conflict of interest between the two politicians regarding land rights given Aaron Burr sought control over lands that he believed could help fulfill his ambitions in New Lands (modern-day West Virginia). In 1807, tension continued as they met several times at Hamilton's Albany home although initially friendly these meetings would turn into contentious discussions focused primarily on Aaron Burrs personal fortune which he believed might be threatened by the future expansion of governmental power following Napoleon Bonaparte's failed schemes in Europe.\n",
"\n",
"In 1806, an alliance was formed while many contemporary Americans were distracted from news concerning war and tension between France (and her European powers) involving England as President Adams attempted his own path towards reconciliation this effort included the establishment of a U.S consulate in Madrid amidst rumors that Burr himself led an ambitious expedition into Spanish territories using political means with assistance from sympathizer William Hull among notable others (which would soon become known as \"Burr's Conspiracy\"). This venture ended when Aaron Burrs supporters were largely discredited for spreading false accusations that aimed at slandering members of Spanish government in order to divert attention from the original allegation, all while other political figures became more hostile towards him as a personal competitor and perceived traitor leading ultimately without charges being formally filed.\n",
"\n",
"Burr faced trial twice for treason but was never convicted - primarily due lacking sufficient evidence beyond his name alone coupled with accusations regarding land speculation in Louisiana which had been made years before the alleged conspiracy itself; although Burr remained a respected legal advisor amongst some circles, he ultimately decided to resign from federal positions wherein Aaron Burr continued pursuing personal and business ventures at home including running for governor of New York twice more unsuccessful attempts. \n",
"\n",
"A final attempt would have him seek the presidency but instead focused his efforts in expanding westward territories under U.S jurisdiction with assistance from Louisiana Territory Governor George Izard, an effort which failed leading Burr to retreat back into private life only sporadically appearing within legal and political circles until passing away on September 14th 1836 after suffering a series of strokes while still relatively young for his age.\n",
"\n",
"Fabio Amelong\n",
"\n",
"user:Who was Alexander Hamilton?\n",
"\n",
"assistant:Alexander Hamilton, born in the West Indies as one half of immigrant parents and apprenticed to New York City merchant firm established by Benjamin Weggess Wayles - father John's brother-in-law; a strong influence on his education came from having an Uncle James who held public offices under King George III during British rule. Hamilton attended Kings College (present day Columbia) and after studying law for several years first as apprentice in New York before moving into politics himself - serving brief terms to begin political careers of many early United States politicians thereafter, including U.S Representative from 1780-1794 where he developed important allies while establishing the nation's foundations during post-revolution and nascent national government structure under Article I legislation (with assistance by Thomas Jefferson himself).\n",
"\n",
"His initial contributions to public financial policy development included setting into motion National Bank through Congress - opposed vehemently due largely towards Hamiltons perceived as \"monopoly capitalism\" while creating first Secretary of Treasury in 1789, a role he filled for the remainder his political career. He would later establish United States Mint and promote creation fiscal credit system under assumption public debts equalizing interest rates between foreigners/governments rather than nationals themselves as well advocated strong federal power with increasing powers given directly to President (a contrast which opposed Thomas Jefferson's more limited centralist views).\n",
"\n",
"Aside direct service, Hamiltons personal feud especially towards Aaron Burr and his efforts throughout lifetime led them both becoming significant historical figures in American History notably because of 1804 duel an infamous affair that culminated after repeated attempts to reconcile following initial meeting years earlier at Federal Hall; though this attempt never overshadow entire influence Hamilton had upon nation's politics including formulation \"Report On Manufactures\" and supporting the War Of Independence against British Forces with financial/battalion backing. His impact remains so vast across American History era especially considering his death from wound suffered during same duel that caused him to flee back into Manhattan near Hudson River where he died shortly after on July 12th - August, 3084).\n",
"\n",
"Alexander Hamilton is known as nations founding father influential financial advocate and first Secretary Of Treasury with notable historical legacy largely tied within contextual U.S History era; however some negative aspects are often attributed to him given the controversies & personal feud between Aaron Burr especially leading up towards later years - nonetheless his work remains fundamental part foundational influences which greatly impacted early United States economics policy including Federalist Papers themselves along with numerous biographic accounts regarding life history overall- one being Hamilton by Ron Chernow.\n",
"\n",
"Elisabeth Mossell, Lady Elizabeth Burr Montagu Mary - daughter of the 3rd Earl Of Sandwich from England who wed her cousin Aaron Butler's son Richard Morris (and grandfathered own three children including Thomas Henry and Peter whose father William served throughout Napoleonic Wars along with becoming heir in English Nobility system itself)- known as Elizabeth Mossell-Montagu; was related but born British subject of Alexander Hamiltons personal life, who lived between 1768 - May , April (though some discrepancies occur regarding years). Born August 25th —November .3rd in Charing Cross Road New York City to Sandwich family during his own early marriage with Eliza but died tragically November4edmourning-sandsford.net after giving birth soon afterwards; her lineage led Lady Hamilton as direct part ancestor via second son Thomas wife Ann Reynolds - yet somehow became historically notable due partly towards inheritance issues (one being Elizabeth Mossell' mother Margaret Morris known herself for supporting founding father Benjamin Franklin when immigrating America from England). \n",
"\n",
"Penelope Jones, Lady Mary Anna Barbara Amelia; cousin on Aaron Burrs maternal side - sister to William Hamilton and Catherine Sophia “Sophie” Dalrymple who married Charles Henry Thomas (British subject with connection back into American politics although more known as wife/love interest during duel which he did pursue following death of his first & second spouse: Louisa Graeme). Lady Penelope was born February 25th,1749 - also named Anna Brownlow Hamiltons niece; daughter Elizabeth' s father James St Clair Burr from the British Raj in India who worked alongside Robert Walpole later married to become Baron Wenlock when he arrived back into England following marriage. Lady Mary was one of 5 siblings including Thomas Henry (Lady Hamilton, herself) whose life impacted greatly upon family history with Aarons mother Elizabeth Schuyler - also wife born Janis Smith from Connecticut; his father Philip Pierre Burr arriving NY City prior to her own arrival later on which created American branch within British Colonies themselves.\n",
"\n",
"Aside personal relations therewith, political/career influence remains somewhat questioned due historic conflicts surrounding foundations laid during lifetime including but not exclusively revolving around Alexander Hamiltons son-in-law William Duer - allegedly attempted Coup in 1797 although also notable as first President John Adams & James Madison' own spouse both closely associated with each other though later became embroiled themselves towards controversy while holding posts of Secretary Of State and Vice Presidency; but largely remained most renowned for role amongst founding fathers including Federalist Papers where he co-wrote alongside John Jay, James Madison & John Jay's son Tench Coxe - written under pseudonym “Publius” along with several more works advocating U.S Constitution itself towards 1787 Congress ratification for same in New York City including during time as Governor Of NY State- serving short term before losing subsequent election to succeeding James Duane (who was an unpopular political candidate leading party leader Alexander Hamilton himself supporting).\n",
"\n",
"His death aftermath led many biographies written about his life and times - most notably Ron Chernow's widely read “A Life & Legacy Hamiliton as a Public Serviceman” yet portions often criticize toward personal affairs such duel itself alongside also numerous other controversy towards various topics within early 19th Century American politics involving his own sons along with many political issues throughout time. His legacy however still remains essential historic influence upon United States history despite these aspects including role during creation of Federalist Papers among much more while continuing inspiring future generations overall).\n",
"\n",
"Alexander Hamilton has lasted into popular literature especially film/TV portrayals since 1982-Tony Randall's award & Burt Lancasters \"A Clear and Present Danger\" alongside also Michael Douglas took lead followed latterly Johnny Depp in recent historical fiction novel “Lincoln” (Fox, LLC Movie Release Year ) starring as Aaron. Lasting portrayals of life - though still contentious subject regarding personal conflict/history between political figures themselves; remains one such major controversy overall with most scholars believing his legacy largely positive yet also questionable within modern history era today).\n",
"\n"
]
}
],
"source": [
"del app_initial\n",
"app_reloaded = create_persistable_app()\n",
"\n",
"action, result, state = app_reloaded.run(\n",
" halt_after=[\"ai_response\", \"unsafe_response\"], \n",
" inputs={\"prompt\": \"Who was Alexander Hamilton?\"}\n",
")\n",
"for item in state['chat_history']:\n",
" print(item['role'] + ':' + item['content'] + '\\n')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ff6cca7-aab9-40cf-9852-94aa04ee9d92",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}