From 38fe5eb2a7783099df0eeeaded518b1934ca66db Mon Sep 17 00:00:00 2001 From: Meor Amer <92068895+mrmer1@users.noreply.github.com> Date: Thu, 26 Sep 2024 22:55:25 +0800 Subject: [PATCH] update v2 notebooks (#220) --- .../getting-started/v2/tutorial_pt4_v2.ipynb | 24 +- .../getting-started/v2/tutorial_pt6_v2.ipynb | 219 +++++++++++------- .../getting-started/v2/tutorial_pt7_v2.ipynb | 36 ++- 3 files changed, 168 insertions(+), 111 deletions(-) diff --git a/notebooks/guides/getting-started/v2/tutorial_pt4_v2.ipynb b/notebooks/guides/getting-started/v2/tutorial_pt4_v2.ipynb index fea618309..cef605560 100644 --- a/notebooks/guides/getting-started/v2/tutorial_pt4_v2.ipynb +++ b/notebooks/guides/getting-started/v2/tutorial_pt4_v2.ipynb @@ -85,7 +85,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -140,7 +140,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -177,7 +177,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -185,12 +185,12 @@ "output_type": "stream", "text": [ "Rank: 1\n", - "Score: 0.442758615743984\n", - "Document: {'text': \"Finding Coffee Spots: For your caffeine fix, head to the break room's coffee machine or cross the street to the café for artisan coffee.\"}\n", + "Score: 0.3872984617627964\n", + "Document: {'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'}\n", "\n", "Rank: 2\n", - "Score: 0.32783563708365726\n", - "Document: {'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'}\n", + "Score: 0.3272549670724577\n", + "Document: {'text': 'Proposing New Ideas: Innovation is welcomed! Share your brilliant ideas at our weekly team meetings or directly with your team lead.'}\n", "\n" ] } @@ -234,7 +234,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -314,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -345,7 +345,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -377,7 +377,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -436,7 +436,7 @@ "kernelspec": { "display_name": "base", "language": "python", - "name": "base" + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/notebooks/guides/getting-started/v2/tutorial_pt6_v2.ipynb b/notebooks/guides/getting-started/v2/tutorial_pt6_v2.ipynb index f81855332..2ebc1921c 100644 --- a/notebooks/guides/getting-started/v2/tutorial_pt6_v2.ipynb +++ b/notebooks/guides/getting-started/v2/tutorial_pt6_v2.ipynb @@ -82,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -124,9 +124,21 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Yes, there are health benefits. We offer gym memberships, on-site yoga classes, and comprehensive health insurance.\n", + "\n", + "CITATIONS:\n", + "start=41 end=115 text='gym memberships, on-site yoga classes, and comprehensive health insurance.' sources=[DocumentSource(type='document', id='doc:2', document={'id': 'doc:2', 'text': 'Health and Wellness Benefits: We care about your well-being and offer gym memberships, on-site yoga classes, and comprehensive health insurance.'})] \n", + "\n" + ] + } + ], "source": [ "# Add the user query\n", "query = \"Are there health benefits?\"\n", @@ -169,53 +181,59 @@ "\n", "There are different possible approaches to this. In this example, we'll take a [tool use](v2/docs/tool-use) approach.\n", "\n", - "Here, we build a tool that takes a user query and returns a list of relevant document snippets for that query. The tool can generate zero, one or multiple search queries depending on the user query.\n", - "\n", - "We'll not do a detailed walkthrough of tool use here as we'll do that in the next tutorial, which is a dedicated tutorial on tool use.\n", - "\n", - "We recommend using the v1 API for this functionality in order to leverage the `force_single_step` feature, as follows:" + "Here, we build a tool that takes a user query and returns a list of relevant document snippets for that query. The tool can generate zero, one or multiple search queries depending on the user query." ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ - "co_v1 = cohere.Client(api_key=\"COHERE_API_KEY\") # Get your free API key: https://dashboard.cohere.com/api-keys\n", - "\n", "def generate_search_queries(message: str) -> List[str]:\n", " \n", " # Define the query generation tool\n", " query_gen_tool = [\n", - " {\n", - " \"name\": \"internet_search\",\n", - " \"description\": \"Returns a list of relevant document snippets for a textual query retrieved from the internet\",\n", - " \"parameter_definitions\": {\n", - " \"queries\": {\n", - " \"description\": \"a list of queries to search the internet with.\",\n", - " \"type\": \"List[str]\",\n", - " \"required\": True\n", - " }\n", + " {\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"internet_search\",\n", + " \"description\": \"Returns a list of relevant document snippets for a textual query retrieved from the internet\",\n", + " \"parameters\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"queries\": {\n", + " \"type\": \"array\",\n", + " \"items\": {\"type\": \"string\"},\n", + " \"description\": \"a list of queries to search the internet with.\",\n", + " }\n", + " },\n", + " \"required\": [\"queries\"],\n", + " },\n", + " },\n", " }\n", - " }]\n", + " ]\n", + "\n", "\n", " # Define a preamble to optimize search query generation\n", " instructions = \"Write a search query that will find helpful information for answering the user's question accurately. If you need more than one search query, write a list of search queries. If you decide that a search is very unlikely to find information that would be useful in constructing a response to the user, you should instead directly answer.\"\n", "\n", " # Generate search queries (if any)\n", " search_queries = []\n", - "\n", - " response = co_v1.chat(\n", - " preamble=instructions,\n", + " \n", + " res = co.chat(\n", " model=\"command-r-08-2024\",\n", - " message=message,\n", - " force_single_step=True,\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": instructions},\n", + " {\"role\": \"user\", \"content\": message},\n", + " ],\n", " tools=query_gen_tool\n", " )\n", - "\n", - " if response.tool_calls:\n", - " search_queries = response.tool_calls[0].parameters[\"queries\"]\n", + " \n", + " if res.message.tool_calls:\n", + " for tc in res.message.tool_calls:\n", + " queries = json.loads(tc.function.arguments)[\"queries\"]\n", + " search_queries.extend(queries)\n", "\n", " return search_queries" ] @@ -229,14 +247,14 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['how to stay connected with the company', 'does the company organize team events']\n" + "['how to stay connected with the company', 'do companies organise team events']\n" ] } ], @@ -255,14 +273,14 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['how flexible are the working hours at the company']\n" + "['How flexible are the working hours?']\n" ] } ], @@ -281,7 +299,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -324,29 +342,69 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "# Define the documents\n", "faqs_long = [\n", - " {\"text\": \"Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.\"},\n", - " {\"text\": \"Finding Coffee Spots: For your caffeine fix, head to the break room's coffee machine or cross the street to the café for artisan coffee.\"},\n", - " {\"text\": \"Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!\"},\n", - " {\"text\": \"Working Hours Flexibility: We prioritize work-life balance. While our core hours are 9 AM to 5 PM, we offer flexibility to adjust as needed.\"},\n", - " {\"text\": \"Side Projects Policy: We encourage you to pursue your passions. Just be mindful of any potential conflicts of interest with our business.\"},\n", - " {\"text\": \"Reimbursing Travel Expenses: Easily manage your travel expenses by submitting them through our finance tool. Approvals are prompt and straightforward.\"},\n", - " {\"text\": \"Working from Abroad: Working remotely from another country is possible. Simply coordinate with your manager and ensure your availability during core hours.\"},\n", - " {\"text\": \"Health and Wellness Benefits: We care about your well-being and offer gym memberships, on-site yoga classes, and comprehensive health insurance.\"},\n", - " {\"text\": \"Performance Reviews Frequency: We conduct informal check-ins every quarter and formal performance reviews twice a year.\"},\n", - " {\"text\": \"Proposing New Ideas: Innovation is welcomed! Share your brilliant ideas at our weekly team meetings or directly with your team lead.\"},\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Finding Coffee Spots: For your caffeine fix, head to the break room's coffee machine or cross the street to the café for artisan coffee.\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Working Hours Flexibility: We prioritize work-life balance. While our core hours are 9 AM to 5 PM, we offer flexibility to adjust as needed.\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Side Projects Policy: We encourage you to pursue your passions. Just be mindful of any potential conflicts of interest with our business.\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Reimbursing Travel Expenses: Easily manage your travel expenses by submitting them through our finance tool. Approvals are prompt and straightforward.\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Working from Abroad: Working remotely from another country is possible. Simply coordinate with your manager and ensure your availability during core hours.\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Health and Wellness Benefits: We care about your well-being and offer gym memberships, on-site yoga classes, and comprehensive health insurance.\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Performance Reviews Frequency: We conduct informal check-ins every quarter and formal performance reviews twice a year.\"\n", + " }\n", + " },\n", + " {\n", + " \"data\": {\n", + " \"text\": \"Proposing New Ideas: Innovation is welcomed! Share your brilliant ideas at our weekly team meetings or directly with your team lead.\"\n", + " }\n", + " },\n", "]\n", "\n", "# Embed the documents\n", "doc_emb = co.embed(\n", " model=\"embed-english-v3.0\",\n", " input_type=\"search_document\",\n", - " texts=[doc['text'] for doc in faqs_long],\n", + " texts=[doc['data']['text'] for doc in faqs_long],\n", " embedding_types=[\"float\"]).embeddings.float" ] }, @@ -361,14 +419,14 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Search query: how to get to know teammates\n" + "Search query: how to get to know your teammates\n" ] } ], @@ -402,7 +460,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -410,24 +468,24 @@ "output_type": "stream", "text": [ "Rank: 1\n", - "Score: 0.34212792245283796\n", - "Document: {'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'}\n", + "Score: 0.32653470360872655\n", + "Document: {'data': {'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'}}\n", "\n", "Rank: 2\n", - "Score: 0.2883222063024371\n", - "Document: {'text': 'Proposing New Ideas: Innovation is welcomed! Share your brilliant ideas at our weekly team meetings or directly with your team lead.'}\n", + "Score: 0.26851855352264786\n", + "Document: {'data': {'text': 'Proposing New Ideas: Innovation is welcomed! Share your brilliant ideas at our weekly team meetings or directly with your team lead.'}}\n", "\n", "Rank: 3\n", - "Score: 0.278128283997032\n", - "Document: {'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'}\n", + "Score: 0.2581341975304149\n", + "Document: {'data': {'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'}}\n", "\n", "Rank: 4\n", - "Score: 0.19474858706643985\n", - "Document: {'text': \"Finding Coffee Spots: For your caffeine fix, head to the break room's coffee machine or cross the street to the café for artisan coffee.\"}\n", + "Score: 0.18633336738178463\n", + "Document: {'data': {'text': \"Finding Coffee Spots: For your caffeine fix, head to the break room's coffee machine or cross the street to the café for artisan coffee.\"}}\n", "\n", "Rank: 5\n", - "Score: 0.13713692506528824\n", - "Document: {'text': 'Side Projects Policy: We encourage you to pursue your passions. Just be mindful of any potential conflicts of interest with our business.'}\n", + "Score: 0.13022396595682814\n", + "Document: {'data': {'text': 'Health and Wellness Benefits: We care about your well-being and offer gym memberships, on-site yoga classes, and comprehensive health insurance.'}}\n", "\n" ] } @@ -443,7 +501,7 @@ "for rank, idx in enumerate(max_idx):\n", " print(f\"Rank: {rank+1}\")\n", " print(f\"Score: {scores[idx]}\")\n", - " print(f\"Document: {retrieved_documents[rank]}\\n\")\n" + " print(f\"Document: {retrieved_documents[rank]}\\n\")" ] }, { @@ -466,7 +524,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -474,12 +532,12 @@ "output_type": "stream", "text": [ "Rank: 1\n", - "Score: 0.0020507434\n", - "Document: {'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'}\n", + "Score: 0.0040072887\n", + "Document: {'data': {'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'}}\n", "\n", "Rank: 2\n", - "Score: 0.0014158706\n", - "Document: {'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'}\n", + "Score: 0.0020829707\n", + "Document: {'data': {'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'}}\n", "\n" ] } @@ -487,7 +545,7 @@ "source": [ "# Rerank the documents\n", "results = co.rerank(query=queries_for_search,\n", - " documents=retrieved_documents,\n", + " documents=[doc['data']['text'] for doc in retrieved_documents],\n", " top_n=2,\n", " model='rerank-english-v3.0')\n", "\n", @@ -521,23 +579,31 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "You can get to know your teammates by joining your company's Slack channels and taking part in team-building activities. You will receive an invite to join relevant Slack channels via email. Your company also organises monthly outings and weekly game nights to foster team spirit.\n", + "You can get to know your teammates by joining Slack channels and participating in team-building activities. You will receive an invite via email to join relevant channels to stay informed and engaged. There are monthly outings and weekly game nights to foster team spirit. You can suggest new activity ideas at any time.\n", "\n", "CITATIONS:\n", - "start=38 end=75 text=\"joining your company's Slack channels\" sources=[Source_Document(id='doc:0:0', document={'id': 'doc:0:0', 'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'}, type='document')] \n", + "start=38 end=60 text='joining Slack channels' sources=[DocumentSource(type='document', id='doc:0', document={'id': 'doc:0', 'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'})] \n", + "\n", + "start=82 end=107 text='team-building activities.' sources=[DocumentSource(type='document', id='doc:1', document={'id': 'doc:1', 'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'})] \n", + "\n", + "start=117 end=144 text='receive an invite via email' sources=[DocumentSource(type='document', id='doc:0', document={'id': 'doc:0', 'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'})] \n", "\n", - "start=95 end=120 text='team-building activities.' sources=[Source_Document(id='doc:0:1', document={'id': 'doc:0:1', 'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'}, type='document')] \n", + "start=148 end=170 text='join relevant channels' sources=[DocumentSource(type='document', id='doc:0', document={'id': 'doc:0', 'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'})] \n", "\n", - "start=130 end=190 text='receive an invite to join relevant Slack channels via email.' sources=[Source_Document(id='doc:0:0', document={'id': 'doc:0:0', 'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'}, type='document')] \n", + "start=174 end=200 text='stay informed and engaged.' sources=[DocumentSource(type='document', id='doc:0', document={'id': 'doc:0', 'text': 'Joining Slack Channels: You will receive an invite via email. Be sure to join relevant channels to stay informed and engaged.'})] \n", "\n", - "start=219 end=280 text='monthly outings and weekly game nights to foster team spirit.' sources=[Source_Document(id='doc:0:1', document={'id': 'doc:0:1', 'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'}, type='document')] \n", + "start=211 end=249 text='monthly outings and weekly game nights' sources=[DocumentSource(type='document', id='doc:1', document={'id': 'doc:1', 'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'})] \n", + "\n", + "start=253 end=272 text='foster team spirit.' sources=[DocumentSource(type='document', id='doc:1', document={'id': 'doc:1', 'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'})] \n", + "\n", + "start=281 end=320 text='suggest new activity ideas at any time.' sources=[DocumentSource(type='document', id='doc:1', document={'id': 'doc:1', 'text': 'Team-Building Activities: We foster team spirit with monthly outings and weekly game nights. Feel free to suggest new activity ideas anytime!'})] \n", "\n" ] } @@ -557,20 +623,13 @@ " for citation in response.message.citations:\n", " print(citation, \"\\n\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", - "name": "base" + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb b/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb index aa7779c97..24245c249 100644 --- a/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb +++ b/notebooks/guides/getting-started/v2/tutorial_pt7_v2.ipynb @@ -225,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -233,7 +233,7 @@ "output_type": "stream", "text": [ "Tool plan:\n", - "I will search the user's emails for any messages about getting set up with IT. \n", + "I will search for messages about getting set up with IT. \n", "\n", "Tool calls:\n", "Tool name: search_emails | Parameters: {\"query\":\"IT setup\"}\n" @@ -289,7 +289,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -308,7 +308,7 @@ " tool_result = functions_map[tc.function.name](**json.loads(tc.function.arguments))\n", " tool_content.append(json.dumps(tool_result))\n", " # Append tool results to the chat history\n", - " messages.append({\"role\": \"tool\", \"tool_call_id\": tc.id, \"tool_content\": tool_content}) \n", + " messages.append({\"role\": \"tool\", \"tool_call_id\": tc.id, \"content\": tool_content}) \n", "\n", "print(\"Tool results:\") \n", "for result in tool_content:\n", @@ -324,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -332,13 +332,13 @@ "output_type": "stream", "text": [ "Response:\n", - "Yes, there is an email from IT with a comprehensive guide attached.\n", + "Yes, there is an email from IT@co1t.com with the subject line 'Setting Up Your IT Needs'. It contains a comprehensive guide to help you set up all your work accounts.\n", "==================================================\n", "\n", "CITATIONS:\n", - "start=17 end=30 text='email from IT' sources=[Source_Tool(type='tool', id='search_emails_dy73yjrx50xq:0', tool_output={'emails': '[{\"date\":\"2024-06-24\",\"from\":\"it@co1t.com\",\"subject\":\"Setting Up Your IT Needs\",\"text\":\"Greetings! To ensure a seamless start, please refer to the attached comprehensive guide, which will assist you in setting up all your work accounts.\",\"to\":\"david@co1t.com\"},{\"date\":\"2024-06-24\",\"from\":\"john@co1t.com\",\"subject\":\"First Week Check-In\",\"text\":\"Hello! I hope you\\'re settling in well. Let\\'s connect briefly tomorrow to discuss how your first week has been going. Also, make sure to join us for a welcoming lunch this Thursday at noon—it\\'s a great opportunity to get to know your colleagues!\",\"to\":\"david@co1t.com\"}]'})] \n", + "start=17 end=88 text=\"email from IT@co1t.com with the subject line 'Setting Up Your IT Needs'\" sources=[ToolSource(type='tool', id='search_emails_my672h5p91sx:0', tool_output={'emails': '[{\"date\":\"2024-06-24\",\"from\":\"it@co1t.com\",\"subject\":\"Setting Up Your IT Needs\",\"text\":\"Greetings! To ensure a seamless start, please refer to the attached comprehensive guide, which will assist you in setting up all your work accounts.\",\"to\":\"david@co1t.com\"},{\"date\":\"2024-06-24\",\"from\":\"john@co1t.com\",\"subject\":\"First Week Check-In\",\"text\":\"Hello! I hope you\\'re settling in well. Let\\'s connect briefly tomorrow to discuss how your first week has been going. Also, make sure to join us for a welcoming lunch this Thursday at noon—it\\'s a great opportunity to get to know your colleagues!\",\"to\":\"david@co1t.com\"}]'})] \n", "\n", - "start=38 end=66 text='comprehensive guide attached' sources=[Source_Tool(type='tool', id='search_emails_dy73yjrx50xq:0', tool_output={'emails': '[{\"date\":\"2024-06-24\",\"from\":\"it@co1t.com\",\"subject\":\"Setting Up Your IT Needs\",\"text\":\"Greetings! To ensure a seamless start, please refer to the attached comprehensive guide, which will assist you in setting up all your work accounts.\",\"to\":\"david@co1t.com\"},{\"date\":\"2024-06-24\",\"from\":\"john@co1t.com\",\"subject\":\"First Week Check-In\",\"text\":\"Hello! I hope you\\'re settling in well. Let\\'s connect briefly tomorrow to discuss how your first week has been going. Also, make sure to join us for a welcoming lunch this Thursday at noon—it\\'s a great opportunity to get to know your colleagues!\",\"to\":\"david@co1t.com\"}]'})] \n", + "start=104 end=166 text='comprehensive guide to help you set up all your work accounts.' sources=[ToolSource(type='tool', id='search_emails_my672h5p91sx:0', tool_output={'emails': '[{\"date\":\"2024-06-24\",\"from\":\"it@co1t.com\",\"subject\":\"Setting Up Your IT Needs\",\"text\":\"Greetings! To ensure a seamless start, please refer to the attached comprehensive guide, which will assist you in setting up all your work accounts.\",\"to\":\"david@co1t.com\"},{\"date\":\"2024-06-24\",\"from\":\"john@co1t.com\",\"subject\":\"First Week Check-In\",\"text\":\"Hello! I hope you\\'re settling in well. Let\\'s connect briefly tomorrow to discuss how your first week has been going. Also, make sure to join us for a welcoming lunch this Thursday at noon—it\\'s a great opportunity to get to know your colleagues!\",\"to\":\"david@co1t.com\"}]'})] \n", "\n" ] } @@ -384,7 +384,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -429,7 +429,7 @@ " for idx, tc in enumerate(response.message.tool_calls):\n", " tool_result = functions_map[tc.function.name](**json.loads(tc.function.arguments))\n", " tool_content.append(json.dumps(tool_result))\n", - " messages.append({\"role\": \"tool\", \"tool_call_id\": tc.id, \"tool_content\": tool_content})\n", + " messages.append({\"role\": \"tool\", \"tool_call_id\": tc.id, \"content\": tool_content})\n", " \n", " # Step 4: Generate response and citations \n", " response = co.chat(\n", @@ -480,27 +480,25 @@ "Can you check if there are any lunch invites, and for those days, create a one-hour event on my calendar at 12PM.\n", "==================================================\n", "Tool plan:\n", - "I will search the user's emails for lunch invites and then create a calendar event for each day they are invited to lunch. \n", + "I will search the user's emails for lunch invites. Then, I will create a one-hour event on the user's calendar at 12PM for each day that has a lunch invite. \n", "\n", "Tool calls:\n", - "Tool name: search_emails | Parameters: {\"query\":\"lunch invite\"}\n", + "Tool name: search_emails | Parameters: {\"query\":\"lunch invites\"}\n", "==================================================\n", "Tool plan:\n", - "I have found an email inviting the user to a welcoming lunch on Thursday at noon. I will now create a calendar event for this. \n", + "I have found one email that mentions a lunch invite on Thursday at noon. I will now create a one-hour event on the user's calendar for Thursday at noon. \n", "\n", "Tool calls:\n", "Tool name: create_calendar_event | Parameters: {\"date\":\"06/27/24\",\"duration\":1,\"time\":\"12:00\"}\n", "==================================================\n", "Response:\n", - "Sure, I found an email from John inviting you to a welcoming lunch this Thursday at noon. I've created a one-hour event on your calendar for this Thursday at 12 pm.\n", + "I found an email from John inviting you to a welcoming lunch this Thursday at noon. I have created a one-hour event on your calendar for this Thursday at 12pm.\n", "==================================================\n", "\n", "CITATIONS:\n", - "start=17 end=32 text='email from John' sources=[Source_Tool(type='tool', id='search_emails_j72zv2xhq0sj:0', tool_output={'emails': '[{\"date\":\"2024-06-24\",\"from\":\"it@co1t.com\",\"subject\":\"Setting Up Your IT Needs\",\"text\":\"Greetings! To ensure a seamless start, please refer to the attached comprehensive guide, which will assist you in setting up all your work accounts.\",\"to\":\"david@co1t.com\"},{\"date\":\"2024-06-24\",\"from\":\"john@co1t.com\",\"subject\":\"First Week Check-In\",\"text\":\"Hello! I hope you\\'re settling in well. Let\\'s connect briefly tomorrow to discuss how your first week has been going. Also, make sure to join us for a welcoming lunch this Thursday at noon—it\\'s a great opportunity to get to know your colleagues!\",\"to\":\"david@co1t.com\"}]'})] \n", - "\n", - "start=51 end=88 text='welcoming lunch this Thursday at noon' sources=[Source_Tool(type='tool', id='search_emails_j72zv2xhq0sj:0', tool_output={'emails': '[{\"date\":\"2024-06-24\",\"from\":\"it@co1t.com\",\"subject\":\"Setting Up Your IT Needs\",\"text\":\"Greetings! To ensure a seamless start, please refer to the attached comprehensive guide, which will assist you in setting up all your work accounts.\",\"to\":\"david@co1t.com\"},{\"date\":\"2024-06-24\",\"from\":\"john@co1t.com\",\"subject\":\"First Week Check-In\",\"text\":\"Hello! I hope you\\'re settling in well. Let\\'s connect briefly tomorrow to discuss how your first week has been going. Also, make sure to join us for a welcoming lunch this Thursday at noon—it\\'s a great opportunity to get to know your colleagues!\",\"to\":\"david@co1t.com\"}]'})] \n", + "start=22 end=26 text='John' sources=[ToolSource(type='tool', id='search_emails_zbmsja6x6za4:0', tool_output={'emails': '[{\"date\":\"2024-06-24\",\"from\":\"it@co1t.com\",\"subject\":\"Setting Up Your IT Needs\",\"text\":\"Greetings! To ensure a seamless start, please refer to the attached comprehensive guide, which will assist you in setting up all your work accounts.\",\"to\":\"david@co1t.com\"},{\"date\":\"2024-06-24\",\"from\":\"john@co1t.com\",\"subject\":\"First Week Check-In\",\"text\":\"Hello! I hope you\\'re settling in well. Let\\'s connect briefly tomorrow to discuss how your first week has been going. Also, make sure to join us for a welcoming lunch this Thursday at noon—it\\'s a great opportunity to get to know your colleagues!\",\"to\":\"david@co1t.com\"}]'})] \n", "\n", - "start=105 end=163 text='one-hour event on your calendar for this Thursday at 12 pm' sources=[Source_Tool(type='tool', id='create_calendar_event_vs7mxjzk9jzs:0', tool_output={'is_success': 'true', 'message': 'Created a 1 hour long event at 12:00 on 06/27/24'})] \n", + "start=45 end=83 text='welcoming lunch this Thursday at noon.' sources=[ToolSource(type='tool', id='search_emails_zbmsja6x6za4:0', tool_output={'emails': '[{\"date\":\"2024-06-24\",\"from\":\"it@co1t.com\",\"subject\":\"Setting Up Your IT Needs\",\"text\":\"Greetings! To ensure a seamless start, please refer to the attached comprehensive guide, which will assist you in setting up all your work accounts.\",\"to\":\"david@co1t.com\"},{\"date\":\"2024-06-24\",\"from\":\"john@co1t.com\",\"subject\":\"First Week Check-In\",\"text\":\"Hello! I hope you\\'re settling in well. Let\\'s connect briefly tomorrow to discuss how your first week has been going. Also, make sure to join us for a welcoming lunch this Thursday at noon—it\\'s a great opportunity to get to know your colleagues!\",\"to\":\"david@co1t.com\"}]'})] \n", "\n" ] } @@ -534,7 +532,7 @@ "kernelspec": { "display_name": "base", "language": "python", - "name": "base" + "name": "python3" }, "language_info": { "codemirror_mode": {