mirror of
https://github.com/james-m-jordan/openai-cookbook.git
synced 2025-05-09 19:32:38 +00:00
Assistants_API_overview_python
notebook updated for the latest openai
package (#1464)
This commit is contained in:
parent
010e24382c
commit
686e0d7a9f
@ -54,7 +54,30 @@
|
|||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"!pip install --upgrade openai"
|
"!pip install --upgrade openai"
|
||||||
]
|
]
|
||||||
@ -75,7 +98,7 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"Version: 1.2.3\n"
|
"Version: 1.51.2\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -173,16 +196,19 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
"{'id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
" 'created_at': 1699828331,\n",
|
" 'created_at': 1728757849,\n",
|
||||||
" 'description': None,\n",
|
" 'description': None,\n",
|
||||||
" 'file_ids': [],\n",
|
|
||||||
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'model': 'gpt-4-1106-preview',\n",
|
" 'model': 'gpt-4o-mini',\n",
|
||||||
" 'name': 'Math Tutor',\n",
|
" 'name': 'Math Tutor',\n",
|
||||||
" 'object': 'assistant',\n",
|
" 'object': 'assistant',\n",
|
||||||
" 'tools': []}"
|
" 'tools': [],\n",
|
||||||
|
" 'response_format': 'auto',\n",
|
||||||
|
" 'temperature': 1.0,\n",
|
||||||
|
" 'tool_resources': {'code_interpreter': None, 'file_search': None},\n",
|
||||||
|
" 'top_p': 1.0}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -199,7 +225,7 @@
|
|||||||
"assistant = client.beta.assistants.create(\n",
|
"assistant = client.beta.assistants.create(\n",
|
||||||
" name=\"Math Tutor\",\n",
|
" name=\"Math Tutor\",\n",
|
||||||
" instructions=\"You are a personal math tutor. Answer questions briefly, in a sentence or less.\",\n",
|
" instructions=\"You are a personal math tutor. Answer questions briefly, in a sentence or less.\",\n",
|
||||||
" model=\"gpt-4-1106-preview\",\n",
|
" model=\"gpt-4o-mini\",\n",
|
||||||
")\n",
|
")\n",
|
||||||
"show_json(assistant)"
|
"show_json(assistant)"
|
||||||
]
|
]
|
||||||
@ -240,10 +266,11 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'thread_bw42vPoQtYBMQE84WubNcJXG',\n",
|
"{'id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L',\n",
|
||||||
" 'created_at': 1699828331,\n",
|
" 'created_at': 1728757849,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'object': 'thread'}"
|
" 'object': 'thread',\n",
|
||||||
|
" 'tool_resources': {'code_interpreter': None, 'file_search': None}}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -270,18 +297,22 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'msg_IBiZDAWHhWPewxzN0EfTYNew',\n",
|
"{'id': 'msg_D9BDx2WGGAWaL7xtjNmItGTi',\n",
|
||||||
" 'assistant_id': None,\n",
|
" 'assistant_id': None,\n",
|
||||||
|
" 'attachments': [],\n",
|
||||||
|
" 'completed_at': None,\n",
|
||||||
" 'content': [{'text': {'annotations': [],\n",
|
" 'content': [{'text': {'annotations': [],\n",
|
||||||
" 'value': 'I need to solve the equation `3x + 11 = 14`. Can you help me?'},\n",
|
" 'value': 'I need to solve the equation `3x + 11 = 14`. Can you help me?'},\n",
|
||||||
" 'type': 'text'}],\n",
|
" 'type': 'text'}],\n",
|
||||||
" 'created_at': 1699828332,\n",
|
" 'created_at': 1728757850,\n",
|
||||||
" 'file_ids': [],\n",
|
" 'incomplete_at': None,\n",
|
||||||
|
" 'incomplete_details': None,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'object': 'thread.message',\n",
|
" 'object': 'thread.message',\n",
|
||||||
" 'role': 'user',\n",
|
" 'role': 'user',\n",
|
||||||
" 'run_id': None,\n",
|
" 'run_id': None,\n",
|
||||||
" 'thread_id': 'thread_bw42vPoQtYBMQE84WubNcJXG'}"
|
" 'status': None,\n",
|
||||||
|
" 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L'}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -329,24 +360,34 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'run_LA08RjouV3RemQ78UZXuyzv6',\n",
|
"{'id': 'run_HgqxvVoL5lCLQi4NcdfQ17p1',\n",
|
||||||
" 'assistant_id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
" 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
" 'cancelled_at': None,\n",
|
" 'cancelled_at': None,\n",
|
||||||
" 'completed_at': None,\n",
|
" 'completed_at': None,\n",
|
||||||
" 'created_at': 1699828332,\n",
|
" 'created_at': 1728757851,\n",
|
||||||
" 'expires_at': 1699828932,\n",
|
" 'expires_at': 1728758451,\n",
|
||||||
" 'failed_at': None,\n",
|
" 'failed_at': None,\n",
|
||||||
" 'file_ids': [],\n",
|
" 'incomplete_details': None,\n",
|
||||||
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
||||||
" 'last_error': None,\n",
|
" 'last_error': None,\n",
|
||||||
|
" 'max_completion_tokens': None,\n",
|
||||||
|
" 'max_prompt_tokens': None,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'model': 'gpt-4-1106-preview',\n",
|
" 'model': 'gpt-4o-mini',\n",
|
||||||
" 'object': 'thread.run',\n",
|
" 'object': 'thread.run',\n",
|
||||||
|
" 'parallel_tool_calls': True,\n",
|
||||||
" 'required_action': None,\n",
|
" 'required_action': None,\n",
|
||||||
|
" 'response_format': 'auto',\n",
|
||||||
" 'started_at': None,\n",
|
" 'started_at': None,\n",
|
||||||
" 'status': 'queued',\n",
|
" 'status': 'queued',\n",
|
||||||
" 'thread_id': 'thread_bw42vPoQtYBMQE84WubNcJXG',\n",
|
" 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L',\n",
|
||||||
" 'tools': []}"
|
" 'tool_choice': 'auto',\n",
|
||||||
|
" 'tools': [],\n",
|
||||||
|
" 'truncation_strategy': {'type': 'auto', 'last_messages': None},\n",
|
||||||
|
" 'usage': None,\n",
|
||||||
|
" 'temperature': 1.0,\n",
|
||||||
|
" 'top_p': 1.0,\n",
|
||||||
|
" 'tool_resources': {}}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -396,24 +437,34 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'run_LA08RjouV3RemQ78UZXuyzv6',\n",
|
"{'id': 'run_HgqxvVoL5lCLQi4NcdfQ17p1',\n",
|
||||||
" 'assistant_id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
" 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
" 'cancelled_at': None,\n",
|
" 'cancelled_at': None,\n",
|
||||||
" 'completed_at': 1699828333,\n",
|
" 'completed_at': 1728757853,\n",
|
||||||
" 'created_at': 1699828332,\n",
|
" 'created_at': 1728757851,\n",
|
||||||
" 'expires_at': None,\n",
|
" 'expires_at': None,\n",
|
||||||
" 'failed_at': None,\n",
|
" 'failed_at': None,\n",
|
||||||
" 'file_ids': [],\n",
|
" 'incomplete_details': None,\n",
|
||||||
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
||||||
" 'last_error': None,\n",
|
" 'last_error': None,\n",
|
||||||
|
" 'max_completion_tokens': None,\n",
|
||||||
|
" 'max_prompt_tokens': None,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'model': 'gpt-4-1106-preview',\n",
|
" 'model': 'gpt-4o-mini',\n",
|
||||||
" 'object': 'thread.run',\n",
|
" 'object': 'thread.run',\n",
|
||||||
|
" 'parallel_tool_calls': True,\n",
|
||||||
" 'required_action': None,\n",
|
" 'required_action': None,\n",
|
||||||
" 'started_at': 1699828332,\n",
|
" 'response_format': 'auto',\n",
|
||||||
|
" 'started_at': 1728757852,\n",
|
||||||
" 'status': 'completed',\n",
|
" 'status': 'completed',\n",
|
||||||
" 'thread_id': 'thread_bw42vPoQtYBMQE84WubNcJXG',\n",
|
" 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L',\n",
|
||||||
" 'tools': []}"
|
" '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",
|
||||||
|
" 'temperature': 1.0,\n",
|
||||||
|
" 'top_p': 1.0,\n",
|
||||||
|
" 'tool_resources': {}}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -447,33 +498,41 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'data': [{'id': 'msg_S0ZtKIWjyWtbIW9JNUocPdUS',\n",
|
"{'data': [{'id': 'msg_oxudC146DeS6nEx8xAsEIyil',\n",
|
||||||
" 'assistant_id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
" 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
|
" 'attachments': [],\n",
|
||||||
|
" 'completed_at': None,\n",
|
||||||
" 'content': [{'text': {'annotations': [],\n",
|
" 'content': [{'text': {'annotations': [],\n",
|
||||||
" 'value': 'Yes. Subtract 11 from both sides to get `3x = 3`, then divide by 3 to find `x = 1`.'},\n",
|
" 'value': 'Sure! To solve for \\\\( x \\\\), subtract 11 from both sides: \\\\( 3x = 3 \\\\), then divide by 3: \\\\( x = 1 \\\\).'},\n",
|
||||||
" 'type': 'text'}],\n",
|
" 'type': 'text'}],\n",
|
||||||
" 'created_at': 1699828333,\n",
|
" 'created_at': 1728757852,\n",
|
||||||
" 'file_ids': [],\n",
|
" 'incomplete_at': None,\n",
|
||||||
|
" 'incomplete_details': None,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'object': 'thread.message',\n",
|
" 'object': 'thread.message',\n",
|
||||||
" 'role': 'assistant',\n",
|
" 'role': 'assistant',\n",
|
||||||
" 'run_id': 'run_LA08RjouV3RemQ78UZXuyzv6',\n",
|
" 'run_id': 'run_HgqxvVoL5lCLQi4NcdfQ17p1',\n",
|
||||||
" 'thread_id': 'thread_bw42vPoQtYBMQE84WubNcJXG'},\n",
|
" 'status': None,\n",
|
||||||
" {'id': 'msg_IBiZDAWHhWPewxzN0EfTYNew',\n",
|
" 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L'},\n",
|
||||||
|
" {'id': 'msg_D9BDx2WGGAWaL7xtjNmItGTi',\n",
|
||||||
" 'assistant_id': None,\n",
|
" 'assistant_id': None,\n",
|
||||||
|
" 'attachments': [],\n",
|
||||||
|
" 'completed_at': None,\n",
|
||||||
" 'content': [{'text': {'annotations': [],\n",
|
" 'content': [{'text': {'annotations': [],\n",
|
||||||
" 'value': 'I need to solve the equation `3x + 11 = 14`. Can you help me?'},\n",
|
" 'value': 'I need to solve the equation `3x + 11 = 14`. Can you help me?'},\n",
|
||||||
" 'type': 'text'}],\n",
|
" 'type': 'text'}],\n",
|
||||||
" 'created_at': 1699828332,\n",
|
" 'created_at': 1728757850,\n",
|
||||||
" 'file_ids': [],\n",
|
" 'incomplete_at': None,\n",
|
||||||
|
" 'incomplete_details': None,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'object': 'thread.message',\n",
|
" 'object': 'thread.message',\n",
|
||||||
" 'role': 'user',\n",
|
" 'role': 'user',\n",
|
||||||
" 'run_id': None,\n",
|
" 'run_id': None,\n",
|
||||||
" 'thread_id': 'thread_bw42vPoQtYBMQE84WubNcJXG'}],\n",
|
" 'status': None,\n",
|
||||||
|
" 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L'}],\n",
|
||||||
" 'object': 'list',\n",
|
" 'object': 'list',\n",
|
||||||
" 'first_id': 'msg_S0ZtKIWjyWtbIW9JNUocPdUS',\n",
|
" 'first_id': 'msg_oxudC146DeS6nEx8xAsEIyil',\n",
|
||||||
" 'last_id': 'msg_IBiZDAWHhWPewxzN0EfTYNew',\n",
|
" 'last_id': 'msg_D9BDx2WGGAWaL7xtjNmItGTi',\n",
|
||||||
" 'has_more': False}"
|
" 'has_more': False}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -508,21 +567,25 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'data': [{'id': 'msg_9MAeOrGriHcImeQnAzvYyJbs',\n",
|
"{'data': [{'id': 'msg_xggODJjxCZpTcYutKOhlKQTW',\n",
|
||||||
" 'assistant_id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
" 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
|
" 'attachments': [],\n",
|
||||||
|
" 'completed_at': None,\n",
|
||||||
" 'content': [{'text': {'annotations': [],\n",
|
" 'content': [{'text': {'annotations': [],\n",
|
||||||
" 'value': 'Certainly. To solve for x in the equation `3x + 11 = 14`:\\n\\n1. Subtract 11 from both sides: `3x + 11 - 11 = 14 - 11` simplifies to `3x = 3`.\\n2. Divide both sides by 3: `3x / 3 = 3 / 3` simplifies to `x = 1`.\\n\\nSo, the solution is `x = 1`.'},\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",
|
||||||
" 'type': 'text'}],\n",
|
" 'type': 'text'}],\n",
|
||||||
" 'created_at': 1699828335,\n",
|
" 'created_at': 1728757857,\n",
|
||||||
" 'file_ids': [],\n",
|
" 'incomplete_at': None,\n",
|
||||||
|
" 'incomplete_details': None,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'object': 'thread.message',\n",
|
" 'object': 'thread.message',\n",
|
||||||
" 'role': 'assistant',\n",
|
" 'role': 'assistant',\n",
|
||||||
" 'run_id': 'run_IFHfsubkJv7RSUbDZpNVs4PG',\n",
|
" 'run_id': 'run_mAnVCGyFm8Mf9ZM9HVJaIO5c',\n",
|
||||||
" 'thread_id': 'thread_bw42vPoQtYBMQE84WubNcJXG'}],\n",
|
" 'status': None,\n",
|
||||||
|
" 'thread_id': 'thread_bEe2uIcRwlKBruGVUCmEXY2L'}],\n",
|
||||||
" 'object': 'list',\n",
|
" 'object': 'list',\n",
|
||||||
" 'first_id': 'msg_9MAeOrGriHcImeQnAzvYyJbs',\n",
|
" 'first_id': 'msg_xggODJjxCZpTcYutKOhlKQTW',\n",
|
||||||
" 'last_id': 'msg_9MAeOrGriHcImeQnAzvYyJbs',\n",
|
" 'last_id': 'msg_xggODJjxCZpTcYutKOhlKQTW',\n",
|
||||||
" 'has_more': False}"
|
" 'has_more': False}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -653,21 +716,21 @@
|
|||||||
"text": [
|
"text": [
|
||||||
"# Messages\n",
|
"# Messages\n",
|
||||||
"user: I need to solve the equation `3x + 11 = 14`. Can you help me?\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 both sides 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",
|
"\n",
|
||||||
"# Messages\n",
|
"# Messages\n",
|
||||||
"user: Could you explain linear algebra to me?\n",
|
"user: Could you explain linear algebra to me?\n",
|
||||||
"assistant: Linear algebra is the branch of mathematics that deals with vector spaces, linear equations, and matrices, focusing on the properties and operations that can be applied to vectors and linear transformations.\n",
|
"assistant: Linear algebra is the branch of mathematics that deals with vectors, vector spaces, linear transformations, and systems of linear equations.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Messages\n",
|
"# Messages\n",
|
||||||
"user: I don't like math. What can I do?\n",
|
"user: I don't like math. What can I do?\n",
|
||||||
"assistant: Try finding aspects of math that relate to your interests or daily life, and consider a tutor or interactive resources to make learning more enjoyable.\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",
|
||||||
"\n",
|
"\n",
|
||||||
"# Messages\n",
|
"# Messages\n",
|
||||||
"user: I don't like math. What can I do?\n",
|
"user: I don't like math. What can I do?\n",
|
||||||
"assistant: Try finding aspects of math that relate to your interests or daily life, and consider a tutor or interactive resources to make learning more enjoyable.\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",
|
||||||
"user: Thank you!\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, feel free to ask!\n",
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -756,16 +819,19 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
"{'id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
" 'created_at': 1699828331,\n",
|
" 'created_at': 1728757849,\n",
|
||||||
" 'description': None,\n",
|
" 'description': None,\n",
|
||||||
" 'file_ids': [],\n",
|
|
||||||
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'model': 'gpt-4-1106-preview',\n",
|
" 'model': 'gpt-4o-mini',\n",
|
||||||
" 'name': 'Math Tutor',\n",
|
" 'name': 'Math Tutor',\n",
|
||||||
" 'object': 'assistant',\n",
|
" 'object': 'assistant',\n",
|
||||||
" 'tools': [{'type': 'code_interpreter'}]}"
|
" '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": {},
|
"metadata": {},
|
||||||
@ -798,7 +864,8 @@
|
|||||||
"text": [
|
"text": [
|
||||||
"# Messages\n",
|
"# Messages\n",
|
||||||
"user: Generate the first 20 fibbonaci numbers with code.\n",
|
"user: Generate the first 20 fibbonaci numbers with code.\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, and 4181.\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",
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -855,10 +922,9 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'tool_calls': [{'id': 'call_WMNqd63PtX8vZzTwaA6eWpBg',\n",
|
"{'tool_calls': [{'id': 'call_cFUCLTIFePVVPwNTs6BvzjCj',\n",
|
||||||
" 'code_interpreter': {'input': '# Python function to generate the first 20 Fibonacci numbers\\ndef 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\\n# Generate the first 20 Fibonacci numbers\\nfirst_20_fibonacci = fibonacci(20)\\nfirst_20_fibonacci',\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",
|
||||||
" '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",
|
" 'outputs': []},\n",
|
||||||
" 'type': 'logs'}]},\n",
|
|
||||||
" 'type': 'code_interpreter'}],\n",
|
" 'type': 'code_interpreter'}],\n",
|
||||||
" 'type': 'tool_calls'}"
|
" 'type': 'tool_calls'}"
|
||||||
]
|
]
|
||||||
@ -876,7 +942,7 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'message_creation': {'message_id': 'msg_z593lE5bvcD6BngeDFHDxzwm'},\n",
|
"{'message_creation': {'message_id': 'msg_EurIZ6oj8fofsg2JlQaNw0AZ'},\n",
|
||||||
" 'type': 'message_creation'}"
|
" 'type': 'message_creation'}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -938,16 +1004,20 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
"{'id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
" 'created_at': 1699828331,\n",
|
" 'created_at': 1728757849,\n",
|
||||||
" 'description': None,\n",
|
" 'description': None,\n",
|
||||||
" 'file_ids': ['file-MdXcQI8OdPp76wukWI4dpLwW'],\n",
|
|
||||||
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'model': 'gpt-4-1106-preview',\n",
|
" 'model': 'gpt-4o-mini',\n",
|
||||||
" 'name': 'Math Tutor',\n",
|
" 'name': 'Math Tutor',\n",
|
||||||
" 'object': 'assistant',\n",
|
" 'object': 'assistant',\n",
|
||||||
" 'tools': [{'type': 'code_interpreter'}, {'type': 'retrieval'}]}"
|
" 'tools': [{'type': 'code_interpreter'}],\n",
|
||||||
|
" 'response_format': 'auto',\n",
|
||||||
|
" 'temperature': 1.0,\n",
|
||||||
|
" 'tool_resources': {'code_interpreter': {'file_ids': ['file-HpD4hsytxNpuq3LaGnGCOdCR']},\n",
|
||||||
|
" 'file_search': None},\n",
|
||||||
|
" 'top_p': 1.0}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -966,8 +1036,8 @@
|
|||||||
"# Update Assistant\n",
|
"# Update Assistant\n",
|
||||||
"assistant = client.beta.assistants.update(\n",
|
"assistant = client.beta.assistants.update(\n",
|
||||||
" MATH_ASSISTANT_ID,\n",
|
" MATH_ASSISTANT_ID,\n",
|
||||||
" tools=[{\"type\": \"code_interpreter\"}, {\"type\": \"retrieval\"}],\n",
|
" tools=[{\"type\": \"code_interpreter\"}],\n",
|
||||||
" file_ids=[file.id],\n",
|
" tool_resources={\"code_interpreter\": {\"file_ids\": [file.id]}},\n",
|
||||||
")\n",
|
")\n",
|
||||||
"show_json(assistant)"
|
"show_json(assistant)"
|
||||||
]
|
]
|
||||||
@ -983,8 +1053,8 @@
|
|||||||
"text": [
|
"text": [
|
||||||
"# Messages\n",
|
"# Messages\n",
|
||||||
"user: What are some cool math concepts behind this ML paper pdf? Explain in two sentences.\n",
|
"user: What are some cool math concepts behind this ML paper pdf? Explain in two sentences.\n",
|
||||||
"assistant: I am unable to find specific sections referring to \"cool math concepts\" directly in the paper using the available tools. I will now read the beginning of the paper to identify any mathematical concepts that are fundamental to the paper.\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 paper discusses leveraging large language models as a framework for unsupervised multitask learning, where tasks are implicitly defined by the context within sequences of text. It explores the zero-shot learning capabilities of such models by showing that when a language model is trained on a vast dataset, it begins to generalize and perform tasks without explicit supervision, achieving competitive results across various natural language processing tasks using a probabilistic framework based on sequential modeling and conditional probabilities.\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",
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -1182,18 +1252,17 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
"{'id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
" 'created_at': 1699828331,\n",
|
" 'created_at': 1728757849,\n",
|
||||||
" 'description': None,\n",
|
" 'description': None,\n",
|
||||||
" 'file_ids': ['file-MdXcQI8OdPp76wukWI4dpLwW'],\n",
|
|
||||||
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'model': 'gpt-4-1106-preview',\n",
|
" 'model': 'gpt-4o-mini',\n",
|
||||||
" 'name': 'Math Tutor',\n",
|
" 'name': 'Math Tutor',\n",
|
||||||
" 'object': 'assistant',\n",
|
" 'object': 'assistant',\n",
|
||||||
" 'tools': [{'type': 'code_interpreter'},\n",
|
" 'tools': [{'type': 'code_interpreter'},\n",
|
||||||
" {'type': 'retrieval'},\n",
|
|
||||||
" {'function': {'name': 'display_quiz',\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",
|
||||||
" 'parameters': {'type': 'object',\n",
|
" 'parameters': {'type': 'object',\n",
|
||||||
" 'properties': {'title': {'type': 'string'},\n",
|
" 'properties': {'title': {'type': 'string'},\n",
|
||||||
" 'questions': {'type': 'array',\n",
|
" 'questions': {'type': 'array',\n",
|
||||||
@ -1205,8 +1274,13 @@
|
|||||||
" 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n",
|
" 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n",
|
||||||
" 'required': ['question_text']}}},\n",
|
" 'required': ['question_text']}}},\n",
|
||||||
" 'required': ['title', 'questions']},\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",
|
" 'strict': False},\n",
|
||||||
" 'type': 'function'}]}"
|
" 'type': 'function'}],\n",
|
||||||
|
" 'response_format': 'auto',\n",
|
||||||
|
" 'temperature': 1.0,\n",
|
||||||
|
" 'tool_resources': {'code_interpreter': {'file_ids': ['file-HpD4hsytxNpuq3LaGnGCOdCR']},\n",
|
||||||
|
" 'file_search': None},\n",
|
||||||
|
" 'top_p': 1.0}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -1218,7 +1292,6 @@
|
|||||||
" MATH_ASSISTANT_ID,\n",
|
" MATH_ASSISTANT_ID,\n",
|
||||||
" tools=[\n",
|
" tools=[\n",
|
||||||
" {\"type\": \"code_interpreter\"},\n",
|
" {\"type\": \"code_interpreter\"},\n",
|
||||||
" {\"type\": \"retrieval\"},\n",
|
|
||||||
" {\"type\": \"function\", \"function\": function_json},\n",
|
" {\"type\": \"function\", \"function\": function_json},\n",
|
||||||
" ],\n",
|
" ],\n",
|
||||||
")\n",
|
")\n",
|
||||||
@ -1271,30 +1344,35 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'run_98PGE3qGtHoaWaCLoytyRUBf',\n",
|
"{'id': 'run_bGozAWfICx0SbHJgIhk9hEAt',\n",
|
||||||
" 'assistant_id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
" 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
" 'cancelled_at': None,\n",
|
" 'cancelled_at': None,\n",
|
||||||
" 'completed_at': None,\n",
|
" 'completed_at': None,\n",
|
||||||
" 'created_at': 1699828370,\n",
|
" 'created_at': 1728757910,\n",
|
||||||
" 'expires_at': 1699828970,\n",
|
" 'expires_at': 1728758510,\n",
|
||||||
" 'failed_at': None,\n",
|
" 'failed_at': None,\n",
|
||||||
" 'file_ids': ['file-MdXcQI8OdPp76wukWI4dpLwW'],\n",
|
" 'incomplete_details': None,\n",
|
||||||
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
||||||
" 'last_error': None,\n",
|
" 'last_error': None,\n",
|
||||||
|
" 'max_completion_tokens': None,\n",
|
||||||
|
" 'max_prompt_tokens': None,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'model': 'gpt-4-1106-preview',\n",
|
" 'model': 'gpt-4o-mini',\n",
|
||||||
" 'object': 'thread.run',\n",
|
" 'object': 'thread.run',\n",
|
||||||
" 'required_action': {'submit_tool_outputs': {'tool_calls': [{'id': 'call_Zf650sWT1wW4Uwbf5YeDS0VG',\n",
|
" 'parallel_tool_calls': True,\n",
|
||||||
" 'function': {'arguments': '{\\n \"title\": \"Mathematics Quiz\",\\n \"questions\": [\\n {\\n \"question_text\": \"Explain why the square root of a negative number is not a real number.\",\\n \"question_type\": \"FREE_RESPONSE\"\\n },\\n {\\n \"question_text\": \"What is the value of an angle in a regular pentagon?\",\\n \"choices\": [\\n \"72 degrees\",\\n \"90 degrees\",\\n \"108 degrees\",\\n \"120 degrees\"\\n ],\\n \"question_type\": \"MULTIPLE_CHOICE\"\\n }\\n ]\\n}',\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",
|
||||||
" 'name': 'display_quiz'},\n",
|
" 'name': 'display_quiz'},\n",
|
||||||
" 'type': 'function'}]},\n",
|
" 'type': 'function'}]},\n",
|
||||||
" 'type': 'submit_tool_outputs'},\n",
|
" 'type': 'submit_tool_outputs'},\n",
|
||||||
" 'started_at': 1699828370,\n",
|
" 'response_format': 'auto',\n",
|
||||||
|
" 'started_at': 1728757910,\n",
|
||||||
" 'status': 'requires_action',\n",
|
" 'status': 'requires_action',\n",
|
||||||
" 'thread_id': 'thread_bICTESFvWoRdj0O0SzsosLCS',\n",
|
" 'thread_id': 'thread_jdCqIesorZG5UggY6qMbTib2',\n",
|
||||||
|
" 'tool_choice': 'auto',\n",
|
||||||
" 'tools': [{'type': 'code_interpreter'},\n",
|
" 'tools': [{'type': 'code_interpreter'},\n",
|
||||||
" {'type': 'retrieval'},\n",
|
|
||||||
" {'function': {'name': 'display_quiz',\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",
|
||||||
" 'parameters': {'type': 'object',\n",
|
" 'parameters': {'type': 'object',\n",
|
||||||
" 'properties': {'title': {'type': 'string'},\n",
|
" 'properties': {'title': {'type': 'string'},\n",
|
||||||
" 'questions': {'type': 'array',\n",
|
" 'questions': {'type': 'array',\n",
|
||||||
@ -1306,8 +1384,13 @@
|
|||||||
" 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n",
|
" 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n",
|
||||||
" 'required': ['question_text']}}},\n",
|
" 'required': ['question_text']}}},\n",
|
||||||
" 'required': ['title', 'questions']},\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",
|
" 'strict': False},\n",
|
||||||
" 'type': 'function'}]}"
|
" '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": {},
|
"metadata": {},
|
||||||
@ -1344,12 +1427,12 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'title': 'Mathematics Quiz',\n",
|
"{'title': 'Math Quiz',\n",
|
||||||
" 'questions': [{'question_text': 'Explain why the square root of a negative number is not a real number.',\n",
|
" 'questions': [{'question_text': 'What is the area of a triangle with a base of 10 units and a height of 5 units?',\n",
|
||||||
" 'question_type': 'FREE_RESPONSE'},\n",
|
" 'question_type': 'FREE_RESPONSE'},\n",
|
||||||
" {'question_text': 'What is the value of an angle in a regular pentagon?',\n",
|
" {'question_text': 'What is the value of 3 x (2 + 4)?',\n",
|
||||||
" 'choices': ['72 degrees', '90 degrees', '108 degrees', '120 degrees'],\n",
|
" 'question_type': 'MULTIPLE_CHOICE',\n",
|
||||||
" 'question_type': 'MULTIPLE_CHOICE'}]}"
|
" 'choices': ['A) 12', 'B) 15', 'C) 21', 'D) 18']}]}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 27,
|
"execution_count": 27,
|
||||||
@ -1384,15 +1467,15 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"Quiz: Mathematics Quiz\n",
|
"Quiz: Math Quiz\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Explain why the square root of a negative number is not a real number.\n",
|
"What is the area of a triangle with a base of 10 units and a height of 5 units?\n",
|
||||||
"\n",
|
"\n",
|
||||||
"What is the value of an angle in a regular pentagon?\n",
|
"What is the value of 3 x (2 + 4)?\n",
|
||||||
"0. 72 degrees\n",
|
"0. A) 12\n",
|
||||||
"1. 90 degrees\n",
|
"1. B) 15\n",
|
||||||
"2. 108 degrees\n",
|
"2. C) 21\n",
|
||||||
"3. 120 degrees\n",
|
"3. D) 18\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Responses: [\"I don't know.\", 'a']\n"
|
"Responses: [\"I don't know.\", 'a']\n"
|
||||||
]
|
]
|
||||||
@ -1416,30 +1499,70 @@
|
|||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 29,
|
"execution_count": 29,
|
||||||
"metadata": {},
|
"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,
|
||||||
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"{'id': 'run_98PGE3qGtHoaWaCLoytyRUBf',\n",
|
"{'id': 'run_bGozAWfICx0SbHJgIhk9hEAt',\n",
|
||||||
" 'assistant_id': 'asst_9HAjl9y41ufsViNcThW1EXUS',\n",
|
" 'assistant_id': 'asst_Eam8s30EfVSynLjRXoUSqHPs',\n",
|
||||||
" 'cancelled_at': None,\n",
|
" 'cancelled_at': None,\n",
|
||||||
" 'completed_at': None,\n",
|
" 'completed_at': None,\n",
|
||||||
" 'created_at': 1699828370,\n",
|
" 'created_at': 1728757910,\n",
|
||||||
" 'expires_at': 1699828970,\n",
|
" 'expires_at': 1728758510,\n",
|
||||||
" 'failed_at': None,\n",
|
" 'failed_at': None,\n",
|
||||||
" 'file_ids': ['file-MdXcQI8OdPp76wukWI4dpLwW'],\n",
|
" 'incomplete_details': None,\n",
|
||||||
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
" 'instructions': 'You are a personal math tutor. Answer questions briefly, in a sentence or less.',\n",
|
||||||
" 'last_error': None,\n",
|
" 'last_error': None,\n",
|
||||||
|
" 'max_completion_tokens': None,\n",
|
||||||
|
" 'max_prompt_tokens': None,\n",
|
||||||
" 'metadata': {},\n",
|
" 'metadata': {},\n",
|
||||||
" 'model': 'gpt-4-1106-preview',\n",
|
" 'model': 'gpt-4o-mini',\n",
|
||||||
" 'object': 'thread.run',\n",
|
" 'object': 'thread.run',\n",
|
||||||
|
" 'parallel_tool_calls': True,\n",
|
||||||
" 'required_action': None,\n",
|
" 'required_action': None,\n",
|
||||||
" 'started_at': 1699828370,\n",
|
" 'response_format': 'auto',\n",
|
||||||
|
" 'started_at': 1728757910,\n",
|
||||||
" 'status': 'queued',\n",
|
" 'status': 'queued',\n",
|
||||||
" 'thread_id': 'thread_bICTESFvWoRdj0O0SzsosLCS',\n",
|
" 'thread_id': 'thread_jdCqIesorZG5UggY6qMbTib2',\n",
|
||||||
|
" 'tool_choice': 'auto',\n",
|
||||||
" 'tools': [{'type': 'code_interpreter'},\n",
|
" 'tools': [{'type': 'code_interpreter'},\n",
|
||||||
" {'type': 'retrieval'},\n",
|
|
||||||
" {'function': {'name': 'display_quiz',\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",
|
||||||
" 'parameters': {'type': 'object',\n",
|
" 'parameters': {'type': 'object',\n",
|
||||||
" 'properties': {'title': {'type': 'string'},\n",
|
" 'properties': {'title': {'type': 'string'},\n",
|
||||||
" 'questions': {'type': 'array',\n",
|
" 'questions': {'type': 'array',\n",
|
||||||
@ -1451,8 +1574,13 @@
|
|||||||
" 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n",
|
" 'choices': {'type': 'array', 'items': {'type': 'string'}}},\n",
|
||||||
" 'required': ['question_text']}}},\n",
|
" 'required': ['question_text']}}},\n",
|
||||||
" 'required': ['title', 'questions']},\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",
|
" 'strict': False},\n",
|
||||||
" 'type': 'function'}]}"
|
" '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": {},
|
"metadata": {},
|
||||||
@ -1463,12 +1591,7 @@
|
|||||||
"run = client.beta.threads.runs.submit_tool_outputs(\n",
|
"run = client.beta.threads.runs.submit_tool_outputs(\n",
|
||||||
" thread_id=thread.id,\n",
|
" thread_id=thread.id,\n",
|
||||||
" run_id=run.id,\n",
|
" run_id=run.id,\n",
|
||||||
" tool_outputs=[\n",
|
" tool_outputs=tool_outputs\n",
|
||||||
" {\n",
|
|
||||||
" \"tool_call_id\": tool_call.id,\n",
|
|
||||||
" \"output\": json.dumps(responses),\n",
|
|
||||||
" }\n",
|
|
||||||
" ],\n",
|
|
||||||
")\n",
|
")\n",
|
||||||
"show_json(run)"
|
"show_json(run)"
|
||||||
]
|
]
|
||||||
@ -1482,7 +1605,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 30,
|
"execution_count": 31,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -1491,11 +1614,16 @@
|
|||||||
"text": [
|
"text": [
|
||||||
"# Messages\n",
|
"# Messages\n",
|
||||||
"user: Make a quiz with 2 questions: One open ended, one multiple choice. Then, give me feedback for the responses.\n",
|
"user: Make a quiz with 2 questions: One open ended, one multiple choice. Then, give me feedback for the responses.\n",
|
||||||
"assistant: Thank you for attempting the quiz.\n",
|
"assistant: Your responses are:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"For the first question, it's important to know that the square root of a negative number is not a real number because real numbers consist of all the numbers on the number line, and that includes all positive numbers, zero, and negative numbers. However, the square root of a negative number is not on this number line; instead, it is what we call an imaginary number. When we want to take the square root of a negative number, we typically use the imaginary unit \\(i\\), where \\(i\\) is defined as \\(\\sqrt{-1}\\).\n",
|
"1. Open-ended question: \"I don't know.\" \n",
|
||||||
|
"2. Multiple choice: \"a\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"For the second question, the correct answer is \"108 degrees.\" In a regular pentagon, which is a five-sided polygon with equal sides and angles, each interior angle is \\(108\\) degrees. This is because the sum of the interior angles of a pentagon is \\(540\\) degrees, and when divided by \\(5\\) (the number of angles), it gives \\(108\\) degrees per angle. The choice you selected, \"72 degrees,\" actually refers to the external angle of a regular pentagon, not the internal angle.\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",
|
||||||
|
"\n",
|
||||||
|
"Keep practicing! Would you like to try another quiz?\n",
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -1548,7 +1676,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.9.13"
|
"version": "3.9.19"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user