diff --git a/examples/Assistants_API_overview_python.ipynb b/examples/Assistants_API_overview_python.ipynb index 12d4f7c..2b9dd29 100644 --- a/examples/Assistants_API_overview_python.ipynb +++ b/examples/Assistants_API_overview_python.ipynb @@ -30,7 +30,7 @@ "### Python SDK \n", "\n", "> **Note**\n", - "> We've updated our [Python SDK](https://github.com/openai/openai-python) to add support for the Assistants API, so you'll need to update it to the latest version (`1.2.1` at time of writing).\n" + "> We've updated our [Python SDK](https://github.com/openai/openai-python) to add support for the Assistants API, so you'll need to update it to the latest version (`1.2.3` at time of writing).\n" ] }, { @@ -95,15 +95,14 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", - "# Just a helper for more readable output\n", "def show_json(obj):\n", - " display(json.loads(obj.model_dump_json()))\n" + " display(json.loads(obj.model_dump_json()))" ] }, { @@ -131,7 +130,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "\"Screenshot\n" + "\"Assistants\n" ] }, { @@ -145,7 +144,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "\"Screenshot\n" + "\"Creating\n" ] }, { @@ -159,7 +158,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "\"Screenshot\n" + "\"Assistants\n" ] }, { @@ -171,14 +170,14 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'asst_7t98qt8iVDP7xfJnRJpQ2zYe',\n", - " 'created_at': 1699648364,\n", + "{'id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'created_at': 1699650767,\n", " 'description': None,\n", " 'file_ids': [],\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", @@ -241,22 +240,14 @@ "outputs": [ { "data": { - "application/json": { - "created_at": 1699647704, - "id": "thread_vtbuepG0aXU9xr82wJbi7fRH", - "metadata": {}, - "object": "thread" - }, "text/plain": [ - "" + "{'id': 'thread_NSX4eG6UvkdgcmlPc5oz4GOl',\n", + " 'created_at': 1699650767,\n", + " 'metadata': {},\n", + " 'object': 'thread'}" ] }, - "metadata": { - "application/json": { - "expanded": false, - "root": "root" - } - }, + "metadata": {}, "output_type": "display_data" } ], @@ -279,36 +270,22 @@ "outputs": [ { "data": { - "application/json": { - "assistant_id": null, - "content": [ - { - "text": { - "annotations": [], - "value": "I need to solve the equation `3x + 11 = 14`. Can you help me?" - }, - "type": "text" - } - ], - "created_at": 1699647704, - "file_ids": [], - "id": "msg_0xvY310ibhmno6VOiDGFgKjF", - "metadata": {}, - "object": "thread.message", - "role": "user", - "run_id": null, - "thread_id": "thread_vtbuepG0aXU9xr82wJbi7fRH" - }, "text/plain": [ - "" + "{'id': 'msg_DBOLoyk6KZ1Vh8OnZQj0CfTC',\n", + " 'assistant_id': None,\n", + " 'content': [{'text': {'annotations': [],\n", + " 'value': 'I need to solve the equation `3x + 11 = 14`. Can you help me?'},\n", + " 'type': 'text'}],\n", + " 'created_at': 1699650767,\n", + " 'file_ids': [],\n", + " 'metadata': {},\n", + " 'object': 'thread.message',\n", + " 'role': 'user',\n", + " 'run_id': None,\n", + " 'thread_id': 'thread_NSX4eG6UvkdgcmlPc5oz4GOl'}" ] }, - "metadata": { - "application/json": { - "expanded": false, - "root": "root" - } - }, + "metadata": {}, "output_type": "display_data" } ], @@ -347,9 +324,36 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'run_Nusuu4zsEsvCBsftmechVVKa',\n", + " 'assistant_id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'cancelled_at': None,\n", + " 'completed_at': None,\n", + " 'created_at': 1699650768,\n", + " 'expires_at': 1699651368,\n", + " 'failed_at': None,\n", + " 'file_ids': [],\n", + " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", + " 'last_error': None,\n", + " 'metadata': {},\n", + " 'model': 'gpt-4-1106-preview',\n", + " 'object': 'thread.run',\n", + " 'required_action': None,\n", + " 'started_at': None,\n", + " 'status': 'queued',\n", + " 'thread_id': 'thread_NSX4eG6UvkdgcmlPc5oz4GOl',\n", + " 'tools': []}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "run = client.beta.threads.runs.create(\n", " thread_id=thread.id,\n", @@ -369,7 +373,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -387,20 +391,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:param.JSON00142: Displaying Panel objects in the notebook requires the panel extension to be loaded. Ensure you run pn.extension() before displaying objects in the notebook.\n" - ] - }, { "data": { "text/plain": [ - "JSON(str)" + "{'id': 'run_Nusuu4zsEsvCBsftmechVVKa',\n", + " 'assistant_id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'cancelled_at': None,\n", + " 'completed_at': 1699650779,\n", + " 'created_at': 1699650768,\n", + " 'expires_at': None,\n", + " 'failed_at': None,\n", + " 'file_ids': [],\n", + " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", + " 'last_error': None,\n", + " 'metadata': {},\n", + " 'model': 'gpt-4-1106-preview',\n", + " 'object': 'thread.run',\n", + " 'required_action': None,\n", + " 'started_at': 1699650768,\n", + " 'status': 'completed',\n", + " 'thread_id': 'thread_NSX4eG6UvkdgcmlPc5oz4GOl',\n", + " 'tools': []}" ] }, "metadata": {}, @@ -428,20 +442,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:param.JSON00148: Displaying Panel objects in the notebook requires the panel extension to be loaded. Ensure you run pn.extension() before displaying objects in the notebook.\n" - ] - }, { "data": { "text/plain": [ - "JSON(str)" + "{'data': [{'id': 'msg_6mVnuj4jDruX1cUaB7ZKd0Ae',\n", + " 'assistant_id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'content': [{'text': {'annotations': [],\n", + " 'value': 'Sure, subtract 11 from both sides to get 3x = 3, then divide by 3 to find x = 1.'},\n", + " 'type': 'text'}],\n", + " 'created_at': 1699650778,\n", + " 'file_ids': [],\n", + " 'metadata': {},\n", + " 'object': 'thread.message',\n", + " 'role': 'assistant',\n", + " 'run_id': 'run_Nusuu4zsEsvCBsftmechVVKa',\n", + " 'thread_id': 'thread_NSX4eG6UvkdgcmlPc5oz4GOl'},\n", + " {'id': 'msg_DBOLoyk6KZ1Vh8OnZQj0CfTC',\n", + " 'assistant_id': None,\n", + " 'content': [{'text': {'annotations': [],\n", + " 'value': 'I need to solve the equation `3x + 11 = 14`. Can you help me?'},\n", + " 'type': 'text'}],\n", + " 'created_at': 1699650767,\n", + " 'file_ids': [],\n", + " 'metadata': {},\n", + " 'object': 'thread.message',\n", + " 'role': 'user',\n", + " 'run_id': None,\n", + " 'thread_id': 'thread_NSX4eG6UvkdgcmlPc5oz4GOl'}],\n", + " 'object': 'list',\n", + " 'first_id': 'msg_6mVnuj4jDruX1cUaB7ZKd0Ae',\n", + " 'last_id': 'msg_DBOLoyk6KZ1Vh8OnZQj0CfTC',\n", + " 'has_more': False}" ] }, "metadata": {}, @@ -469,20 +503,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:param.JSON00154: Displaying Panel objects in the notebook requires the panel extension to be loaded. Ensure you run pn.extension() before displaying objects in the notebook.\n" - ] - }, { "data": { "text/plain": [ - "JSON(str)" + "{'data': [{'id': 'msg_BvPtOMdPjo5WOnKS3pz62oRH',\n", + " 'assistant_id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'content': [{'text': {'annotations': [],\n", + " 'value': 'To solve `3x + 11 = 14`, you want to isolate x. First, subtract 11 from both sides to remove the constant term on the left, leaving you with `3x = 3`. Then divide both sides by 3, the coefficient of x, to get `x = 1`, which is your solution.'},\n", + " 'type': 'text'}],\n", + " 'created_at': 1699650781,\n", + " 'file_ids': [],\n", + " 'metadata': {},\n", + " 'object': 'thread.message',\n", + " 'role': 'assistant',\n", + " 'run_id': 'run_2wptlex34YZfsQE5dYNVNln1',\n", + " 'thread_id': 'thread_NSX4eG6UvkdgcmlPc5oz4GOl'}],\n", + " 'object': 'list',\n", + " 'first_id': 'msg_BvPtOMdPjo5WOnKS3pz62oRH',\n", + " 'last_id': 'msg_BvPtOMdPjo5WOnKS3pz62oRH',\n", + " 'has_more': False}" ] }, "metadata": {}, @@ -539,7 +581,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -575,7 +617,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -602,7 +644,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -611,21 +653,21 @@ "text": [ "# Messages\n", "user: I need to solve the equation `3x + 11 = 14`. Can you help me?\n", - "assistant: Yes, subtract 11 from both sides to get `3x = 3`, then divide by 3 to find `x = 1`.\n", + "assistant: Sure, subtract 11 from both sides to get `3x = 3`, then divide both sides by 3 to find `x = 1`.\n", "\n", "# Messages\n", "user: Could you explain linear algebra to me?\n", - "assistant: Linear algebra is a branch of mathematics focused on vector spaces and linear mappings between these spaces, which includes the study of vectors, matrices, determinants, eigenvalues, eigenvectors, and systems of linear equations.\n", + "assistant: Linear algebra is the branch of mathematics concerning vector spaces and linear mappings between such spaces, which includes the study of lines, planes, and subspaces, as well as concepts like vectors, matrices, determinants, eigenvalues, and eigenvectors.\n", "\n", "# Messages\n", "user: I don't like math. What can I do?\n", - "assistant: Try relating math topics to your interests, practice regularly to build confidence, or work with a tutor to help make the subject more approachable and enjoyable.\n", + "assistant: Try to find real-life applications of math that interest you, work with a tutor or friend who can make the learning process more enjoyable, or set small, achievable goals to build your confidence and appreciation for the subject over time.\n", "\n", "# Messages\n", "user: I don't like math. What can I do?\n", - "assistant: Try relating math topics to your interests, practice regularly to build confidence, or work with a tutor to help make the subject more approachable and enjoyable.\n", + "assistant: Try to find real-life applications of math that interest you, work with a tutor or friend who can make the learning process more enjoyable, or set small, achievable goals to build your confidence and appreciation for the subject over time.\n", "user: Thank you!\n", - "assistant: You're welcome! If you have any more questions, feel free to ask.\n", + "assistant: You're welcome! If you have any more questions or need help, feel free to ask. Good luck!\n", "\n" ] } @@ -697,7 +739,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "\"Screenshot\n" + "\"Enabling\n" ] }, { @@ -709,9 +751,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'created_at': 1699650767,\n", + " 'description': None,\n", + " 'file_ids': [],\n", + " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", + " 'metadata': {},\n", + " 'model': 'gpt-4-1106-preview',\n", + " 'name': 'Math Tutor',\n", + " 'object': 'assistant',\n", + " 'tools': [{'type': 'code_interpreter'}]}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "assistant = client.beta.assistants.update(\n", " MATH_ASSISTANT_ID,\n", @@ -729,7 +790,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -738,8 +799,7 @@ "text": [ "# Messages\n", "user: Generate the first 20 fibbonaci numbers with code.\n", - "assistant: The first 20 Fibonacci numbers are:\n", - "0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181.\n", + "assistant: The first 20 Fibonacci numbers are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181.\n", "\n" ] } @@ -772,7 +832,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -790,14 +850,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [ + { + "data": { + "text/plain": [ + "{'tool_calls': [{'id': 'call_3wkAlWG2fzNT5UrQufSCicTy',\n", + " 'code_interpreter': {'input': 'def fibonacci(n):\\n fib_sequence = [0, 1]\\n while len(fib_sequence) < n:\\n fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])\\n return fib_sequence\\n\\nfirst_20_fibonacci = fibonacci(20)\\nfirst_20_fibonacci',\n", + " 'outputs': [{'logs': '[0,\\n 1,\\n 1,\\n 2,\\n 3,\\n 5,\\n 8,\\n 13,\\n 21,\\n 34,\\n 55,\\n 89,\\n 144,\\n 233,\\n 377,\\n 610,\\n 987,\\n 1597,\\n 2584,\\n 4181]',\n", + " 'type': 'logs'}]},\n", + " 'type': 'code_interpreter'}],\n", + " 'type': 'tool_calls'}" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "null\n" + ] + }, + { + "data": { + "text/plain": [ + "{'message_creation': {'message_id': 'msg_pbZ6kCzRyrgXENzOEDq58k1B'},\n", + " 'type': 'message_creation'}" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdout", "output_type": "stream", "text": [ - "null\n", "null\n" ] } @@ -838,14 +928,33 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "\"Screenshot\n" + "\"Enabling\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'created_at': 1699650767,\n", + " 'description': None,\n", + " 'file_ids': ['file-bfXOZPBktVHlmm8rDDcCDTzD'],\n", + " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", + " 'metadata': {},\n", + " 'model': 'gpt-4-1106-preview',\n", + " 'name': 'Math Tutor',\n", + " 'object': 'assistant',\n", + " 'tools': [{'type': 'code_interpreter'}, {'type': 'retrieval'}]}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "# Upload the file\n", "file = client.files.create(\n", @@ -866,9 +975,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "# Messages\n", + "user: What are some cool math concepts behind this ML paper pdf? Explain in two sentences.\n", + "assistant: The document does not contain explicit sections with the phrases \"math concepts\", \"mathematical\", or \"algorithm\". Without visible content or a text-based search that yields results, I am unable to identify the mathematical concepts in the paper.\n", + "\n", + "I would recommend uploading the PDF again, ensuring that it can be accessed with the tools provided, so that I can assist you properly.\n", + "\n" + ] + } + ], "source": [ "thread, run = create_thread_and_run(\n", " \"What are some cool math concepts behind this ML paper pdf? Explain in two sentences.\"\n", @@ -908,7 +1030,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -954,7 +1076,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -999,7 +1121,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -1043,7 +1165,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "\"Screenshot\n" + "\"Enabling\n" ] }, { @@ -1056,151 +1178,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [ { "data": { - "text/html": [ - "
{\n",
-       "  \"id\": \"asst_oWtP199nJHb6uR48GseDKtvv\",\n",
-       "  \"created_at\": 1699647366,\n",
-       "  \"description\": null,\n",
-       "  \"file_ids\": [\n",
-       "    \"file-BXMBZx4F9yCVwW27doS6uRiJ\"\n",
-       "  ],\n",
-       "  \"instructions\": \"You are a personal math tutor. Answer questions briefly, in a sentence or less.\",\n",
-       "  \"metadata\": {},\n",
-       "  \"model\": \"gpt-4-1106-preview\",\n",
-       "  \"name\": \"Math Tutor\",\n",
-       "  \"object\": \"assistant\",\n",
-       "  \"tools\": [\n",
-       "    {\n",
-       "      \"type\": \"code_interpreter\"\n",
-       "    },\n",
-       "    {\n",
-       "      \"type\": \"retrieval\"\n",
-       "    },\n",
-       "    {\n",
-       "      \"function\": {\n",
-       "        \"name\": \"display_quiz\",\n",
-       "        \"parameters\": {\n",
-       "          \"type\": \"object\",\n",
-       "          \"properties\": {\n",
-       "            \"title\": {\n",
-       "              \"type\": \"string\"\n",
-       "            },\n",
-       "            \"questions\": {\n",
-       "              \"type\": \"array\",\n",
-       "              \"description\": \"An array of questions, each with a title and potentially options (if multiple choice).\",\n",
-       "              \"items\": {\n",
-       "                \"type\": \"object\",\n",
-       "                \"properties\": {\n",
-       "                  \"question_text\": {\n",
-       "                    \"type\": \"string\"\n",
-       "                  },\n",
-       "                  \"question_type\": {\n",
-       "                    \"type\": \"string\",\n",
-       "                    \"enum\": [\n",
-       "                      \"MULTIPLE_CHOICE\",\n",
-       "                      \"FREE_RESPONSE\"\n",
-       "                    ]\n",
-       "                  },\n",
-       "                  \"choices\": {\n",
-       "                    \"type\": \"array\",\n",
-       "                    \"items\": {\n",
-       "                      \"type\": \"string\"\n",
-       "                    }\n",
-       "                  }\n",
-       "                },\n",
-       "                \"required\": [\n",
-       "                  \"question_text\"\n",
-       "                ]\n",
-       "              }\n",
-       "            }\n",
-       "          },\n",
-       "          \"required\": [\n",
-       "            \"title\",\n",
-       "            \"questions\"\n",
-       "          ]\n",
-       "        },\n",
-       "        \"description\": \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"\n",
-       "      },\n",
-       "      \"type\": \"function\"\n",
-       "    }\n",
-       "  ]\n",
-       "}\n",
-       "
\n" - ], "text/plain": [ - "\u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"id\"\u001b[0m: \u001b[32m\"asst_oWtP199nJHb6uR48GseDKtvv\"\u001b[0m,\n", - " \u001b[1;34m\"created_at\"\u001b[0m: \u001b[1;36m1699647366\u001b[0m,\n", - " \u001b[1;34m\"description\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"file_ids\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"file-BXMBZx4F9yCVwW27doS6uRiJ\"\u001b[0m\n", - " \u001b[1m]\u001b[0m,\n", - " \u001b[1;34m\"instructions\"\u001b[0m: \u001b[32m\"You are a personal math tutor. Answer questions briefly, in a sentence or less.\"\u001b[0m,\n", - " \u001b[1;34m\"metadata\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"model\"\u001b[0m: \u001b[32m\"gpt-4-1106-preview\"\u001b[0m,\n", - " \u001b[1;34m\"name\"\u001b[0m: \u001b[32m\"Math Tutor\"\u001b[0m,\n", - " \u001b[1;34m\"object\"\u001b[0m: \u001b[32m\"assistant\"\u001b[0m,\n", - " \u001b[1;34m\"tools\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"code_interpreter\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"retrieval\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"function\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"name\"\u001b[0m: \u001b[32m\"display_quiz\"\u001b[0m,\n", - " \u001b[1;34m\"parameters\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"object\"\u001b[0m,\n", - " \u001b[1;34m\"properties\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"title\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"questions\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"array\"\u001b[0m,\n", - " \u001b[1;34m\"description\"\u001b[0m: \u001b[32m\"An array of questions, each with a title and potentially options (if multiple choice).\"\u001b[0m,\n", - " \u001b[1;34m\"items\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"object\"\u001b[0m,\n", - " \u001b[1;34m\"properties\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"question_text\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"question_type\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m,\n", - " \u001b[1;34m\"enum\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"MULTIPLE_CHOICE\"\u001b[0m,\n", - " \u001b[32m\"FREE_RESPONSE\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"choices\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"array\"\u001b[0m,\n", - " \u001b[1;34m\"items\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"required\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"question_text\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"required\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"title\"\u001b[0m,\n", - " \u001b[32m\"questions\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"description\"\u001b[0m: \u001b[32m\"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"function\"\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - "\u001b[1m}\u001b[0m\n" + "{'id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'created_at': 1699650767,\n", + " 'description': None,\n", + " 'file_ids': ['file-bfXOZPBktVHlmm8rDDcCDTzD'],\n", + " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", + " 'metadata': {},\n", + " 'model': 'gpt-4-1106-preview',\n", + " 'name': 'Math Tutor',\n", + " 'object': 'assistant',\n", + " 'tools': [{'type': 'code_interpreter'},\n", + " {'type': 'retrieval'},\n", + " {'function': {'name': 'display_quiz',\n", + " 'parameters': {'type': 'object',\n", + " 'properties': {'title': {'type': 'string'},\n", + " 'questions': {'type': 'array',\n", + " 'description': 'An array of questions, each with a title and potentially options (if multiple choice).',\n", + " 'items': {'type': 'object',\n", + " 'properties': {'question_text': {'type': 'string'},\n", + " 'question_type': {'type': 'string',\n", + " 'enum': ['MULTIPLE_CHOICE', 'FREE_RESPONSE']},\n", + " 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n", + " 'required': ['question_text']}}},\n", + " 'required': ['title', 'questions']},\n", + " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"},\n", + " 'type': 'function'}]}" ] }, "metadata": {}, @@ -1228,26 +1236,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, "outputs": [ - { - "data": { - "text/html": [ - "
\n"
-      ],
-      "text/plain": []
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    },
     {
      "data": {
       "text/plain": [
-       "\u001b[32m'requires_action'\u001b[0m"
+       "'requires_action'"
       ]
      },
-     "execution_count": 26,
+     "execution_count": 25,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -1269,195 +1267,49 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 26,
    "metadata": {},
    "outputs": [
     {
      "data": {
-      "text/html": [
-       "
{\n",
-       "  \"id\": \"run_cTgSKShYNiCfW5XXuU01tAtP\",\n",
-       "  \"assistant_id\": \"asst_oWtP199nJHb6uR48GseDKtvv\",\n",
-       "  \"cancelled_at\": null,\n",
-       "  \"completed_at\": null,\n",
-       "  \"created_at\": 1699647410,\n",
-       "  \"expires_at\": 1699648010,\n",
-       "  \"failed_at\": null,\n",
-       "  \"file_ids\": [\n",
-       "    \"file-BXMBZx4F9yCVwW27doS6uRiJ\"\n",
-       "  ],\n",
-       "  \"instructions\": \"You are a personal math tutor. Answer questions briefly, in a sentence or less.\",\n",
-       "  \"last_error\": null,\n",
-       "  \"metadata\": {},\n",
-       "  \"model\": \"gpt-4-1106-preview\",\n",
-       "  \"object\": \"thread.run\",\n",
-       "  \"required_action\": {\n",
-       "    \"submit_tool_outputs\": {\n",
-       "      \"tool_calls\": [\n",
-       "        {\n",
-       "          \"id\": \"call_MtNGP8QtyF8raQgCe1iLteto\",\n",
-       "          \"function\": {\n",
-       "            \"arguments\": \"{\\n  \\\"title\\\": \\\"Math Quiz\\\",\\n  \\\"questions\\\": [\\n    {\\n      \\\"question_text\\\": \\\"Calculate the derivative of the function f(x) = 3x^3 - 5x^2 + 6.\\\",\\n      \\\"question_type\\\": \\\"FREE_RESPONSE\\\"\\n    },\\n    {\\n      \\\"question_text\\\": \\\"The graph of a quadratic function ax^2 + bx + c opens downward when:\\\",\\n      \\\"question_type\\\": \\\"MULTIPLE_CHOICE\\\",\\n      \\\"choices\\\": [\\\"a > 0\\\", \\\"a < 0\\\", \\\"b > 0\\\", \\\"c > 0\\\"]\\n    }\\n  ]\\n}\",\n",
-       "            \"name\": \"display_quiz\"\n",
-       "          },\n",
-       "          \"type\": \"function\"\n",
-       "        }\n",
-       "      ]\n",
-       "    },\n",
-       "    \"type\": \"submit_tool_outputs\"\n",
-       "  },\n",
-       "  \"started_at\": 1699647410,\n",
-       "  \"status\": \"requires_action\",\n",
-       "  \"thread_id\": \"thread_sVjQ15Tk8JAHwfwIKy190fMX\",\n",
-       "  \"tools\": [\n",
-       "    {\n",
-       "      \"type\": \"code_interpreter\"\n",
-       "    },\n",
-       "    {\n",
-       "      \"type\": \"retrieval\"\n",
-       "    },\n",
-       "    {\n",
-       "      \"function\": {\n",
-       "        \"name\": \"display_quiz\",\n",
-       "        \"parameters\": {\n",
-       "          \"type\": \"object\",\n",
-       "          \"properties\": {\n",
-       "            \"title\": {\n",
-       "              \"type\": \"string\"\n",
-       "            },\n",
-       "            \"questions\": {\n",
-       "              \"type\": \"array\",\n",
-       "              \"description\": \"An array of questions, each with a title and potentially options (if multiple choice).\",\n",
-       "              \"items\": {\n",
-       "                \"type\": \"object\",\n",
-       "                \"properties\": {\n",
-       "                  \"question_text\": {\n",
-       "                    \"type\": \"string\"\n",
-       "                  },\n",
-       "                  \"question_type\": {\n",
-       "                    \"type\": \"string\",\n",
-       "                    \"enum\": [\n",
-       "                      \"MULTIPLE_CHOICE\",\n",
-       "                      \"FREE_RESPONSE\"\n",
-       "                    ]\n",
-       "                  },\n",
-       "                  \"choices\": {\n",
-       "                    \"type\": \"array\",\n",
-       "                    \"items\": {\n",
-       "                      \"type\": \"string\"\n",
-       "                    }\n",
-       "                  }\n",
-       "                },\n",
-       "                \"required\": [\n",
-       "                  \"question_text\"\n",
-       "                ]\n",
-       "              }\n",
-       "            }\n",
-       "          },\n",
-       "          \"required\": [\n",
-       "            \"title\",\n",
-       "            \"questions\"\n",
-       "          ]\n",
-       "        },\n",
-       "        \"description\": \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"\n",
-       "      },\n",
-       "      \"type\": \"function\"\n",
-       "    }\n",
-       "  ]\n",
-       "}\n",
-       "
\n" - ], "text/plain": [ - "\u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"id\"\u001b[0m: \u001b[32m\"run_cTgSKShYNiCfW5XXuU01tAtP\"\u001b[0m,\n", - " \u001b[1;34m\"assistant_id\"\u001b[0m: \u001b[32m\"asst_oWtP199nJHb6uR48GseDKtvv\"\u001b[0m,\n", - " \u001b[1;34m\"cancelled_at\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"completed_at\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"created_at\"\u001b[0m: \u001b[1;36m1699647410\u001b[0m,\n", - " \u001b[1;34m\"expires_at\"\u001b[0m: \u001b[1;36m1699648010\u001b[0m,\n", - " \u001b[1;34m\"failed_at\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"file_ids\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"file-BXMBZx4F9yCVwW27doS6uRiJ\"\u001b[0m\n", - " \u001b[1m]\u001b[0m,\n", - " \u001b[1;34m\"instructions\"\u001b[0m: \u001b[32m\"You are a personal math tutor. Answer questions briefly, in a sentence or less.\"\u001b[0m,\n", - " \u001b[1;34m\"last_error\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"metadata\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"model\"\u001b[0m: \u001b[32m\"gpt-4-1106-preview\"\u001b[0m,\n", - " \u001b[1;34m\"object\"\u001b[0m: \u001b[32m\"thread.run\"\u001b[0m,\n", - " \u001b[1;34m\"required_action\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"submit_tool_outputs\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"tool_calls\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"id\"\u001b[0m: \u001b[32m\"call_MtNGP8QtyF8raQgCe1iLteto\"\u001b[0m,\n", - " \u001b[1;34m\"function\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"arguments\"\u001b[0m: \u001b[32m\"{\\n \\\"title\\\": \\\"Math Quiz\\\",\\n \\\"questions\\\": [\\n {\\n \\\"question_text\\\": \\\"Calculate the derivative of the function f(x) = 3x^3 - 5x^2 + 6.\\\",\\n \\\"question_type\\\": \\\"FREE_RESPONSE\\\"\\n },\\n {\\n \\\"question_text\\\": \\\"The graph of a quadratic function ax^2 + bx + c opens downward when:\\\",\\n \\\"question_type\\\": \\\"MULTIPLE_CHOICE\\\",\\n \\\"choices\\\": [\\\"a > 0\\\", \\\"a < 0\\\", \\\"b > 0\\\", \\\"c > 0\\\"]\\n }\\n ]\\n}\"\u001b[0m,\n", - " \u001b[1;34m\"name\"\u001b[0m: \u001b[32m\"display_quiz\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"function\"\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"submit_tool_outputs\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"started_at\"\u001b[0m: \u001b[1;36m1699647410\u001b[0m,\n", - " \u001b[1;34m\"status\"\u001b[0m: \u001b[32m\"requires_action\"\u001b[0m,\n", - " \u001b[1;34m\"thread_id\"\u001b[0m: \u001b[32m\"thread_sVjQ15Tk8JAHwfwIKy190fMX\"\u001b[0m,\n", - " \u001b[1;34m\"tools\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"code_interpreter\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"retrieval\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"function\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"name\"\u001b[0m: \u001b[32m\"display_quiz\"\u001b[0m,\n", - " \u001b[1;34m\"parameters\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"object\"\u001b[0m,\n", - " \u001b[1;34m\"properties\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"title\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"questions\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"array\"\u001b[0m,\n", - " \u001b[1;34m\"description\"\u001b[0m: \u001b[32m\"An array of questions, each with a title and potentially options (if multiple choice).\"\u001b[0m,\n", - " \u001b[1;34m\"items\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"object\"\u001b[0m,\n", - " \u001b[1;34m\"properties\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"question_text\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"question_type\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m,\n", - " \u001b[1;34m\"enum\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"MULTIPLE_CHOICE\"\u001b[0m,\n", - " \u001b[32m\"FREE_RESPONSE\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"choices\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"array\"\u001b[0m,\n", - " \u001b[1;34m\"items\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"required\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"question_text\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"required\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"title\"\u001b[0m,\n", - " \u001b[32m\"questions\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"description\"\u001b[0m: \u001b[32m\"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"function\"\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - "\u001b[1m}\u001b[0m\n" + "{'id': 'run_6P1wtBLDSnlgTaaHRRJh7GeT',\n", + " 'assistant_id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'cancelled_at': None,\n", + " 'completed_at': None,\n", + " 'created_at': 1699650818,\n", + " 'expires_at': 1699651418,\n", + " 'failed_at': None,\n", + " 'file_ids': ['file-bfXOZPBktVHlmm8rDDcCDTzD'],\n", + " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", + " 'last_error': None,\n", + " 'metadata': {},\n", + " 'model': 'gpt-4-1106-preview',\n", + " 'object': 'thread.run',\n", + " 'required_action': {'submit_tool_outputs': {'tool_calls': [{'id': 'call_x3X31AVz7CzFR95M4oBmB5j3',\n", + " 'function': {'arguments': '{\\n \"title\": \"Math Concepts Quiz\",\\n \"questions\": [\\n {\\n \"question_text\": \"Explain why the Pythagorean theorem only applies to right-angled triangles.\",\\n \"question_type\": \"FREE_RESPONSE\"\\n },\\n {\\n \"question_text\": \"What is the derivative of the function f(x) = 3x^2 + 2x + 1?\",\\n \"question_type\": \"MULTIPLE_CHOICE\",\\n \"choices\": [\\n \"f\\'(x) = 6x + 2\",\\n \"f\\'(x) = 6x^2 + 2\",\\n \"f\\'(x) = 3x^2 + 2\",\\n \"f\\'(x) = 9x + 2\"\\n ]\\n }\\n ]\\n}',\n", + " 'name': 'display_quiz'},\n", + " 'type': 'function'}]},\n", + " 'type': 'submit_tool_outputs'},\n", + " 'started_at': 1699650818,\n", + " 'status': 'requires_action',\n", + " 'thread_id': 'thread_afPuFpKVuFCENZYey3LyDGfM',\n", + " 'tools': [{'type': 'code_interpreter'},\n", + " {'type': 'retrieval'},\n", + " {'function': {'name': 'display_quiz',\n", + " 'parameters': {'type': 'object',\n", + " 'properties': {'title': {'type': 'string'},\n", + " 'questions': {'type': 'array',\n", + " 'description': 'An array of questions, each with a title and potentially options (if multiple choice).',\n", + " 'items': {'type': 'object',\n", + " 'properties': {'question_text': {'type': 'string'},\n", + " 'question_type': {'type': 'string',\n", + " 'enum': ['MULTIPLE_CHOICE', 'FREE_RESPONSE']},\n", + " 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n", + " 'required': ['question_text']}}},\n", + " 'required': ['title', 'questions']},\n", + " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"},\n", + " 'type': 'function'}]}" ] }, "metadata": {}, @@ -1480,7 +1332,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -1491,37 +1343,21 @@ "Function Arguments:\n" ] }, - { - "data": { - "text/html": [ - "
\n"
-      ],
-      "text/plain": []
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    },
     {
      "data": {
       "text/plain": [
-       "\n",
-       "\u001b[1m{\u001b[0m\n",
-       "    \u001b[32m'title'\u001b[0m: \u001b[32m'Math Quiz'\u001b[0m,\n",
-       "    \u001b[32m'questions'\u001b[0m: \u001b[1m[\u001b[0m\n",
-       "        \u001b[1m{\u001b[0m\n",
-       "            \u001b[32m'question_text'\u001b[0m: \u001b[32m'Calculate the derivative of the function f\u001b[0m\u001b[32m(\u001b[0m\u001b[32mx\u001b[0m\u001b[32m)\u001b[0m\u001b[32m = 3x^3 - 5x^2 + 6.'\u001b[0m,\n",
-       "            \u001b[32m'question_type'\u001b[0m: \u001b[32m'FREE_RESPONSE'\u001b[0m\n",
-       "        \u001b[1m}\u001b[0m,\n",
-       "        \u001b[1m{\u001b[0m\n",
-       "            \u001b[32m'question_text'\u001b[0m: \u001b[32m'The graph of a quadratic function ax^2 + bx + c opens downward when:'\u001b[0m,\n",
-       "            \u001b[32m'question_type'\u001b[0m: \u001b[32m'MULTIPLE_CHOICE'\u001b[0m,\n",
-       "            \u001b[32m'choices'\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m'a > 0'\u001b[0m, \u001b[32m'a \u001b[0m\u001b[32m<\u001b[0m\u001b[32m 0'\u001b[0m\u001b[39m, \u001b[0m\u001b[32m'b > 0'\u001b[0m\u001b[39m, \u001b[0m\u001b[32m'c \u001b[0m\u001b[32m>\u001b[0m\u001b[32m 0'\u001b[0m\u001b[1m]\u001b[0m\n",
-       "        \u001b[1m}\u001b[0m\n",
-       "    \u001b[1m]\u001b[0m\n",
-       "\u001b[1m}\u001b[0m"
+       "{'title': 'Math Concepts Quiz',\n",
+       " 'questions': [{'question_text': 'Explain why the Pythagorean theorem only applies to right-angled triangles.',\n",
+       "   'question_type': 'FREE_RESPONSE'},\n",
+       "  {'question_text': 'What is the derivative of the function f(x) = 3x^2 + 2x + 1?',\n",
+       "   'question_type': 'MULTIPLE_CHOICE',\n",
+       "   'choices': [\"f'(x) = 6x + 2\",\n",
+       "    \"f'(x) = 6x^2 + 2\",\n",
+       "    \"f'(x) = 3x^2 + 2\",\n",
+       "    \"f'(x) = 9x + 2\"]}]}"
       ]
      },
-     "execution_count": 28,
+     "execution_count": 27,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -1546,22 +1382,22 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 28,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Quiz: Math Quiz\n",
+      "Quiz: Math Concepts Quiz\n",
       "\n",
-      "Calculate the derivative of the function f(x) = 3x^3 - 5x^2 + 6.\n",
+      "Explain why the Pythagorean theorem only applies to right-angled triangles.\n",
       "\n",
-      "The graph of a quadratic function ax^2 + bx + c opens downward when:\n",
-      "0. a > 0\n",
-      "1. a < 0\n",
-      "2. b > 0\n",
-      "3. c > 0\n",
+      "What is the derivative of the function f(x) = 3x^2 + 2x + 1?\n",
+      "0. f'(x) = 6x + 2\n",
+      "1. f'(x) = 6x^2 + 2\n",
+      "2. f'(x) = 3x^2 + 2\n",
+      "3. f'(x) = 9x + 2\n",
       "\n",
       "Responses: [\"I don't know.\", 'a']\n"
      ]
@@ -1583,167 +1419,45 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 29,
    "metadata": {},
    "outputs": [
     {
      "data": {
-      "text/html": [
-       "
{\n",
-       "  \"id\": \"run_cTgSKShYNiCfW5XXuU01tAtP\",\n",
-       "  \"assistant_id\": \"asst_oWtP199nJHb6uR48GseDKtvv\",\n",
-       "  \"cancelled_at\": null,\n",
-       "  \"completed_at\": null,\n",
-       "  \"created_at\": 1699647410,\n",
-       "  \"expires_at\": 1699648010,\n",
-       "  \"failed_at\": null,\n",
-       "  \"file_ids\": [\n",
-       "    \"file-BXMBZx4F9yCVwW27doS6uRiJ\"\n",
-       "  ],\n",
-       "  \"instructions\": \"You are a personal math tutor. Answer questions briefly, in a sentence or less.\",\n",
-       "  \"last_error\": null,\n",
-       "  \"metadata\": {},\n",
-       "  \"model\": \"gpt-4-1106-preview\",\n",
-       "  \"object\": \"thread.run\",\n",
-       "  \"required_action\": null,\n",
-       "  \"started_at\": 1699647410,\n",
-       "  \"status\": \"queued\",\n",
-       "  \"thread_id\": \"thread_sVjQ15Tk8JAHwfwIKy190fMX\",\n",
-       "  \"tools\": [\n",
-       "    {\n",
-       "      \"type\": \"code_interpreter\"\n",
-       "    },\n",
-       "    {\n",
-       "      \"type\": \"retrieval\"\n",
-       "    },\n",
-       "    {\n",
-       "      \"function\": {\n",
-       "        \"name\": \"display_quiz\",\n",
-       "        \"parameters\": {\n",
-       "          \"type\": \"object\",\n",
-       "          \"properties\": {\n",
-       "            \"title\": {\n",
-       "              \"type\": \"string\"\n",
-       "            },\n",
-       "            \"questions\": {\n",
-       "              \"type\": \"array\",\n",
-       "              \"description\": \"An array of questions, each with a title and potentially options (if multiple choice).\",\n",
-       "              \"items\": {\n",
-       "                \"type\": \"object\",\n",
-       "                \"properties\": {\n",
-       "                  \"question_text\": {\n",
-       "                    \"type\": \"string\"\n",
-       "                  },\n",
-       "                  \"question_type\": {\n",
-       "                    \"type\": \"string\",\n",
-       "                    \"enum\": [\n",
-       "                      \"MULTIPLE_CHOICE\",\n",
-       "                      \"FREE_RESPONSE\"\n",
-       "                    ]\n",
-       "                  },\n",
-       "                  \"choices\": {\n",
-       "                    \"type\": \"array\",\n",
-       "                    \"items\": {\n",
-       "                      \"type\": \"string\"\n",
-       "                    }\n",
-       "                  }\n",
-       "                },\n",
-       "                \"required\": [\n",
-       "                  \"question_text\"\n",
-       "                ]\n",
-       "              }\n",
-       "            }\n",
-       "          },\n",
-       "          \"required\": [\n",
-       "            \"title\",\n",
-       "            \"questions\"\n",
-       "          ]\n",
-       "        },\n",
-       "        \"description\": \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"\n",
-       "      },\n",
-       "      \"type\": \"function\"\n",
-       "    }\n",
-       "  ]\n",
-       "}\n",
-       "
\n" - ], "text/plain": [ - "\u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"id\"\u001b[0m: \u001b[32m\"run_cTgSKShYNiCfW5XXuU01tAtP\"\u001b[0m,\n", - " \u001b[1;34m\"assistant_id\"\u001b[0m: \u001b[32m\"asst_oWtP199nJHb6uR48GseDKtvv\"\u001b[0m,\n", - " \u001b[1;34m\"cancelled_at\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"completed_at\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"created_at\"\u001b[0m: \u001b[1;36m1699647410\u001b[0m,\n", - " \u001b[1;34m\"expires_at\"\u001b[0m: \u001b[1;36m1699648010\u001b[0m,\n", - " \u001b[1;34m\"failed_at\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"file_ids\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"file-BXMBZx4F9yCVwW27doS6uRiJ\"\u001b[0m\n", - " \u001b[1m]\u001b[0m,\n", - " \u001b[1;34m\"instructions\"\u001b[0m: \u001b[32m\"You are a personal math tutor. Answer questions briefly, in a sentence or less.\"\u001b[0m,\n", - " \u001b[1;34m\"last_error\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"metadata\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"model\"\u001b[0m: \u001b[32m\"gpt-4-1106-preview\"\u001b[0m,\n", - " \u001b[1;34m\"object\"\u001b[0m: \u001b[32m\"thread.run\"\u001b[0m,\n", - " \u001b[1;34m\"required_action\"\u001b[0m: \u001b[3;35mnull\u001b[0m,\n", - " \u001b[1;34m\"started_at\"\u001b[0m: \u001b[1;36m1699647410\u001b[0m,\n", - " \u001b[1;34m\"status\"\u001b[0m: \u001b[32m\"queued\"\u001b[0m,\n", - " \u001b[1;34m\"thread_id\"\u001b[0m: \u001b[32m\"thread_sVjQ15Tk8JAHwfwIKy190fMX\"\u001b[0m,\n", - " \u001b[1;34m\"tools\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"code_interpreter\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"retrieval\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"function\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"name\"\u001b[0m: \u001b[32m\"display_quiz\"\u001b[0m,\n", - " \u001b[1;34m\"parameters\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"object\"\u001b[0m,\n", - " \u001b[1;34m\"properties\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"title\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"questions\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"array\"\u001b[0m,\n", - " \u001b[1;34m\"description\"\u001b[0m: \u001b[32m\"An array of questions, each with a title and potentially options (if multiple choice).\"\u001b[0m,\n", - " \u001b[1;34m\"items\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"object\"\u001b[0m,\n", - " \u001b[1;34m\"properties\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"question_text\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"question_type\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m,\n", - " \u001b[1;34m\"enum\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"MULTIPLE_CHOICE\"\u001b[0m,\n", - " \u001b[32m\"FREE_RESPONSE\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"choices\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"array\"\u001b[0m,\n", - " \u001b[1;34m\"items\"\u001b[0m: \u001b[1m{\u001b[0m\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"string\"\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"required\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"question_text\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"required\"\u001b[0m: \u001b[1m[\u001b[0m\n", - " \u001b[32m\"title\"\u001b[0m,\n", - " \u001b[32m\"questions\"\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"description\"\u001b[0m: \u001b[32m\"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"\u001b[0m\n", - " \u001b[1m}\u001b[0m,\n", - " \u001b[1;34m\"type\"\u001b[0m: \u001b[32m\"function\"\u001b[0m\n", - " \u001b[1m}\u001b[0m\n", - " \u001b[1m]\u001b[0m\n", - "\u001b[1m}\u001b[0m\n" + "{'id': 'run_6P1wtBLDSnlgTaaHRRJh7GeT',\n", + " 'assistant_id': 'asst_u4HvMODTO0Yh8cioTejb3NlZ',\n", + " 'cancelled_at': None,\n", + " 'completed_at': None,\n", + " 'created_at': 1699650818,\n", + " 'expires_at': 1699651418,\n", + " 'failed_at': None,\n", + " 'file_ids': ['file-bfXOZPBktVHlmm8rDDcCDTzD'],\n", + " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", + " 'last_error': None,\n", + " 'metadata': {},\n", + " 'model': 'gpt-4-1106-preview',\n", + " 'object': 'thread.run',\n", + " 'required_action': None,\n", + " 'started_at': 1699650818,\n", + " 'status': 'queued',\n", + " 'thread_id': 'thread_afPuFpKVuFCENZYey3LyDGfM',\n", + " 'tools': [{'type': 'code_interpreter'},\n", + " {'type': 'retrieval'},\n", + " {'function': {'name': 'display_quiz',\n", + " 'parameters': {'type': 'object',\n", + " 'properties': {'title': {'type': 'string'},\n", + " 'questions': {'type': 'array',\n", + " 'description': 'An array of questions, each with a title and potentially options (if multiple choice).',\n", + " 'items': {'type': 'object',\n", + " 'properties': {'question_text': {'type': 'string'},\n", + " 'question_type': {'type': 'string',\n", + " 'enum': ['MULTIPLE_CHOICE', 'FREE_RESPONSE']},\n", + " 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n", + " 'required': ['question_text']}}},\n", + " 'required': ['title', 'questions']},\n", + " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\"},\n", + " 'type': 'function'}]}" ] }, "metadata": {}, @@ -1773,7 +1487,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -1782,26 +1496,11 @@ "text": [ "# Messages\n", "user: Make a quiz with 2 questions: One open ended, one multiple choice. Then, give me feedback for the responses.\n", - "assistant: Sure, I can create a math quiz for you. Here is a suggested set of questions, one open-ended and the other multiple choice:\n", - "\n", - "**Question 1 (Open-ended):** \n", - "Calculate the derivative of the function \\( f(x) = 3x^3 - 5x^2 + 6 \\).\n", - "\n", - "**Question 2 (Multiple-choice):**\n", - "The graph of a quadratic function \\( ax^2 + bx + c \\) opens downward when:\n", - "- A) \\( a > 0 \\)\n", - "- B) \\( a < 0 \\)\n", - "- C) \\( b > 0 \\)\n", - "- D) \\( c > 0 \\)\n", - "\n", - "I will now use the `display_quiz` function to present these questions and then provide feedback on your responses. Let's proceed.\n", - "assistant: Thank you for your responses. Here is the feedback:\n", - "\n", - "For **Question 1**, the correct answer requires using the power rule of differentiation. The derivative of \\( f(x) = 3x^3 - 5x^2 + 6 \\) is \\( f'(x) = 9x^2 - 10x \\). This is obtained by differentiating each term separately: the derivative of \\(3x^3\\) is \\(9x^2\\), the derivative of \\(-5x^2\\) is \\(-10x\\), and the derivative of the constant term \\(6\\) is \\(0\\).\n", + "assistant: For the first question regarding the Pythagorean theorem, it is important to know that this theorem relates the lengths of the sides of a right-angled triangle. Specifically, the theorem states that the square of the length of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the lengths of the other two sides. This is intrinsically linked to the properties of a right angle and the way distances are related in Euclidean geometry; as such it only applies to right-angled triangles and not to other types of triangles.\n", "\n", - "For **Question 2**, the correct answer is B) \\( a < 0 \\). The sign of the coefficient \\(a\\) in a quadratic equation \\(ax^2 + bx + c\\) determines the direction in which the parabola opens. If \\(a\\) is positive, the parabola opens upward, and if \\(a\\) is negative, it opens downward. Therefore, the correct choice is \\(a < 0\\). You chose A) \\(a > 0\\), which is incorrect.\n", + "For the second question concerning the derivative of the function \\( f(x) = 3x^2 + 2x + 1 \\), the correct answer is \\( f'(x) = 6x + 2 \\), which means your choice of \"a\" was correct. The derivative of a function gives the rate of change of the function's output with respect to changes in the input. In the case of a polynomial function like the one given, the power rule can be applied to find the derivative. For the term \\( 3x^2 \\), the derivative is \\( 6x \\), and for \\( 2x \\), it is \\( 2 \\), and the constant \\( 1 \\) drops out as its derivative is zero. So the full derivative function is \\( f'(x) = 6x + 2 \\).\n", "\n", - "Would you like to try more questions or need further clarification on these topics?\n", + "Overall, well done on the multiple-choice question, and now you have a bit more insight on the open-ended question. Keep studying and asking questions to strengthen your understanding!\n", "\n" ] } diff --git a/images/assistants_overview_assistants_dashboard.png b/images/assistants_overview_assistants_dashboard.png new file mode 100644 index 0000000..dff577c Binary files /dev/null and b/images/assistants_overview_assistants_dashboard.png differ diff --git a/images/assistants_overview_assistants_playground.png b/images/assistants_overview_assistants_playground.png new file mode 100644 index 0000000..b55af21 Binary files /dev/null and b/images/assistants_overview_assistants_playground.png differ diff --git a/images/assistants_overview_enable_code_interpreter.png b/images/assistants_overview_enable_code_interpreter.png new file mode 100644 index 0000000..81d498d Binary files /dev/null and b/images/assistants_overview_enable_code_interpreter.png differ diff --git a/images/assistants_overview_enable_function.png b/images/assistants_overview_enable_function.png new file mode 100644 index 0000000..b17aa30 Binary files /dev/null and b/images/assistants_overview_enable_function.png differ diff --git a/images/assistants_overview_enable_retrieval.png b/images/assistants_overview_enable_retrieval.png new file mode 100644 index 0000000..fd6684f Binary files /dev/null and b/images/assistants_overview_enable_retrieval.png differ diff --git a/images/assistants_overview_new_assistant.png b/images/assistants_overview_new_assistant.png new file mode 100644 index 0000000..318f860 Binary files /dev/null and b/images/assistants_overview_new_assistant.png differ diff --git a/registry.yaml b/registry.yaml index 9b88e7c..976e643 100644 --- a/registry.yaml +++ b/registry.yaml @@ -1098,7 +1098,7 @@ tags: - completions -- title: Assistants API Overview with the Python SDK +- title: Assistants API Overview (Python SDK) path: examples/Assistants_API_overview_python.ipynb date: 2023-11-10 authors: