diff --git a/examples/Assistants_API_overview_python.ipynb b/examples/Assistants_API_overview_python.ipynb index 8c038ff..272cff5 100644 --- a/examples/Assistants_API_overview_python.ipynb +++ b/examples/Assistants_API_overview_python.ipynb @@ -11,7 +11,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The new [Assistants API](https://platform.openai.com/docs/assistants/overview) is a stateful evolution of our [Chat Completions API](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) meant to simplify the creation of assistant-like experiences, and enable developer access to powerful tools like Code Interpreter and Retrieval." + "The new [Assistants API](https://platform.openai.com/docs/assistants/overview) is a stateful evolution of our [Chat Completions API](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) meant to simplify the creation of assistant-like experiences, and enable developer access to powerful tools like Code Interpreter and File Search." ] }, { @@ -27,7 +27,7 @@ "source": [ "## Chat Completions API vs Assistants API\n", "\n", - "The primitives of the **Chat Completions API** are `Messages`, on which you perform a `Completion` with a `Model` (`gpt-3.5-turbo`, `gpt-4`, etc). It is lightweight and powerful, but inherently stateless, which means you have to manage conversation state, tool definitions, retrieval documents, and code execution manually.\n", + "The primitives of the **Chat Completions API** are `Messages`, on which you perform a `Completion` with a `Model` (`gpt-4o`, `gpt-4o-mini`, etc). It is lightweight and powerful, but inherently stateless, which means you have to manage conversation state, tool definitions, retrieval documents, and code execution manually.\n", "\n", "The primitives of the **Assistants API** are\n", "\n", @@ -47,34 +47,33 @@ "### 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.3` 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.59.4` at time of writing).\n" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: openai in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (1.51.2)\n", - "Requirement already satisfied: anyio<5,>=3.5.0 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from openai) (4.4.0)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from openai) (1.9.0)\n", - "Requirement already satisfied: httpx<1,>=0.23.0 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from openai) (0.27.2)\n", - "Requirement already satisfied: jiter<1,>=0.4.0 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from openai) (0.5.0)\n", - "Requirement already satisfied: pydantic<3,>=1.9.0 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from openai) (2.9.2)\n", - "Requirement already satisfied: sniffio in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from openai) (1.3.1)\n", - "Requirement already satisfied: tqdm>4 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from openai) (4.66.5)\n", - "Requirement already satisfied: typing-extensions<5,>=4.11 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from openai) (4.11.0)\n", - "Requirement already satisfied: idna>=2.8 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from anyio<5,>=3.5.0->openai) (3.10)\n", - "Requirement already satisfied: exceptiongroup>=1.0.2 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from anyio<5,>=3.5.0->openai) (1.2.0)\n", - "Requirement already satisfied: certifi in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from httpx<1,>=0.23.0->openai) (2024.8.30)\n", - "Requirement already satisfied: httpcore==1.* in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from httpx<1,>=0.23.0->openai) (1.0.5)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n", - "Requirement already satisfied: annotated-types>=0.6.0 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from pydantic<3,>=1.9.0->openai) (0.7.0)\n", - "Requirement already satisfied: pydantic-core==2.23.4 in /opt/homebrew/Caskroom/miniconda/base/envs/ops/lib/python3.9/site-packages (from pydantic<3,>=1.9.0->openai) (2.23.4)\n" + "Requirement already satisfied: openai in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (1.59.4)\n", + "Requirement already satisfied: anyio<5,>=3.5.0 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from openai) (3.7.1)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from openai) (1.9.0)\n", + "Requirement already satisfied: httpx<1,>=0.23.0 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from openai) (0.27.0)\n", + "Requirement already satisfied: jiter<1,>=0.4.0 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from openai) (0.7.0)\n", + "Requirement already satisfied: pydantic<3,>=1.9.0 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from openai) (2.8.2)\n", + "Requirement already satisfied: sniffio in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from openai) (1.3.1)\n", + "Requirement already satisfied: tqdm>4 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from openai) (4.66.4)\n", + "Requirement already satisfied: typing-extensions<5,>=4.11 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from openai) (4.12.2)\n", + "Requirement already satisfied: idna>=2.8 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from anyio<5,>=3.5.0->openai) (3.7)\n", + "Requirement already satisfied: certifi in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai) (2024.7.4)\n", + "Requirement already satisfied: httpcore==1.* in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai) (1.0.5)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.20.1 in /Users/lee.spacagna/myenv/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (2.20.1)\n" ] } ], @@ -91,14 +90,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Version: 1.51.2\n" + "Version: 1.59.4\n" ] } ], @@ -115,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -167,20 +166,6 @@ "![Creating New Assistant](../images/assistants_overview_new_assistant.png)\n" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can view Assistants you've created in the [Assistants Dashboard](https://platform.openai.com/assistants).\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Assistants Dashboard](../images/assistants_overview_assistants_dashboard.png)\n" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -190,18 +175,18 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", - " 'created_at': 1728757849,\n", + "{'id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", + " 'created_at': 1736340398,\n", " 'description': None,\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", " 'metadata': {},\n", - " 'model': 'gpt-4o-mini',\n", + " 'model': 'gpt-4o',\n", " 'name': 'Math Tutor',\n", " 'object': 'assistant',\n", " 'tools': [],\n", @@ -209,6 +194,11 @@ " 'temperature': 1.0,\n", " 'tool_resources': {'code_interpreter': None, 'file_search': None},\n", " 'top_p': 1.0}" + " 'tools': [],\n", + " 'response_format': 'auto',\n", + " 'temperature': 1.0,\n", + " 'tool_resources': {'code_interpreter': None, 'file_search': None},\n", + " 'top_p': 1.0}" ] }, "metadata": {}, @@ -225,7 +215,7 @@ "assistant = client.beta.assistants.create(\n", " name=\"Math Tutor\",\n", " instructions=\"You are a personal math tutor. Answer questions briefly, in a sentence or less.\",\n", - " model=\"gpt-4o-mini\",\n", + " model=\"gpt-4o\",\n", ")\n", "show_json(assistant)" ] @@ -260,17 +250,19 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L',\n", - " 'created_at': 1728757849,\n", + "{'id': 'thread_j4dc1TiHPfkviKUHNi4aAsA6',\n", + " 'created_at': 1736340398,\n", " 'metadata': {},\n", " 'object': 'thread',\n", " 'tool_resources': {'code_interpreter': None, 'file_search': None}}" + " 'object': 'thread',\n", + " 'tool_resources': {'code_interpreter': None, 'file_search': None}}" ] }, "metadata": {}, @@ -291,20 +283,22 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'msg_D9BDx2WGGAWaL7xtjNmItGTi',\n", + "{'id': 'msg_1q4Y7ZZ9gIcPoAKSx9UtrrKJ',\n", " 'assistant_id': None,\n", " 'attachments': [],\n", " 'completed_at': None,\n", + " 'attachments': [],\n", + " 'completed_at': 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': 1728757850,\n", + " 'created_at': 1736340400,\n", " 'incomplete_at': None,\n", " 'incomplete_details': None,\n", " 'metadata': {},\n", @@ -312,7 +306,7 @@ " 'role': 'user',\n", " 'run_id': None,\n", " 'status': None,\n", - " 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L'}" + " 'thread_id': 'thread_j4dc1TiHPfkviKUHNi4aAsA6'}" ] }, "metadata": {}, @@ -354,33 +348,38 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'run_HgqxvVoL5lCLQi4NcdfQ17p1',\n", - " 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", + "{'id': 'run_qVYsWok6OCjHxkajpIrdHuVP',\n", + " 'assistant_id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", " 'cancelled_at': None,\n", " 'completed_at': None,\n", - " 'created_at': 1728757851,\n", - " 'expires_at': 1728758451,\n", + " 'created_at': 1736340403,\n", + " 'expires_at': 1736341003,\n", " 'failed_at': None,\n", " 'incomplete_details': None,\n", + " 'incomplete_details': None,\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", " 'last_error': None,\n", " 'max_completion_tokens': None,\n", " 'max_prompt_tokens': None,\n", + " 'max_completion_tokens': None,\n", + " 'max_prompt_tokens': None,\n", " 'metadata': {},\n", - " 'model': 'gpt-4o-mini',\n", + " 'model': 'gpt-4o',\n", " 'object': 'thread.run',\n", " 'parallel_tool_calls': True,\n", + " 'parallel_tool_calls': True,\n", " 'required_action': None,\n", " 'response_format': 'auto',\n", + " 'response_format': 'auto',\n", " 'started_at': None,\n", " 'status': 'queued',\n", - " 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L',\n", + " 'thread_id': 'thread_j4dc1TiHPfkviKUHNi4aAsA6',\n", " 'tool_choice': 'auto',\n", " 'tools': [],\n", " 'truncation_strategy': {'type': 'auto', 'last_messages': None},\n", @@ -413,7 +412,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -431,37 +430,45 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'run_HgqxvVoL5lCLQi4NcdfQ17p1',\n", - " 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", + "{'id': 'run_qVYsWok6OCjHxkajpIrdHuVP',\n", + " 'assistant_id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", " 'cancelled_at': None,\n", - " 'completed_at': 1728757853,\n", - " 'created_at': 1728757851,\n", + " 'completed_at': 1736340406,\n", + " 'created_at': 1736340403,\n", " 'expires_at': None,\n", " 'failed_at': None,\n", " 'incomplete_details': None,\n", + " 'incomplete_details': None,\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", " 'last_error': None,\n", " 'max_completion_tokens': None,\n", " 'max_prompt_tokens': None,\n", + " 'max_completion_tokens': None,\n", + " 'max_prompt_tokens': None,\n", " 'metadata': {},\n", - " 'model': 'gpt-4o-mini',\n", + " 'model': 'gpt-4o',\n", " 'object': 'thread.run',\n", " 'parallel_tool_calls': True,\n", + " 'parallel_tool_calls': True,\n", " 'required_action': None,\n", " 'response_format': 'auto',\n", - " 'started_at': 1728757852,\n", + " 'started_at': 1736340405,\n", " 'status': 'completed',\n", - " 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L',\n", + " 'thread_id': 'thread_j4dc1TiHPfkviKUHNi4aAsA6',\n", " 'tool_choice': 'auto',\n", " 'tools': [],\n", " 'truncation_strategy': {'type': 'auto', 'last_messages': None},\n", - " 'usage': {'completion_tokens': 40, 'prompt_tokens': 66, 'total_tokens': 106},\n", + " 'usage': {'completion_tokens': 35,\n", + " 'prompt_tokens': 66,\n", + " 'total_tokens': 101,\n", + " 'prompt_token_details': {'cached_tokens': 0},\n", + " 'completion_tokens_details': {'reasoning_tokens': 0}},\n", " 'temperature': 1.0,\n", " 'top_p': 1.0,\n", " 'tool_resources': {}}" @@ -492,36 +499,38 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'data': [{'id': 'msg_oxudC146DeS6nEx8xAsEIyil',\n", - " 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", + "{'data': [{'id': 'msg_A5eAN6ZAJDmFBOYutEm5DFCy',\n", + " 'assistant_id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", " 'attachments': [],\n", " 'completed_at': None,\n", " 'content': [{'text': {'annotations': [],\n", - " 'value': 'Sure! To solve for \\\\( x \\\\), subtract 11 from both sides: \\\\( 3x = 3 \\\\), then divide by 3: \\\\( x = 1 \\\\).'},\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': 1728757852,\n", + " 'created_at': 1736340405,\n", " 'incomplete_at': None,\n", " 'incomplete_details': None,\n", " 'metadata': {},\n", " 'object': 'thread.message',\n", " 'role': 'assistant',\n", - " 'run_id': 'run_HgqxvVoL5lCLQi4NcdfQ17p1',\n", + " 'run_id': 'run_qVYsWok6OCjHxkajpIrdHuVP',\n", " 'status': None,\n", - " 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L'},\n", - " {'id': 'msg_D9BDx2WGGAWaL7xtjNmItGTi',\n", + " 'thread_id': 'thread_j4dc1TiHPfkviKUHNi4aAsA6'},\n", + " {'id': 'msg_1q4Y7ZZ9gIcPoAKSx9UtrrKJ',\n", " 'assistant_id': None,\n", " 'attachments': [],\n", " 'completed_at': None,\n", + " 'attachments': [],\n", + " 'completed_at': 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': 1728757850,\n", + " 'created_at': 1736340400,\n", " 'incomplete_at': None,\n", " 'incomplete_details': None,\n", " 'metadata': {},\n", @@ -529,10 +538,10 @@ " 'role': 'user',\n", " 'run_id': None,\n", " 'status': None,\n", - " 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L'}],\n", + " 'thread_id': 'thread_j4dc1TiHPfkviKUHNi4aAsA6'}],\n", " 'object': 'list',\n", - " 'first_id': 'msg_oxudC146DeS6nEx8xAsEIyil',\n", - " 'last_id': 'msg_D9BDx2WGGAWaL7xtjNmItGTi',\n", + " 'first_id': 'msg_A5eAN6ZAJDmFBOYutEm5DFCy',\n", + " 'last_id': 'msg_1q4Y7ZZ9gIcPoAKSx9UtrrKJ',\n", " 'has_more': False}" ] }, @@ -561,31 +570,31 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'data': [{'id': 'msg_xggODJjxCZpTcYutKOhlKQTW',\n", - " 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", + "{'data': [{'id': 'msg_wSHHvaMnaWktZWsKs6gyoPUB',\n", + " 'assistant_id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", " 'attachments': [],\n", " 'completed_at': None,\n", " 'content': [{'text': {'annotations': [],\n", - " 'value': 'Of course! \\n\\n1. Start with the equation: \\\\( 3x + 11 = 14 \\\\).\\n2. To isolate the term with \\\\( x \\\\), subtract 11 from both sides: \\n \\\\[\\n 3x + 11 - 11 = 14 - 11 \\\\implies 3x = 3\\n \\\\]\\n3. Now, divide both sides by 3 to solve for \\\\( x \\\\):\\n \\\\[\\n \\\\frac{3x}{3} = \\\\frac{3}{3} \\\\implies x = 1\\n \\\\]\\n\\nSo, the solution is \\\\( x = 1 \\\\).'},\n", + " 'value': 'Certainly! To isolate \\\\(x\\\\), first subtract 11 from both sides of the equation \\\\(3x + 11 = 14\\\\), resulting in \\\\(3x = 3\\\\). Then, divide both sides by 3 to solve for \\\\(x\\\\), giving you \\\\(x = 1\\\\).'},\n", " 'type': 'text'}],\n", - " 'created_at': 1728757857,\n", + " 'created_at': 1736340414,\n", " 'incomplete_at': None,\n", " 'incomplete_details': None,\n", " 'metadata': {},\n", " 'object': 'thread.message',\n", " 'role': 'assistant',\n", - " 'run_id': 'run_mAnVCGyFm8Mf9ZM9HVJaIO5c',\n", + " 'run_id': 'run_lJsumsDtPTmdG3Enx2CfYrrq',\n", " 'status': None,\n", - " 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L'}],\n", + " 'thread_id': 'thread_j4dc1TiHPfkviKUHNi4aAsA6'}],\n", " 'object': 'list',\n", - " 'first_id': 'msg_xggODJjxCZpTcYutKOhlKQTW',\n", - " 'last_id': 'msg_xggODJjxCZpTcYutKOhlKQTW',\n", + " 'first_id': 'msg_wSHHvaMnaWktZWsKs6gyoPUB',\n", + " 'last_id': 'msg_wSHHvaMnaWktZWsKs6gyoPUB',\n", " 'has_more': False}" ] }, @@ -643,7 +652,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -678,7 +687,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -707,7 +716,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -716,19 +725,19 @@ "text": [ "# Messages\n", "user: I need to solve the equation `3x + 11 = 14`. Can you help me?\n", - "assistant: Sure! 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 by 3 to find \\(x = 1\\).\n", "\n", "# Messages\n", "user: Could you explain linear algebra to me?\n", - "assistant: Linear algebra is the branch of mathematics that deals with vectors, vector spaces, linear transformations, and systems of linear equations.\n", + "assistant: Linear algebra is the branch of mathematics concerning vector spaces, linear transformations, and systems of linear equations, often represented with matrices.\n", "\n", "# Messages\n", "user: I don't like math. What can I do?\n", - "assistant: Try to find real-life applications of math that interest you, or approach it with a positive mindset by practicing and seeking help when needed.\n", + "assistant: Try relating math to real-life interests or hobbies, practice with fun games or apps, and gradually build confidence with easier problems.\n", "\n", "# Messages\n", "user: I don't like math. What can I do?\n", - "assistant: Try to find real-life applications of math that interest you, or approach it with a positive mindset by practicing and seeking help when needed.\n", + "assistant: Try relating math to real-life interests or hobbies, practice with fun games or apps, and gradually build confidence with easier problems.\n", "user: Thank you!\n", "assistant: You're welcome! If you have any more questions, feel free to ask!\n", "\n" @@ -790,7 +799,7 @@ "source": [ "## Tools\n", "\n", - "A key feature of the Assistants API is the ability to equip our Assistants with Tools, like Code Interpreter, Retrieval, and custom Functions. Let's take a look at each.\n", + "A key feature of the Assistants API is the ability to equip our Assistants with Tools, like Code Interpreter, File Search, and custom Functions. Let's take a look at each.\n", "\n", "### Code Interpreter\n", "\n", @@ -813,18 +822,18 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", - " 'created_at': 1728757849,\n", + "{'id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", + " 'created_at': 1736340398,\n", " 'description': None,\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", " 'metadata': {},\n", - " 'model': 'gpt-4o-mini',\n", + " 'model': 'gpt-4o',\n", " 'name': 'Math Tutor',\n", " 'object': 'assistant',\n", " 'tools': [{'type': 'code_interpreter'}],\n", @@ -832,6 +841,11 @@ " 'temperature': 1.0,\n", " 'tool_resources': {'code_interpreter': {'file_ids': []}, 'file_search': None},\n", " 'top_p': 1.0}" + " 'tools': [{'type': 'code_interpreter'}],\n", + " 'response_format': 'auto',\n", + " 'temperature': 1.0,\n", + " 'tool_resources': {'code_interpreter': {'file_ids': []}, 'file_search': None},\n", + " 'top_p': 1.0}" ] }, "metadata": {}, @@ -855,7 +869,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -864,8 +878,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" ] } @@ -898,7 +911,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -916,14 +929,14 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'tool_calls': [{'id': 'call_cFUCLTIFePVVPwNTs6BvzjCj',\n", - " 'code_interpreter': {'input': 'def fibonacci(n):\\n fib_sequence = [0, 1]\\n for i in range(2, 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", + "{'tool_calls': [{'id': 'call_E1EE1loDmcWoc7FpkOMKYj6n',\n", + " 'code_interpreter': {'input': 'def generate_fibonacci(n):\\n fib_sequence = [0, 1]\\n while len(fib_sequence) < n:\\n next_value = fib_sequence[-1] + fib_sequence[-2]\\n fib_sequence.append(next_value)\\n return fib_sequence\\n\\n# Generate the first 20 Fibonacci numbers\\nfirst_20_fibonacci = generate_fibonacci(20)\\nfirst_20_fibonacci',\n", " 'outputs': []},\n", " 'type': 'code_interpreter'}],\n", " 'type': 'tool_calls'}" @@ -942,7 +955,7 @@ { "data": { "text/plain": [ - "{'message_creation': {'message_id': 'msg_EurIZ6oj8fofsg2JlQaNw0AZ'},\n", + "{'message_creation': {'message_id': 'msg_RzTnbBMmzDYHk79a0x9qM5uU'},\n", " 'type': 'message_creation'}" ] }, @@ -984,9 +997,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Retrieval\n", + "### File search\n", "\n", - "Another powerful tool in the Assistants API is [Retrieval](https://platform.openai.com/docs/assistants/tools/knowledge-retrieval): the ability to upload files that the Assistant will use as a knowledge base when answering questions. This can also be enabled from the Dashboard or the API, where we can upload files we want to be used.\n" + "Another powerful tool in the Assistants API is [File search](https://platform.openai.com/docs/assistants/tools/file-search). This allows the uploading of files to the Assistant to be used as a knowledge base when answering questions.\n" ] }, { @@ -998,25 +1011,36 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 20, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "File added to vector store\n" + ] + }, { "data": { "text/plain": [ - "{'id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", - " 'created_at': 1728757849,\n", + "{'id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", + " 'created_at': 1736340398,\n", " 'description': None,\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", " 'metadata': {},\n", - " 'model': 'gpt-4o-mini',\n", + " 'model': 'gpt-4o',\n", " 'name': 'Math Tutor',\n", " 'object': 'assistant',\n", - " 'tools': [{'type': 'code_interpreter'}],\n", + " 'tools': [{'type': 'code_interpreter'},\n", + " {'type': 'file_search',\n", + " 'file_search': {'max_num_results': None,\n", + " 'ranking_options': {'score_threshold': 0.0,\n", + " 'ranker': 'default_2024_08_21'}}}],\n", " 'response_format': 'auto',\n", " 'temperature': 1.0,\n", - " 'tool_resources': {'code_interpreter': {'file_ids': ['file-HpD4hsytxNpuq3LaGnGCOdCR']},\n", - " 'file_search': None},\n", + " 'tool_resources': {'code_interpreter': {'file_ids': ['file-GQFm2i7N8LrAQatefWKEsE']},\n", + " 'file_search': {'vector_store_ids': ['vs_dEArILZSJh7J799QACi3QhuU']}},\n", " 'top_p': 1.0}" ] }, @@ -1033,18 +1057,45 @@ " ),\n", " purpose=\"assistants\",\n", ")\n", + "\n", + "# Create a vector store\n", + "vector_store = client.beta.vector_stores.create(\n", + " name=\"language_models_are_unsupervised_multitask_learners\",\n", + ")\n", + "\n", + "# Add the file to the vector store\n", + "vector_store_file = client.beta.vector_stores.files.create_and_poll(\n", + " vector_store_id=vector_store.id,\n", + " file_id=file.id,\n", + ")\n", + "\n", + "# Confirm the file was added\n", + "while vector_store_file.status == \"in_progress\":\n", + " time.sleep(1)\n", + "if vector_store_file.status == \"completed\":\n", + " print(\"File added to vector store\")\n", + "elif vector_store_file.status == \"failed\":\n", + " raise Exception(\"Failed to add file to vector store\")\n", + "\n", "# Update Assistant\n", "assistant = client.beta.assistants.update(\n", " MATH_ASSISTANT_ID,\n", - " tools=[{\"type\": \"code_interpreter\"}],\n", - " tool_resources={\"code_interpreter\": {\"file_ids\": [file.id]}},\n", + " tools=[{\"type\": \"code_interpreter\"}, {\"type\": \"file_search\"}],\n", + " tool_resources={\n", + " \"file_search\":{\n", + " \"vector_store_ids\": [vector_store.id]\n", + " },\n", + " \"code_interpreter\": {\n", + " \"file_ids\": [file.id]\n", + " }\n", + " },\n", ")\n", "show_json(assistant)" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -1053,8 +1104,7 @@ "text": [ "# Messages\n", "user: What are some cool math concepts behind this ML paper pdf? Explain in two sentences.\n", - "assistant: I'll first take a look at the contents of the uploaded PDF file to identify the key mathematical concepts discussed in it. Let's analyze the file.\n", - "assistant: The document appears to focus on the capabilities of language models, particularly GPT-2, in performing various natural language processing tasks without explicit supervision. Key mathematical concepts likely include optimization methods for training neural networks, such as gradient descent, and statistical measures for evaluating model performance, such as F1 score.\n", + "assistant: The paper explores the concept of multitask learning where a single model is used to perform various tasks, modeling the conditional distribution \\( p(\\text{output} | \\text{input, task}) \\), inspired by probabilistic approaches【6:10†source】. It also discusses the use of Transformer-based architectures and parallel corpus substitution in language models, enhancing their ability to generalize across domain tasks without explicit task-specific supervision【6:2†source】【6:5†source】.\n", "\n" ] } @@ -1072,7 +1122,28 @@ "metadata": {}, "source": [ "> **Note**\n", - "> There are more intricacies in Retrieval, like [Annotations](https://platform.openai.com/docs/assistants/how-it-works/managing-threads-and-messages), which may be covered in another cookbook.\n" + "> There are more intricacies in File Search, like [Annotations](https://platform.openai.com/docs/assistants/how-it-works/managing-threads-and-messages), which may be covered in another cookbook.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "VectorStoreDeleted(id='vs_dEArILZSJh7J799QACi3QhuU', deleted=True, object='vector_store.deleted')" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the vector store\n", + "client.beta.vector_stores.delete(vector_store.id)\n" ] }, { @@ -1093,12 +1164,12 @@ " - `question_type`: [`MULTIPLE_CHOICE`, `FREE_RESPONSE`]\n", " - `choices`: [\"choice 1\", \"choice 2\", ...]\n", "\n", - "Unfortunately I don't know how to get user input within a Python Notebook, so I'll be mocking out responses with `get_mock_response...`. This is where you'd get the user's actual input.\n" + "I'll mocking out responses with `get_mock_response...`. This is where you'd get the user's actual input.\n" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -1144,7 +1215,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -1189,7 +1260,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ @@ -1209,17 +1280,17 @@ " \"question_text\": {\"type\": \"string\"},\n", " \"question_type\": {\n", " \"type\": \"string\",\n", - " \"enum\": [\"MULTIPLE_CHOICE\", \"FREE_RESPONSE\"],\n", + " \"enum\": [\"MULTIPLE_CHOICE\", \"FREE_RESPONSE\"]\n", " },\n", - " \"choices\": {\"type\": \"array\", \"items\": {\"type\": \"string\"}},\n", + " \"choices\": {\"type\": \"array\", \"items\": {\"type\": \"string\"}}\n", " },\n", - " \"required\": [\"question_text\"],\n", - " },\n", - " },\n", + " \"required\": [\"question_text\"]\n", + " }\n", + " }\n", " },\n", - " \"required\": [\"title\", \"questions\"],\n", - " },\n", - "}" + " \"required\": [\"title\", \"questions\"]\n", + " }\n", + "}\n" ] }, { @@ -1246,23 +1317,28 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", - " 'created_at': 1728757849,\n", + "{'id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", + " 'created_at': 1736340398,\n", " 'description': None,\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", " 'metadata': {},\n", - " 'model': 'gpt-4o-mini',\n", + " 'model': 'gpt-4o',\n", " 'name': 'Math Tutor',\n", " 'object': 'assistant',\n", " 'tools': [{'type': 'code_interpreter'},\n", + " {'type': 'file_search',\n", + " 'file_search': {'max_num_results': None,\n", + " 'ranking_options': {'score_threshold': 0.0,\n", + " 'ranker': 'default_2024_08_21'}}},\n", " {'function': {'name': 'display_quiz',\n", " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\",\n", + " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\",\n", " 'parameters': {'type': 'object',\n", " 'properties': {'title': {'type': 'string'},\n", " 'questions': {'type': 'array',\n", @@ -1278,8 +1354,8 @@ " 'type': 'function'}],\n", " 'response_format': 'auto',\n", " 'temperature': 1.0,\n", - " 'tool_resources': {'code_interpreter': {'file_ids': ['file-HpD4hsytxNpuq3LaGnGCOdCR']},\n", - " 'file_search': None},\n", + " 'tool_resources': {'code_interpreter': {'file_ids': ['file-GQFm2i7N8LrAQatefWKEsE']},\n", + " 'file_search': {'vector_store_ids': []}},\n", " 'top_p': 1.0}" ] }, @@ -1292,6 +1368,7 @@ " MATH_ASSISTANT_ID,\n", " tools=[\n", " {\"type\": \"code_interpreter\"},\n", + " {\"type\": \"file_search\"},\n", " {\"type\": \"function\", \"function\": function_json},\n", " ],\n", ")\n", @@ -1307,7 +1384,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -1316,7 +1393,7 @@ "'requires_action'" ] }, - "execution_count": 25, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -1338,41 +1415,49 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'run_bGozAWfICx0SbHJgIhk9hEAt',\n", - " 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", + "{'id': 'run_ekMRSI2h35asEzKirRf4BTwZ',\n", + " 'assistant_id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", " 'cancelled_at': None,\n", " 'completed_at': None,\n", - " 'created_at': 1728757910,\n", - " 'expires_at': 1728758510,\n", + " 'created_at': 1736341020,\n", + " 'expires_at': 1736341620,\n", " 'failed_at': None,\n", " 'incomplete_details': None,\n", + " 'incomplete_details': None,\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", " 'last_error': None,\n", " 'max_completion_tokens': None,\n", " 'max_prompt_tokens': None,\n", + " 'max_completion_tokens': None,\n", + " 'max_prompt_tokens': None,\n", " 'metadata': {},\n", - " 'model': 'gpt-4o-mini',\n", + " 'model': 'gpt-4o',\n", " 'object': 'thread.run',\n", " 'parallel_tool_calls': True,\n", - " 'required_action': {'submit_tool_outputs': {'tool_calls': [{'id': 'call_FCukTw0EeUDC873gcF4Pgi5B',\n", - " 'function': {'arguments': '{\"title\": \"Math Quiz\", \"questions\": [{\"question_text\": \"What is the area of a triangle with a base of 10 units and a height of 5 units?\", \"question_type\": \"FREE_RESPONSE\"}, {\"question_text\": \"What is the value of 3 x (2 + 4)?\", \"question_type\": \"MULTIPLE_CHOICE\", \"choices\": [\"A) 12\", \"B) 15\", \"C) 21\", \"D) 18\"]}]}',\n", + " 'required_action': {'submit_tool_outputs': {'tool_calls': [{'id': 'call_uvJEn0fxM4sgmzek8wahBGLi',\n", + " 'function': {'arguments': '{\"title\":\"Math Quiz\",\"questions\":[{\"question_text\":\"What is the derivative of the function f(x) = 3x^2 + 2x - 5?\",\"question_type\":\"FREE_RESPONSE\"},{\"question_text\":\"What is the value of \\\\\\\\( \\\\\\\\int_{0}^{1} 2x \\\\\\\\, dx \\\\\\\\)?\",\"question_type\":\"MULTIPLE_CHOICE\",\"choices\":[\"0\",\"1\",\"2\",\"3\"]}]}',\n", " 'name': 'display_quiz'},\n", " 'type': 'function'}]},\n", " 'type': 'submit_tool_outputs'},\n", " 'response_format': 'auto',\n", - " 'started_at': 1728757910,\n", + " 'started_at': 1736341022,\n", " 'status': 'requires_action',\n", - " 'thread_id': 'thread_jdCqIesorZG5UggY6qMbTib2',\n", + " 'thread_id': 'thread_8bK2PXfoeijEHBVEzYuJXt17',\n", " 'tool_choice': 'auto',\n", " 'tools': [{'type': 'code_interpreter'},\n", + " {'type': 'file_search',\n", + " 'file_search': {'max_num_results': None,\n", + " 'ranking_options': {'score_threshold': 0.0,\n", + " 'ranker': 'default_2024_08_21'}}},\n", " {'function': {'name': 'display_quiz',\n", " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\",\n", + " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\",\n", " 'parameters': {'type': 'object',\n", " 'properties': {'title': {'type': 'string'},\n", " 'questions': {'type': 'array',\n", @@ -1391,6 +1476,13 @@ " 'temperature': 1.0,\n", " 'top_p': 1.0,\n", " 'tool_resources': {}}" + " 'strict': False},\n", + " 'type': 'function'}],\n", + " 'truncation_strategy': {'type': 'auto', 'last_messages': None},\n", + " 'usage': None,\n", + " 'temperature': 1.0,\n", + " 'top_p': 1.0,\n", + " 'tool_resources': {}}" ] }, "metadata": {}, @@ -1413,7 +1505,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -1428,14 +1520,14 @@ "data": { "text/plain": [ "{'title': 'Math Quiz',\n", - " 'questions': [{'question_text': 'What is the area of a triangle with a base of 10 units and a height of 5 units?',\n", + " 'questions': [{'question_text': 'What is the derivative of the function f(x) = 3x^2 + 2x - 5?',\n", " 'question_type': 'FREE_RESPONSE'},\n", - " {'question_text': 'What is the value of 3 x (2 + 4)?',\n", + " {'question_text': 'What is the value of \\\\( \\\\int_{0}^{1} 2x \\\\, dx \\\\)?',\n", " 'question_type': 'MULTIPLE_CHOICE',\n", - " 'choices': ['A) 12', 'B) 15', 'C) 21', 'D) 18']}]}" + " 'choices': ['0', '1', '2', '3']}]}" ] }, - "execution_count": 27, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -1460,22 +1552,23 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "Quiz: Math Quiz\n", "Quiz: Math Quiz\n", "\n", - "What is the area of a triangle with a base of 10 units and a height of 5 units?\n", + "What is the derivative of the function f(x) = 3x^2 + 2x - 5?\n", "\n", - "What is the value of 3 x (2 + 4)?\n", - "0. A) 12\n", - "1. B) 15\n", - "2. C) 21\n", - "3. D) 18\n", + "What is the value of \\( \\int_{0}^{1} 2x \\, dx \\)?\n", + "0. 0\n", + "1. 1\n", + "2. 2\n", + "3. 3\n", "\n", "Responses: [\"I don't know.\", 'a']\n" ] @@ -1497,72 +1590,46 @@ }, { "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Quiz: Math Quiz\n", - "\n", - "What is the area of a triangle with a base of 10 units and a height of 5 units?\n", - "\n", - "What is the value of 3 x (2 + 4)?\n", - "0. A) 12\n", - "1. B) 15\n", - "2. C) 21\n", - "3. D) 18\n", - "\n" - ] - } - ], - "source": [ - "tool_outputs = []\n", - "tool_calls = run.required_action.submit_tool_outputs.tool_calls\n", - "\n", - "for tool_call in tool_calls:\n", - " arguments = json.loads(tool_call.function.arguments)\n", - " responses = display_quiz(arguments[\"title\"], arguments[\"questions\"])\n", - " tool_outputs.append({\n", - " \"tool_call_id\": tool_call.id,\n", - " \"output\": json.dumps(responses),\n", - " })" - ] - }, - { - "cell_type": "code", - "execution_count": 30, + "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'id': 'run_bGozAWfICx0SbHJgIhk9hEAt',\n", - " 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n", + "{'id': 'run_ekMRSI2h35asEzKirRf4BTwZ',\n", + " 'assistant_id': 'asst_qvXmYlZV8zhABI2RtPzDfV6z',\n", " 'cancelled_at': None,\n", " 'completed_at': None,\n", - " 'created_at': 1728757910,\n", - " 'expires_at': 1728758510,\n", + " 'created_at': 1736341020,\n", + " 'expires_at': 1736341620,\n", " 'failed_at': None,\n", " 'incomplete_details': None,\n", + " 'incomplete_details': None,\n", " 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n", " 'last_error': None,\n", " 'max_completion_tokens': None,\n", " 'max_prompt_tokens': None,\n", + " 'max_completion_tokens': None,\n", + " 'max_prompt_tokens': None,\n", " 'metadata': {},\n", - " 'model': 'gpt-4o-mini',\n", + " 'model': 'gpt-4o',\n", " 'object': 'thread.run',\n", " 'parallel_tool_calls': True,\n", + " 'parallel_tool_calls': True,\n", " 'required_action': None,\n", " 'response_format': 'auto',\n", - " 'started_at': 1728757910,\n", + " 'started_at': 1736341022,\n", " 'status': 'queued',\n", - " 'thread_id': 'thread_jdCqIesorZG5UggY6qMbTib2',\n", + " 'thread_id': 'thread_8bK2PXfoeijEHBVEzYuJXt17',\n", " 'tool_choice': 'auto',\n", " 'tools': [{'type': 'code_interpreter'},\n", + " {'type': 'file_search',\n", + " 'file_search': {'max_num_results': None,\n", + " 'ranking_options': {'score_threshold': 0.0,\n", + " 'ranker': 'default_2024_08_21'}}},\n", " {'function': {'name': 'display_quiz',\n", " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\",\n", + " 'description': \"Displays a quiz to the student, and returns the student's response. A single quiz can have multiple questions.\",\n", " 'parameters': {'type': 'object',\n", " 'properties': {'title': {'type': 'string'},\n", " 'questions': {'type': 'array',\n", @@ -1581,6 +1648,13 @@ " 'temperature': 1.0,\n", " 'top_p': 1.0,\n", " 'tool_resources': {}}" + " 'strict': False},\n", + " 'type': 'function'}],\n", + " 'truncation_strategy': {'type': 'auto', 'last_messages': None},\n", + " 'usage': None,\n", + " 'temperature': 1.0,\n", + " 'top_p': 1.0,\n", + " 'tool_resources': {}}" ] }, "metadata": {}, @@ -1605,7 +1679,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -1614,16 +1688,26 @@ "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: Your responses are:\n", + "assistant: Since no specific information was found in the uploaded file, I'll create a general math quiz for you:\n", "\n", - "1. Open-ended question: \"I don't know.\" \n", - "2. Multiple choice: \"a\"\n", + "1. **Open-ended Question**: What is the derivative of the function \\( f(x) = 3x^2 + 2x - 5 \\)?\n", "\n", - "### Feedback:\n", - "1. For the first question, the area of a triangle is calculated using the formula \\( \\frac{1}{2} \\times \\text{base} \\times \\text{height} \\). The correct answer is 25 square units.\n", - "2. For the second question, the correct answer is option D) 18, since \\( 3 \\times (2 + 4) = 3 \\times 6 = 18 \\).\n", + "2. **Multiple Choice Question**: What is the value of \\( \\int_{0}^{1} 2x \\, dx \\)?\n", + " - A) 0\n", + " - B) 1\n", + " - C) 2\n", + " - D) 3\n", "\n", - "Keep practicing! Would you like to try another quiz?\n", + "I will now present the quiz to you for response.\n", + "assistant: Here is the feedback for your responses:\n", + "\n", + "1. **Derivative Question**: \n", + " - Your Response: \"I don't know.\"\n", + " - Feedback: The derivative of \\( f(x) = 3x^2 + 2x - 5 \\) is \\( f'(x) = 6x + 2 \\).\n", + "\n", + "2. **Integration Question**: \n", + " - Your Response: A) 0\n", + " - Feedback: The correct answer is B) 1. The integration \\(\\int_{0}^{1} 2x \\, dx \\) evaluates to 1.\n", "\n" ] } @@ -1676,7 +1760,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.19" + "version": "3.12.7" } }, "nbformat": 4, diff --git a/images/assistants_overview_assistants_playground.png b/images/assistants_overview_assistants_playground.png index b55af21..9adf82b 100644 Binary files a/images/assistants_overview_assistants_playground.png 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 index 81d498d..399b520 100644 Binary files a/images/assistants_overview_enable_code_interpreter.png 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 index b17aa30..b486534 100644 Binary files a/images/assistants_overview_enable_function.png 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 index fd6684f..86d5fbd 100644 Binary files a/images/assistants_overview_enable_retrieval.png 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 index 318f860..69274aa 100644 Binary files a/images/assistants_overview_new_assistant.png and b/images/assistants_overview_new_assistant.png differ