# embeddings_queue

created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: f1a3e740-788a-4061-8abe-b6d9d3e14758
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb", "title": "Creating slides with the Assistants API (GPT-4), and DALL\u00b7E-3", "tokens": 6653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"f1a3e740-788a-4061-8abe-b6d9d3e14758\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"11dab93a-3b10-4ad4-b4fb-41b810ebfc2a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"590e51a96173634ecd748515644cc72146bf4bf8fd4a0e2662f25556548bcf92\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"70a8af37-22ed-4d1d-b036-3cda523a5171\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"832f654edf9487092cb70ea0ebe71084135f18f95a4076afbc0abffddf613123\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"33a9388c-e27e-4d30-bb17-42d34d6f9292\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4769ad0bf72700876901892898b89b631621c11f5a486f78ea3c0b107eb14b6b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 13430, \"end_char_idx\": 15845, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "ref_doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "chroma:document": "Run(id='run_NWoygMcBfHUr58fCE4Cn6rxN', assistant_id='asst_3T362kLlTyAq0FUnkvjjQczO', cancelled_at=None, completed_at=None, created_at=1701827074, expires_at=1701827674, failed_at=None, file_ids=['file-piTokyHGllwGITzIpoG8dok3'], instructions='You are a data scientist assistant. When given data and a query, write the proper code and create the proper visualization', last_error=None, metadata={}, model='gpt-4-1106-preview', object='thread.run', required_action=None, started_at=None, status='queued', thread_id='thread_73TgtFoJMlEJvb13ngjTnAo3', tools=[ToolAssistantToolsCode(type='code_interpreter')])\n\n\n\nNow, once the run has completed, we can see the latest message\n\n\n```python\n# Hard coded wait for a response, as the assistant may iterate on the bullets.\ntime.sleep(10)\nresponse = get_response(thread)\nbullet_points = response.data[0].content[0].text.value\nprint(bullet_points)\n\n```\n\n    The plot reveals a consistent upward trend in profits for all distribution channels, indicating successful business growth over time. Particularly, 'Online Sales' shows a notable increase, underscoring the importance of digital presence in revenue generation.\n\n\nCool! So our assistant was able to identify the noteworthy growth in Online Sales profit, and infer that this shows the importance of a large digital presence. Now let's get a compelling title for the slide.\n\n\n```python\nsubmit_message(assistant.id,thread,\"Given the plot and bullet points you created,\\\n come up with a very brief title for a slide. It should reflect just the main insights you came up with.\"\n)\n\n```\n\n\n\n\n    Run(id='run_q6E85J31jCw3QkHpjJKl969P', assistant_id='asst_3T362kLlTyAq0FUnkvjjQczO', cancelled_at=None, completed_at=None, created_at=1701827084, expires_at=1701827684, failed_at=None, file_ids=['file-piTokyHGllwGITzIpoG8dok3'], instructions='You are a data scientist assistant. When given data and a query, write the proper code and create the proper visualization', last_error=None, metadata={}, model='gpt-4-1106-preview', object='thread.run', required_action=None, started_at=None, status='queued', thread_id='thread_73TgtFoJMlEJvb13ngjTnAo3', tools=[ToolAssistantToolsCode(type='code_interpreter')])\n\n\n\nAnd the title is:\n\n\n```python\n#Wait as assistant may take a few steps\ntime.sleep(10)\nresponse = get_response(thread)\ntitle = response.data[0].content[0].text.value\nprint(title)\n\n```\n\n    \"Ascending Profits & Digital Dominance\""}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 33a9388c-e27e-4d30-bb17-42d34d6f9292
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb", "title": "Creating slides with the Assistants API (GPT-4), and DALL\u00b7E-3", "tokens": 6653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"33a9388c-e27e-4d30-bb17-42d34d6f9292\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"11dab93a-3b10-4ad4-b4fb-41b810ebfc2a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"590e51a96173634ecd748515644cc72146bf4bf8fd4a0e2662f25556548bcf92\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"f1a3e740-788a-4061-8abe-b6d9d3e14758\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"23377ed3da4766b93aef19d4f4422036fe5d4949b73d9ed36bea5f25c967256c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"8aaaea1f-8d2b-45af-9998-f807ba3452a9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6f7729e185b9d62b0e981a2601987f65bf066ff52bcfa69457f5e85981364b90\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14587, \"end_char_idx\": 17019, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "ref_doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "chroma:document": "Cool! So our assistant was able to identify the noteworthy growth in Online Sales profit, and infer that this shows the importance of a large digital presence. Now let's get a compelling title for the slide.\n\n\n```python\nsubmit_message(assistant.id,thread,\"Given the plot and bullet points you created,\\\n come up with a very brief title for a slide. It should reflect just the main insights you came up with.\"\n)\n\n```\n\n\n\n\n    Run(id='run_q6E85J31jCw3QkHpjJKl969P', assistant_id='asst_3T362kLlTyAq0FUnkvjjQczO', cancelled_at=None, completed_at=None, created_at=1701827084, expires_at=1701827684, failed_at=None, file_ids=['file-piTokyHGllwGITzIpoG8dok3'], instructions='You are a data scientist assistant. When given data and a query, write the proper code and create the proper visualization', last_error=None, metadata={}, model='gpt-4-1106-preview', object='thread.run', required_action=None, started_at=None, status='queued', thread_id='thread_73TgtFoJMlEJvb13ngjTnAo3', tools=[ToolAssistantToolsCode(type='code_interpreter')])\n\n\n\nAnd the title is:\n\n\n```python\n#Wait as assistant may take a few steps\ntime.sleep(10)\nresponse = get_response(thread)\ntitle = response.data[0].content[0].text.value\nprint(title)\n\n```\n\n    \"Ascending Profits & Digital Dominance\"\n\n\n## 3. DALL\u00b7E-3 title image\n\nNice, now we have a title, a plot and two bullet points. We're almost ready to put this all on a slide, but as a final step, let's have DALL\u00b7E-3 come up with an image to use as the title slide of the presentation. <br><br>\n*Note:* DALL\u00b7E-3 is not yet available within the assistants API but is coming soon! <br> <br>\nWe'll feed in a brief description of our company (NotRealCorp) and have DALL\u00b7E-3 do the rest!\n\n\n```python\ncompany_summary = \"NotReal Corp is a prominent hardware company that manufactures and sells processors, graphics cards and other essential computer hardware.\"\n\n```\n\n\n```python\nresponse = client.images.generate(\n  model='dall-e-3',\n  prompt=f\"given this company summary {company_summary}, create an inspirational \\\n    photo showing the growth and path forward. This will be used at a quarterly\\\n       financial planning meeting\",\n       size=\"1024x1024\",\n       quality=\"hd\",\n       n=1\n)\nimage_url = response.data[0].url\n\n```\n\nCool, now we can add this image to our thread. First, we can save the image locally, then upload it to the assistants API using the `File` upload endpoint. Let's also take a look at our image"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 8aaaea1f-8d2b-45af-9998-f807ba3452a9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb", "title": "Creating slides with the Assistants API (GPT-4), and DALL\u00b7E-3", "tokens": 6653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"8aaaea1f-8d2b-45af-9998-f807ba3452a9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"11dab93a-3b10-4ad4-b4fb-41b810ebfc2a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"590e51a96173634ecd748515644cc72146bf4bf8fd4a0e2662f25556548bcf92\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"33a9388c-e27e-4d30-bb17-42d34d6f9292\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"660025750de8f19b7ca9826a63e1361fd158e0cec530ff8a6d7aafb5af5244fb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a6963e04-1e2f-428b-b72e-bdd2a0e4da9c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"21c0304c6d099e443e96345e27ecebf86bebffd2d958f36d533694665a42645e\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 15619, \"end_char_idx\": 17717, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "ref_doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "chroma:document": "And the title is:\n\n\n```python\n#Wait as assistant may take a few steps\ntime.sleep(10)\nresponse = get_response(thread)\ntitle = response.data[0].content[0].text.value\nprint(title)\n\n```\n\n    \"Ascending Profits & Digital Dominance\"\n\n\n## 3. DALL\u00b7E-3 title image\n\nNice, now we have a title, a plot and two bullet points. We're almost ready to put this all on a slide, but as a final step, let's have DALL\u00b7E-3 come up with an image to use as the title slide of the presentation. <br><br>\n*Note:* DALL\u00b7E-3 is not yet available within the assistants API but is coming soon! <br> <br>\nWe'll feed in a brief description of our company (NotRealCorp) and have DALL\u00b7E-3 do the rest!\n\n\n```python\ncompany_summary = \"NotReal Corp is a prominent hardware company that manufactures and sells processors, graphics cards and other essential computer hardware.\"\n\n```\n\n\n```python\nresponse = client.images.generate(\n  model='dall-e-3',\n  prompt=f\"given this company summary {company_summary}, create an inspirational \\\n    photo showing the growth and path forward. This will be used at a quarterly\\\n       financial planning meeting\",\n       size=\"1024x1024\",\n       quality=\"hd\",\n       n=1\n)\nimage_url = response.data[0].url\n\n```\n\nCool, now we can add this image to our thread. First, we can save the image locally, then upload it to the assistants API using the `File` upload endpoint. Let's also take a look at our image\n\n\n```python\ndalle_img_path = '../images/dalle_image.png'\nimg = requests.get(image_url)\n\n#Save locally\nwith open(dalle_img_path,'wb') as file:\n  file.write(img.content)\n\n#Upload\ndalle_file = client.files.create(\n  file=open(dalle_img_path, \"rb\"),\n  purpose='assistants'\n)\n\n```\n\n  \n![Image](../images/dalle_image.png)\n\n## 4. Creating the slides\n\nWe now have all the content we need to create the slides. While we could simply add a message asking for slides, but let's instead give the assistant a slide template, using the `python-pptx` library, to use. This will ensure we get a deck in the style we want. See the `Extensions` section at the end of the notebook for notes on creating the template."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: a6963e04-1e2f-428b-b72e-bdd2a0e4da9c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb", "title": "Creating slides with the Assistants API (GPT-4), and DALL\u00b7E-3", "tokens": 6653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a6963e04-1e2f-428b-b72e-bdd2a0e4da9c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"11dab93a-3b10-4ad4-b4fb-41b810ebfc2a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"590e51a96173634ecd748515644cc72146bf4bf8fd4a0e2662f25556548bcf92\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"8aaaea1f-8d2b-45af-9998-f807ba3452a9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ce9d93ad8eee5dd563b45e090e9c37a3fa9c11e189052c2e42f851a445112bd0\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"446a52e9-a355-4cd9-91ca-d87a753331bc\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"956100c8f45f61d59b2d42244df8344c45e359bfb9280f963d9cf0e50a19ab5d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 16289, \"end_char_idx\": 20270, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "ref_doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "chroma:document": "```python\ncompany_summary = \"NotReal Corp is a prominent hardware company that manufactures and sells processors, graphics cards and other essential computer hardware.\"\n\n```\n\n\n```python\nresponse = client.images.generate(\n  model='dall-e-3',\n  prompt=f\"given this company summary {company_summary}, create an inspirational \\\n    photo showing the growth and path forward. This will be used at a quarterly\\\n       financial planning meeting\",\n       size=\"1024x1024\",\n       quality=\"hd\",\n       n=1\n)\nimage_url = response.data[0].url\n\n```\n\nCool, now we can add this image to our thread. First, we can save the image locally, then upload it to the assistants API using the `File` upload endpoint. Let's also take a look at our image\n\n\n```python\ndalle_img_path = '../images/dalle_image.png'\nimg = requests.get(image_url)\n\n#Save locally\nwith open(dalle_img_path,'wb') as file:\n  file.write(img.content)\n\n#Upload\ndalle_file = client.files.create(\n  file=open(dalle_img_path, \"rb\"),\n  purpose='assistants'\n)\n\n```\n\n  \n![Image](../images/dalle_image.png)\n\n## 4. Creating the slides\n\nWe now have all the content we need to create the slides. While we could simply add a message asking for slides, but let's instead give the assistant a slide template, using the `python-pptx` library, to use. This will ensure we get a deck in the style we want. See the `Extensions` section at the end of the notebook for notes on creating the template.\n\n\n```python\ntitle_template = \"\"\"\nfrom pptx import Presentation\nfrom pptx.util import Inches, Pt\nfrom pptx.enum.text import PP_PARAGRAPH_ALIGNMENT\nfrom pptx.dml.color import RGBColor\n\n# Create a new presentation object\nprs = Presentation()\n\n# Add a blank slide layout\nblank_slide_layout = prs.slide_layouts[6]\nslide = prs.slides.add_slide(blank_slide_layout)\n\n# Set the background color of the slide to black\nbackground = slide.background\nfill = background.fill\nfill.solid()\nfill.fore_color.rgb = RGBColor(0, 0, 0)\n\n# Add image to the left side of the slide with a margin at the top and bottom\nleft = Inches(0)\ntop = Inches(0)\nheight = prs.slide_height\nwidth = prs.slide_width * 3/5\npic = slide.shapes.add_picture(image_path, left, top, width=width, height=height)\n\n# Add title text box positioned higher\nleft = prs.slide_width * 3/5\ntop = Inches(2)\nwidth = prs.slide_width * 2/5\nheight = Inches(1)\ntitle_box = slide.shapes.add_textbox(left, top, width, height)\ntitle_frame = title_box.text_frame\ntitle_p = title_frame.add_paragraph()\ntitle_p.text = title_text\ntitle_p.font.bold = True\ntitle_p.font.size = Pt(38)\ntitle_p.font.color.rgb = RGBColor(255, 255, 255)\ntitle_p.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER\n\n# Add subtitle text box\nleft = prs.slide_width * 3/5\ntop = Inches(3)\nwidth = prs.slide_width * 2/5\nheight = Inches(1)\nsubtitle_box = slide.shapes.add_textbox(left, top, width, height)\nsubtitle_frame = subtitle_box.text_frame\nsubtitle_p = subtitle_frame.add_paragraph()\nsubtitle_p.text = subtitle_text\nsubtitle_p.font.size = Pt(22)\nsubtitle_p.font.color.rgb = RGBColor(255, 255, 255)\nsubtitle_p.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER\n\"\"\"\n\ndata_vis_template = \"\"\"\nfrom pptx import Presentation\nfrom pptx.util import Inches, Pt\nfrom pptx.enum.text import PP_PARAGRAPH_ALIGNMENT\nfrom pptx.dml.color import RGBColor\n\n# Create a new presentation object\nprs = Presentation()\n\n# Add a blank slide layout\nblank_slide_layout = prs.slide_layouts[6]\nslide = prs.slides.add_slide(blank_slide_layout)\n\n# Set the background color of the slide to black\nbackground = slide.background\nfill = background.fill\nfill.solid()\nfill.fore_color.rgb = RGBColor(0, 0, 0)\n\n# Define placeholders\nimage_path = data_vis_img\ntitle_text = \"Maximizing Profits: The Dominance of Online Sales & Direct Sales Optimization\"\nbullet_points = \"\u2022 Online Sales consistently lead in profitability across quarters, indicating a strong digital market presence.\\n\u2022 Direct Sales show fluctuations, suggesting variable performance and the need for targeted improvements in that channel.\""}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 446a52e9-a355-4cd9-91ca-d87a753331bc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb", "title": "Creating slides with the Assistants API (GPT-4), and DALL\u00b7E-3", "tokens": 6653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"446a52e9-a355-4cd9-91ca-d87a753331bc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"11dab93a-3b10-4ad4-b4fb-41b810ebfc2a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"590e51a96173634ecd748515644cc72146bf4bf8fd4a0e2662f25556548bcf92\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a6963e04-1e2f-428b-b72e-bdd2a0e4da9c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f74bd1f33b13e07a5f82b71d8ac5436c9ddbab15a10616754e34b726bb4ee794\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"aefbba7f-aa02-4996-82d6-8cc52ad6a0b9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"33e5be768a8b09e71b7cce7ae25c6abea4bf3f41cddd1308089a14fe9fb8b228\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 20272, \"end_char_idx\": 22329, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "ref_doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "chroma:document": "# Add image placeholder on the left side of the slide\nleft = Inches(0.2)\ntop = Inches(1.8)\nheight = prs.slide_height - Inches(3)\nwidth = prs.slide_width * 3/5\npic = slide.shapes.add_picture(image_path, left, top, width=width, height=height)\n\n# Add title text spanning the whole width\nleft = Inches(0)\ntop = Inches(0)\nwidth = prs.slide_width\nheight = Inches(1)\ntitle_box = slide.shapes.add_textbox(left, top, width, height)\ntitle_frame = title_box.text_frame\ntitle_frame.margin_top = Inches(0.1)\ntitle_p = title_frame.add_paragraph()\ntitle_p.text = title_text\ntitle_p.font.bold = True\ntitle_p.font.size = Pt(28)\ntitle_p.font.color.rgb = RGBColor(255, 255, 255)\ntitle_p.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER\n\n# Add hardcoded \"Key Insights\" text and bullet points\nleft = prs.slide_width * 2/3\ntop = Inches(1.5)\nwidth = prs.slide_width * 1/3\nheight = Inches(4.5)\ninsights_box = slide.shapes.add_textbox(left, top, width, height)\ninsights_frame = insights_box.text_frame\ninsights_p = insights_frame.add_paragraph()\ninsights_p.text = \"Key Insights:\"\ninsights_p.font.bold = True\ninsights_p.font.size = Pt(24)\ninsights_p.font.color.rgb = RGBColor(0, 128, 100)\ninsights_p.alignment = PP_PARAGRAPH_ALIGNMENT.LEFT\ninsights_frame.add_paragraph()\n\n\nbullet_p = insights_frame.add_paragraph()\nbullet_p.text = bullet_points\nbullet_p.font.size = Pt(12)\nbullet_p.font.color.rgb = RGBColor(255, 255, 255)\nbullet_p.line_spacing = 1.5\n\"\"\"\n\n\n```\n\nLet's set a few quick variables for our slides. We want the company name, NotRealCorp, to be on the title slide, and the title of the presentation should 'Quartlerly financial planning metting, Q3, 2023'.\n\n\n```python\ntitle_text = \"NotRealCorp\"\nsubtitle_text = \"Quarterly financial planning meeting, Q3 2023\"\n\n```\n\nAnd for the data slide, we have:\n\nHere we have a template to create a Title Slide. The template below was created by uploading the image of a desirable title slide to GPT-V, and asking for the `python-pptx` code to create that template. The inputs to the template are the image_path, title_text, and subtitle_text."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: aefbba7f-aa02-4996-82d6-8cc52ad6a0b9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb", "title": "Creating slides with the Assistants API (GPT-4), and DALL\u00b7E-3", "tokens": 6653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"aefbba7f-aa02-4996-82d6-8cc52ad6a0b9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"11dab93a-3b10-4ad4-b4fb-41b810ebfc2a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"590e51a96173634ecd748515644cc72146bf4bf8fd4a0e2662f25556548bcf92\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"446a52e9-a355-4cd9-91ca-d87a753331bc\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0614c49bc46776f141b4309ab0f7f9d4e9f6e764fe70f1ee7f0c49a2357efbe1\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"85a99d1b-35c2-476a-8e75-58b7aa4877da\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"850db94a535cc563d1caea6eb85a52c9ae547276cafae2bc591feb4a23604d92\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 21512, \"end_char_idx\": 24199, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "ref_doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "chroma:document": "bullet_p = insights_frame.add_paragraph()\nbullet_p.text = bullet_points\nbullet_p.font.size = Pt(12)\nbullet_p.font.color.rgb = RGBColor(255, 255, 255)\nbullet_p.line_spacing = 1.5\n\"\"\"\n\n\n```\n\nLet's set a few quick variables for our slides. We want the company name, NotRealCorp, to be on the title slide, and the title of the presentation should 'Quartlerly financial planning metting, Q3, 2023'.\n\n\n```python\ntitle_text = \"NotRealCorp\"\nsubtitle_text = \"Quarterly financial planning meeting, Q3 2023\"\n\n```\n\nAnd for the data slide, we have:\n\nHere we have a template to create a Title Slide. The template below was created by uploading the image of a desirable title slide to GPT-V, and asking for the `python-pptx` code to create that template. The inputs to the template are the image_path, title_text, and subtitle_text.\n\n\n```python\nsubmit_message(assistant.id,thread,f\"Use the included code template to create a PPTX slide that follows the template format, but uses the image, company name/title, and document name/subtitle included:\\\n{title_template}. IMPORTANT: Use the image file included in this message as the image_path image in this first slide, and use the Company Name {title_text} as the title_text variable, and \\\n  use the subtitle_text {subtitle_text} a the subtitle_text variable. \\\n    NEST, create a SECOND slide using the following code template: {data_vis_template} to create a PPTX slide that follows the template format, but uses the company name/title, and document name/subtitle included:\\\n{data_vis_template}. IMPORTANT: Use the line plot image, that is the second attached image in this message, that you created earlier in the thread as the data_vis_img image, and use the data visualization title that you created earlier for the variable title_text, and\\\n  the bullet points of insights you created earlier for the bullet_points variable. Output these TWO SLIDES as a .pptx file. Make sure the output is two slides, with each slide matching the respective template given in this message.\",\n              file_ids=[dalle_file.id, plot_file.id]\n)\n\n```\n\n\n\n\n    Run(id='run_taLrnOnlDhoywgQFFBOLPlg0', assistant_id='asst_3T362kLlTyAq0FUnkvjjQczO', cancelled_at=None, completed_at=None, created_at=1701827118, expires_at=1701827718, failed_at=None, file_ids=['file-piTokyHGllwGITzIpoG8dok3'], instructions='You are a data scientist assistant. When given data and a query, write the proper code and create the proper visualization', last_error=None, metadata={}, model='gpt-4-1106-preview', object='thread.run', required_action=None, started_at=None, status='queued', thread_id='thread_73TgtFoJMlEJvb13ngjTnAo3', tools=[ToolAssistantToolsCode(type='code_interpreter')])"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 85a99d1b-35c2-476a-8e75-58b7aa4877da
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb", "title": "Creating slides with the Assistants API (GPT-4), and DALL\u00b7E-3", "tokens": 6653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"85a99d1b-35c2-476a-8e75-58b7aa4877da\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"11dab93a-3b10-4ad4-b4fb-41b810ebfc2a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"590e51a96173634ecd748515644cc72146bf4bf8fd4a0e2662f25556548bcf92\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"aefbba7f-aa02-4996-82d6-8cc52ad6a0b9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7a7f47faac68414196a108ae7b469dc601bc60a903a4effe65293bf23ff1619f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"5df85321-3c77-4d61-a989-d54b43b7ab5d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5a91b78a47272940ded8a24762703d1bc3cdaf3128f16e6d1b92846cd3219b40\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 23595, \"end_char_idx\": 25013, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "ref_doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "chroma:document": "Run(id='run_taLrnOnlDhoywgQFFBOLPlg0', assistant_id='asst_3T362kLlTyAq0FUnkvjjQczO', cancelled_at=None, completed_at=None, created_at=1701827118, expires_at=1701827718, failed_at=None, file_ids=['file-piTokyHGllwGITzIpoG8dok3'], instructions='You are a data scientist assistant. When given data and a query, write the proper code and create the proper visualization', last_error=None, metadata={}, model='gpt-4-1106-preview', object='thread.run', required_action=None, started_at=None, status='queued', thread_id='thread_73TgtFoJMlEJvb13ngjTnAo3', tools=[ToolAssistantToolsCode(type='code_interpreter')])\n\n\n\n\n```python\n#May take 1-3 mins\nwhile True:\n    try:\n        response = get_response(thread)\n        pptx_id = response.data[0].content[0].text.annotations[0].file_path.file_id\n        print(\"Successfully retrieved pptx_id:\", pptx_id)\n        break\n    except Exception as e:\n        print(\"Assistant still working on PPTX...\")\n        time.sleep(10)\n\n```\n\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Successfully retrieved pptx_id: file-oa0i63qPH4IaJXYj90aA6L4Q"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 5df85321-3c77-4d61-a989-d54b43b7ab5d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb", "title": "Creating slides with the Assistants API (GPT-4), and DALL\u00b7E-3", "tokens": 6653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"5df85321-3c77-4d61-a989-d54b43b7ab5d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"11dab93a-3b10-4ad4-b4fb-41b810ebfc2a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"590e51a96173634ecd748515644cc72146bf4bf8fd4a0e2662f25556548bcf92\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"85a99d1b-35c2-476a-8e75-58b7aa4877da\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Creating_slides_with_Assistants_API_and_DALL-E3.ipynb\", \"title\": \"Creating slides with the Assistants API (GPT-4), and DALL\\u00b7E-3\", \"tokens\": 6653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"9b260b22349184103a9b6885c6004466952680a22253162f3a9b987adb28e42c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 23595, \"end_char_idx\": 27158, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "ref_doc_id": "11dab93a-3b10-4ad4-b4fb-41b810ebfc2a", "chroma:document": "Run(id='run_taLrnOnlDhoywgQFFBOLPlg0', assistant_id='asst_3T362kLlTyAq0FUnkvjjQczO', cancelled_at=None, completed_at=None, created_at=1701827118, expires_at=1701827718, failed_at=None, file_ids=['file-piTokyHGllwGITzIpoG8dok3'], instructions='You are a data scientist assistant. When given data and a query, write the proper code and create the proper visualization', last_error=None, metadata={}, model='gpt-4-1106-preview', object='thread.run', required_action=None, started_at=None, status='queued', thread_id='thread_73TgtFoJMlEJvb13ngjTnAo3', tools=[ToolAssistantToolsCode(type='code_interpreter')])\n\n\n\n\n```python\n#May take 1-3 mins\nwhile True:\n    try:\n        response = get_response(thread)\n        pptx_id = response.data[0].content[0].text.annotations[0].file_path.file_id\n        print(\"Successfully retrieved pptx_id:\", pptx_id)\n        break\n    except Exception as e:\n        print(\"Assistant still working on PPTX...\")\n        time.sleep(10)\n\n```\n\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Assistant still working on PPTX...\n    Successfully retrieved pptx_id: file-oa0i63qPH4IaJXYj90aA6L4Q\n\n\n\n```python\npptx_id = response.data[0].content[0].text.annotations[0].file_path.file_id\nppt_file= client.files.content(pptx_id)\nfile_obj = io.BytesIO(ppt_file.read())\nwith open(\"data/created_slides.pptx\", \"wb\") as f:\n    f.write(file_obj.getbuffer())\n\n```\n\nNow, we have a PPTX file saved with all of our created content!. <br>\n\nLet's look at the screenshots of the .pptx we just created using JUST the assistants API and DALL\u00b7E-3. We don't have a `seed` parameter yet in the Assistants API, so the DALL\u00b7E-3 image and wordings will be slightly different from what you see when you run this notebook, due to the non-determinism of LLMs, but the outputs should be directionally the same.\n\nThe title slide:\n\n![Title Slide](../images/title_slide.png)\n\nAnd the data slide:\n\n![Data Slide](../images/data_vis_slide.png)\n\n## 5. Conclusion\n\nWoo! While these slides could use some formatting tweaks, we have made some great content using the Assistants API, GPT-4 and DALL\u00b7E-3. We were able to take a `.csv` file with financial data, and use our assisant to calculate profit by quarter across distribution channels, plot the results, identify insights and key takeaways from the visualization, and create a summarative title. And, given just a description of our company, NotRealCorp, we used DALL\u00b7E-3 to make an awesome title image. <br><br>\nWhile we are still a ways away from entirely automating this process without a human in the loop, hopefully this notebook can make the slide creation process a bit easier for you. More importantly, this notebook can ideally give you a glimpse into the potential of the assistants API! We're excited to see what you build.\n\n## 6. Extensions\n\n- When  DALL\u00b7E-3 is incorporated in the Assistants API, we will have the ability to request the generated title image within the thread. \n- GPT-4-Vision is not yet supported in the Assistants API, but could have been used to gather insights from the line plot image.\n- GPT-4-Vision was used to generate the `python-pptx` template included in this recipe, so a potential extension project could be demonstrating best practices around converting images to slide templates."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6b5d93cb-0ecc-4ce0-ab6c-0c4e0c41706d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Regression_using_embeddings.ipynb", "title": "## Regression using the embeddings", "tokens": 516, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6b5d93cb-0ecc-4ce0-ab6c-0c4e0c41706d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Regression_using_embeddings.ipynb\", \"title\": \"## Regression using the embeddings\", \"tokens\": 516, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bf6cb950-e75e-47f2-a131-07e8f79fde01\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Regression_using_embeddings.ipynb\", \"title\": \"## Regression using the embeddings\", \"tokens\": 516, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d79db1616d2b5f52d1193de835e36aefed460c394bcfe79b2f631acc36b64a3d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2149, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bf6cb950-e75e-47f2-a131-07e8f79fde01", "doc_id": "bf6cb950-e75e-47f2-a131-07e8f79fde01", "ref_doc_id": "bf6cb950-e75e-47f2-a131-07e8f79fde01", "chroma:document": "## Regression using the embeddings\n\nRegression means predicting a number, rather than one of the categories. We will predict the score based on the embedding of the review's text. We split the dataset into a training and a testing set for all of the following tasks, so we can realistically evaluate performance on unseen data. The dataset is created in the [Get_embeddings_from_dataset Notebook](Get_embeddings_from_dataset.ipynb).\n\nWe're predicting the score of the review, which is a number between 1 and 5 (1-star being negative and 5-star positive).\n\n\n```python\nimport pandas as pd\nimport numpy as np\nfrom ast import literal_eval\n\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error, mean_absolute_error\n\ndatafile_path = \"data/fine_food_reviews_with_embeddings_1k.csv\"\n\ndf = pd.read_csv(datafile_path)\ndf[\"embedding\"] = df.embedding.apply(literal_eval).apply(np.array)\n\nX_train, X_test, y_train, y_test = train_test_split(list(df.embedding.values), df.Score, test_size=0.2, random_state=42)\n\nrfr = RandomForestRegressor(n_estimators=100)\nrfr.fit(X_train, y_train)\npreds = rfr.predict(X_test)\n\nmse = mean_squared_error(y_test, preds)\nmae = mean_absolute_error(y_test, preds)\n\nprint(f\"text-embedding-3-small performance on 1k Amazon reviews: mse={mse:.2f}, mae={mae:.2f}\")\n\n```\n\n    text-embedding-3-small performance on 1k Amazon reviews: mse=0.65, mae=0.52\n\n\n\n```python\nbmse = mean_squared_error(y_test, np.repeat(y_test.mean(), len(y_test)))\nbmae = mean_absolute_error(y_test, np.repeat(y_test.mean(), len(y_test)))\nprint(\n    f\"Dummy mean prediction performance on Amazon reviews: mse={bmse:.2f}, mae={bmae:.2f}\"\n)\n\n```\n\n    Dummy mean prediction performance on Amazon reviews: mse=1.73, mae=1.03\n\n\nWe can see that the embeddings are able to predict the scores with an average error of 0.53 per score prediction. This is roughly equivalent to predicting half of reviews perfectly, and half off by one star.\n\nYou could also train a classifier to predict the label, or use the embeddings within an existing ML model to encode free text features."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 3c92c0bc-e931-47fb-ad61-8a0472a82009
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb", "title": "imports", "tokens": 1743, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3c92c0bc-e931-47fb-ad61-8a0472a82009\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"89b0fbc6-8468-4f59-8fc0-46c772ded6cc\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"33b195d3788ce86941015464446578b737d50abff856f45799d369fc2fbb2fc5\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"172c763c-64ea-4d47-ae93-6e2ac574a64b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"03fb1940436df738a8f139da96c038dc6f81eb449ec55a302639d3a3185f189c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2827, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "doc_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "ref_doc_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "chroma:document": "## K-means Clustering in Python using OpenAI\n\nWe use a simple k-means algorithm to demonstrate how clustering can be done. Clustering can help discover valuable, hidden groupings within the data. The dataset is created in the [Get_embeddings_from_dataset Notebook](Get_embeddings_from_dataset.ipynb).\n\n\n```python\n# imports\nimport numpy as np\nimport pandas as pd\nfrom ast import literal_eval\n\n# load data\ndatafile_path = \"./data/fine_food_reviews_with_embeddings_1k.csv\"\n\ndf = pd.read_csv(datafile_path)\ndf[\"embedding\"] = df.embedding.apply(literal_eval).apply(np.array)  # convert string to numpy array\nmatrix = np.vstack(df.embedding.values)\nmatrix.shape\n\n```\n\n\n\n\n    (1000, 1536)\n\n\n\n### 1. Find the clusters using K-means\n\nWe show the simplest use of K-means. You can pick the number of clusters that fits your use case best.\n\n\n```python\nfrom sklearn.cluster import KMeans\n\nn_clusters = 4\n\nkmeans = KMeans(n_clusters=n_clusters, init=\"k-means++\", random_state=42)\nkmeans.fit(matrix)\nlabels = kmeans.labels_\ndf[\"Cluster\"] = labels\n\ndf.groupby(\"Cluster\").Score.mean().sort_values()\n\n```\n\n    /opt/homebrew/lib/python3.11/site-packages/sklearn/cluster/_kmeans.py:870: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning\n      warnings.warn(\n\n\n\n\n\n    Cluster\n    0    4.105691\n    1    4.191176\n    2    4.215613\n    3    4.306590\n    Name: Score, dtype: float64\n\n\n\n\n```python\nfrom sklearn.manifold import TSNE\nimport matplotlib\nimport matplotlib.pyplot as plt\n\ntsne = TSNE(n_components=2, perplexity=15, random_state=42, init=\"random\", learning_rate=200)\nvis_dims2 = tsne.fit_transform(matrix)\n\nx = [x for x, y in vis_dims2]\ny = [y for x, y in vis_dims2]\n\nfor category, color in enumerate([\"purple\", \"green\", \"red\", \"blue\"]):\n    xs = np.array(x)[df.Cluster == category]\n    ys = np.array(y)[df.Cluster == category]\n    plt.scatter(xs, ys, color=color, alpha=0.3)\n\n    avg_x = xs.mean()\n    avg_y = ys.mean()\n\n    plt.scatter(avg_x, avg_y, marker=\"x\", color=color, s=100)\nplt.title(\"Clusters identified visualized in language 2d using t-SNE\")\n\n```\n\n\n\n\n    Text(0.5, 1.0, 'Clusters identified visualized in language 2d using t-SNE')\n\n\n\n\n    \n![png](output_5_1.png)\n    \n\n\nVisualization of clusters in a 2d projection. In this run, the green cluster (#1) seems quite different from the others. Let's see a few samples from each cluster.\n\n### 2. Text samples in the clusters & naming the clusters\n\nLet's show random samples from each cluster. We'll use gpt-4 to name the clusters, based on a random sample of 5 reviews from that cluster.\n\n\n```python\nfrom openai import OpenAI\nimport os\n\nclient = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as env var>\"))\n\n# Reading a review which belong to each group."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 172c763c-64ea-4d47-ae93-6e2ac574a64b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb", "title": "imports", "tokens": 1743, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"172c763c-64ea-4d47-ae93-6e2ac574a64b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"89b0fbc6-8468-4f59-8fc0-46c772ded6cc\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"33b195d3788ce86941015464446578b737d50abff856f45799d369fc2fbb2fc5\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"3c92c0bc-e931-47fb-ad61-8a0472a82009\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"dec495bb3b7e969cb232bab30cca2948d77e9c2e1b41e550d66106923724c451\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"069ed1dd-6412-4fd1-a2c4-d8cb3becbade\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5f08c6bb964ef6c9a71ceec12c69883a0cfce436f93a4f1ff40eb874a991322c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1457, \"end_char_idx\": 4327, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "doc_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "ref_doc_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "chroma:document": "```python\nfrom sklearn.manifold import TSNE\nimport matplotlib\nimport matplotlib.pyplot as plt\n\ntsne = TSNE(n_components=2, perplexity=15, random_state=42, init=\"random\", learning_rate=200)\nvis_dims2 = tsne.fit_transform(matrix)\n\nx = [x for x, y in vis_dims2]\ny = [y for x, y in vis_dims2]\n\nfor category, color in enumerate([\"purple\", \"green\", \"red\", \"blue\"]):\n    xs = np.array(x)[df.Cluster == category]\n    ys = np.array(y)[df.Cluster == category]\n    plt.scatter(xs, ys, color=color, alpha=0.3)\n\n    avg_x = xs.mean()\n    avg_y = ys.mean()\n\n    plt.scatter(avg_x, avg_y, marker=\"x\", color=color, s=100)\nplt.title(\"Clusters identified visualized in language 2d using t-SNE\")\n\n```\n\n\n\n\n    Text(0.5, 1.0, 'Clusters identified visualized in language 2d using t-SNE')\n\n\n\n\n    \n![png](output_5_1.png)\n    \n\n\nVisualization of clusters in a 2d projection. In this run, the green cluster (#1) seems quite different from the others. Let's see a few samples from each cluster.\n\n### 2. Text samples in the clusters & naming the clusters\n\nLet's show random samples from each cluster. We'll use gpt-4 to name the clusters, based on a random sample of 5 reviews from that cluster.\n\n\n```python\nfrom openai import OpenAI\nimport os\n\nclient = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as env var>\"))\n\n# Reading a review which belong to each group.\nrev_per_cluster = 5\n\nfor i in range(n_clusters):\n    print(f\"Cluster {i} Theme:\", end=\" \")\n\n    reviews = \"\\n\".join(\n        df[df.Cluster == i]\n        .combined.str.replace(\"Title: \", \"\")\n        .str.replace(\"\\n\\nContent: \", \":  \")\n        .sample(rev_per_cluster, random_state=42)\n        .values\n    )\n\n    messages = [\n        {\"role\": \"user\", \"content\": f'What do the following customer reviews have in common?\\n\\nCustomer reviews:\\n\"\"\"\\n{reviews}\\n\"\"\"\\n\\nTheme:'}\n    ]\n\n    response = client.chat.completions.create(\n        model=\"gpt-4\",\n        messages=messages,\n        temperature=0,\n        max_tokens=64,\n        top_p=1,\n        frequency_penalty=0,\n        presence_penalty=0)\n    print(response.choices[0].message.content.replace(\"\\n\", \"\"))\n\n    sample_cluster_rows = df[df.Cluster == i].sample(rev_per_cluster, random_state=42)\n    for j in range(rev_per_cluster):\n        print(sample_cluster_rows.Score.values[j], end=\", \")\n        print(sample_cluster_rows.Summary.values[j], end=\":   \")\n        print(sample_cluster_rows.Text.str[:70].values[j])\n\n    print(\"-\" * 100)\n\n```\n\n    Cluster 0 Theme: The theme of these customer reviews is food products purchased on Amazon.\n    5, Loved these gluten free healthy bars, saved $$ ordering on Amazon:   These Kind Bars are so good and healthy & gluten free.  My daughter ca\n    1, Should advertise coconut as an ingredient more prominently:   First, these should be called Mac - Coconut bars, as Coconut is the #2\n    5, very good!!"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 069ed1dd-6412-4fd1-a2c4-d8cb3becbade
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb", "title": "imports", "tokens": 1743, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"069ed1dd-6412-4fd1-a2c4-d8cb3becbade\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"89b0fbc6-8468-4f59-8fc0-46c772ded6cc\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"33b195d3788ce86941015464446578b737d50abff856f45799d369fc2fbb2fc5\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"172c763c-64ea-4d47-ae93-6e2ac574a64b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ba7acf4cc99c09996640686b0b4e47dfe091e0a4bf7dac4aba2249645af53ed\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2d7bc133-52b4-4d7f-a871-ef925e7f3bbb\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"dabcc93b170635332ccebe0ffc557dab5c63789b4e8b14f679338b15c3ba1694\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2828, \"end_char_idx\": 5961, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "doc_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "ref_doc_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "chroma:document": "rev_per_cluster = 5\n\nfor i in range(n_clusters):\n    print(f\"Cluster {i} Theme:\", end=\" \")\n\n    reviews = \"\\n\".join(\n        df[df.Cluster == i]\n        .combined.str.replace(\"Title: \", \"\")\n        .str.replace(\"\\n\\nContent: \", \":  \")\n        .sample(rev_per_cluster, random_state=42)\n        .values\n    )\n\n    messages = [\n        {\"role\": \"user\", \"content\": f'What do the following customer reviews have in common?\\n\\nCustomer reviews:\\n\"\"\"\\n{reviews}\\n\"\"\"\\n\\nTheme:'}\n    ]\n\n    response = client.chat.completions.create(\n        model=\"gpt-4\",\n        messages=messages,\n        temperature=0,\n        max_tokens=64,\n        top_p=1,\n        frequency_penalty=0,\n        presence_penalty=0)\n    print(response.choices[0].message.content.replace(\"\\n\", \"\"))\n\n    sample_cluster_rows = df[df.Cluster == i].sample(rev_per_cluster, random_state=42)\n    for j in range(rev_per_cluster):\n        print(sample_cluster_rows.Score.values[j], end=\", \")\n        print(sample_cluster_rows.Summary.values[j], end=\":   \")\n        print(sample_cluster_rows.Text.str[:70].values[j])\n\n    print(\"-\" * 100)\n\n```\n\n    Cluster 0 Theme: The theme of these customer reviews is food products purchased on Amazon.\n    5, Loved these gluten free healthy bars, saved $$ ordering on Amazon:   These Kind Bars are so good and healthy & gluten free.  My daughter ca\n    1, Should advertise coconut as an ingredient more prominently:   First, these should be called Mac - Coconut bars, as Coconut is the #2\n    5, very good!!:   just like the runts<br />great flavor, def worth getting<br />I even o\n    5, Excellent product:   After scouring every store in town for orange peels and not finding an\n    5, delicious:   Gummi Frogs have been my favourite candy that I have ever tried. of co\n    ----------------------------------------------------------------------------------------------------\n    Cluster 1 Theme: Pet food reviews\n    2, Messy and apparently undelicious:   My cat is not a huge fan. Sure, she'll lap up the gravy, but leaves th\n    4, The cats like it:   My 7 cats like this food but it is a little yucky for the human. Piece\n    5, cant get enough of it!!!:   Our lil shih tzu puppy cannot get enough of it. Everytime she sees the\n    1, Food Caused Illness:   I switched my cats over from the Blue Buffalo Wildnerness Food to this\n    5, My furbabies LOVE these!:   Shake the container and they come running. Even my boy cat, who isn't \n    ----------------------------------------------------------------------------------------------------\n    Cluster 2 Theme: All the reviews are about different types of coffee.\n    5, Fog Chaser Coffee:   This coffee has a full body and a rich taste. The price is far below t\n    5, Excellent taste:   This is to me a great coffee, once you try it you will enjoy it, this \n    4, Good, but not Wolfgang Puck good:   Honestly, I have to admit that I expected a little better. That's not \n    5, Just My Kind of Coffee:   Coffee Masters Hazelnut coffee used to be carried in a local coffee/pa\n    5, Rodeo Drive is Crazy Good Coffee!:   Rodeo Drive is my absolute favorite and I'm ready to order more!"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 2d7bc133-52b4-4d7f-a871-ef925e7f3bbb
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb", "title": "imports", "tokens": 1743, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2d7bc133-52b4-4d7f-a871-ef925e7f3bbb\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"89b0fbc6-8468-4f59-8fc0-46c772ded6cc\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"33b195d3788ce86941015464446578b737d50abff856f45799d369fc2fbb2fc5\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"069ed1dd-6412-4fd1-a2c4-d8cb3becbade\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb\", \"title\": \"imports\", \"tokens\": 1743, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f8637740e73377aed40ad4601c217b1023e980e1d9ec51191991e7db884995d7\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4586, \"end_char_idx\": 7023, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "doc_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "ref_doc_id": "89b0fbc6-8468-4f59-8fc0-46c772ded6cc", "chroma:document": "of co\n    ----------------------------------------------------------------------------------------------------\n    Cluster 1 Theme: Pet food reviews\n    2, Messy and apparently undelicious:   My cat is not a huge fan. Sure, she'll lap up the gravy, but leaves th\n    4, The cats like it:   My 7 cats like this food but it is a little yucky for the human. Piece\n    5, cant get enough of it!!!:   Our lil shih tzu puppy cannot get enough of it. Everytime she sees the\n    1, Food Caused Illness:   I switched my cats over from the Blue Buffalo Wildnerness Food to this\n    5, My furbabies LOVE these!:   Shake the container and they come running. Even my boy cat, who isn't \n    ----------------------------------------------------------------------------------------------------\n    Cluster 2 Theme: All the reviews are about different types of coffee.\n    5, Fog Chaser Coffee:   This coffee has a full body and a rich taste. The price is far below t\n    5, Excellent taste:   This is to me a great coffee, once you try it you will enjoy it, this \n    4, Good, but not Wolfgang Puck good:   Honestly, I have to admit that I expected a little better. That's not \n    5, Just My Kind of Coffee:   Coffee Masters Hazelnut coffee used to be carried in a local coffee/pa\n    5, Rodeo Drive is Crazy Good Coffee!:   Rodeo Drive is my absolute favorite and I'm ready to order more!  That\n    ----------------------------------------------------------------------------------------------------\n    Cluster 3 Theme: The theme of these customer reviews is food and drink products.\n    5, Wonderful alternative to soda pop:   This is a wonderful alternative to soda pop.  It's carbonated for thos\n    5, So convenient, for so little!:   I needed two vanilla beans for the Love Goddess cake that my husbands \n    2, bot very cheesy:   Got this about a month ago.first of all it smells horrible...it tastes\n    5, Delicious!:   I am not a huge beer lover.  I do enjoy an occasional Blue Moon (all o\n    3, Just ok:   I bought this brand because it was all they had at Ranch 99 near us. I\n    ----------------------------------------------------------------------------------------------------\n\n\nIt's important to note that clusters will not necessarily match what you intend to use them for. A larger amount of clusters will focus on more specific patterns, whereas a small number of clusters will usually focus on largest discrepencies in the data."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 9f38adbb-a52f-49d8-8bb4-7d807efacb81
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb", "title": "Long Document Content Extraction", "tokens": 2562, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"9f38adbb-a52f-49d8-8bb4-7d807efacb81\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"6f9bae17-92ff-4a94-b0ff-c442e0292a3e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"381db3223923ff44d2e90b9f6c7028e0d381b0d3c769c3586bf8b4a299d35de4\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"436d98dc-334a-4fff-b571-515c3da9551d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6fb7099abf2140b0f2f18b1a886560b7f2662bdb69fa2106cbd4ed9affe4f491\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3115, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "ref_doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "chroma:document": "# Long Document Content Extraction\n\nGPT-3 can help us extract key figures, dates or other bits of important content from documents that are too big to fit into the context window. One approach for solving this is to chunk the document up and process each chunk separately, before combining into one list of answers. \n\nIn this notebook we'll run through this approach:\n- Load in a long PDF and pull the text out\n- Create a prompt to be used to extract key bits of information\n- Chunk up our document and process each chunk to pull any answers out\n- Combine them at the end\n- This simple approach will then be extended to three more difficult questions\n\n## Approach\n\n- **Setup**: Take a PDF, a Formula 1 Financial Regulation document on Power Units, and extract the text from it for entity extraction. We'll use this to try to extract answers that are buried in the content.\n- **Simple Entity Extraction**: Extract key bits of information from chunks of a document by:\n    - Creating a template prompt with our questions and an example of the format it expects\n    - Create a function to take a chunk of text as input, combine with the prompt and get a response\n    - Run a script to chunk the text, extract answers and output them for parsing\n- **Complex Entity Extraction**: Ask some more difficult questions which require tougher reasoning to work out\n\n## Setup\n\n\n```python\n!pip install textract\n!pip install tiktoken\n```\n\n\n```python\nimport textract\nimport os\nimport openai\nimport tiktoken\n\nclient = openai.OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as env var>\"))\n\n# Extract the raw text from each PDF using textract\ntext = textract.process('data/fia_f1_power_unit_financial_regulations_issue_1_-_2022-08-16.pdf', method='pdfminer').decode('utf-8')\nclean_text = text.replace(\"  \", \" \").replace(\"\\n\", \"; \").replace(';',' ')\n```\n\n## Simple Entity Extraction\n\n\n```python\n# Example prompt - \ndocument = '<document>'\ntemplate_prompt=f'''Extract key pieces of information from this regulation document.\nIf a particular piece of information is not present, output \\\"Not specified\\\".\nWhen you extract a key piece of information, include the closest page number.\nUse the following format:\\n0. Who is the author\\n1. What is the amount of the \"Power Unit Cost Cap\" in USD, GBP and EUR\\n2. What is the value of External Manufacturing Costs in USD\\n3. What is the Capital Expenditure Limit in USD\\n\\nDocument: \\\"\\\"\\\"<document>\\\"\\\"\\\"\\n\\n0. Who is the author: Tom Anderson (Page 1)\\n1.'''\nprint(template_prompt)\n```\n\n    Extract key pieces of information from this regulation document.\n    If a particular piece of information is not present, output \"Not specified\".\n    When you extract a key piece of information, include the closest page number.\n    Use the following format:\n    0. Who is the author\n    1. What is the amount of the \"Power Unit Cost Cap\" in USD, GBP and EUR\n    2. What is the value of External Manufacturing Costs in USD\n    3. What is the Capital Expenditure Limit in USD\n    \n    Document: \"\"\"<document>\"\"\"\n    \n    0. Who is the author: Tom Anderson (Page 1)\n    1."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 436d98dc-334a-4fff-b571-515c3da9551d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb", "title": "Long Document Content Extraction", "tokens": 2562, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"436d98dc-334a-4fff-b571-515c3da9551d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"6f9bae17-92ff-4a94-b0ff-c442e0292a3e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"381db3223923ff44d2e90b9f6c7028e0d381b0d3c769c3586bf8b4a299d35de4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"9f38adbb-a52f-49d8-8bb4-7d807efacb81\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e4425026bb0ed2e30d8f132097de6f9c07907c4ea6e616fe3bd6b75121b1082f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"5138e72e-ddc1-4e9c-9edd-53a5ea2a3bcd\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"151324bbc2bdf37a45e302a88ddc1a8962a1565d3cf0652c856c2558bfa14f16\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1898, \"end_char_idx\": 4891, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "ref_doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "chroma:document": "```python\n# Example prompt - \ndocument = '<document>'\ntemplate_prompt=f'''Extract key pieces of information from this regulation document.\nIf a particular piece of information is not present, output \\\"Not specified\\\".\nWhen you extract a key piece of information, include the closest page number.\nUse the following format:\\n0. Who is the author\\n1. What is the amount of the \"Power Unit Cost Cap\" in USD, GBP and EUR\\n2. What is the value of External Manufacturing Costs in USD\\n3. What is the Capital Expenditure Limit in USD\\n\\nDocument: \\\"\\\"\\\"<document>\\\"\\\"\\\"\\n\\n0. Who is the author: Tom Anderson (Page 1)\\n1.'''\nprint(template_prompt)\n```\n\n    Extract key pieces of information from this regulation document.\n    If a particular piece of information is not present, output \"Not specified\".\n    When you extract a key piece of information, include the closest page number.\n    Use the following format:\n    0. Who is the author\n    1. What is the amount of the \"Power Unit Cost Cap\" in USD, GBP and EUR\n    2. What is the value of External Manufacturing Costs in USD\n    3. What is the Capital Expenditure Limit in USD\n    \n    Document: \"\"\"<document>\"\"\"\n    \n    0. Who is the author: Tom Anderson (Page 1)\n    1.\n\n\n\n```python\n# Split a text into smaller chunks of size n, preferably ending at the end of a sentence\ndef create_chunks(text, n, tokenizer):\n    tokens = tokenizer.encode(text)\n    \"\"\"Yield successive n-sized chunks from text.\"\"\"\n    i = 0\n    while i < len(tokens):\n        # Find the nearest end of sentence within a range of 0.5 * n and 1.5 * n tokens\n        j = min(i + int(1.5 * n), len(tokens))\n        while j > i + int(0.5 * n):\n            # Decode the tokens and check for full stop or newline\n            chunk = tokenizer.decode(tokens[i:j])\n            if chunk.endswith(\".\") or chunk.endswith(\"\\n\"):\n                break\n            j -= 1\n        # If no end of sentence found, use n tokens as the chunk size\n        if j == i + int(0.5 * n):\n            j = min(i + n, len(tokens))\n        yield tokens[i:j]\n        i = j\n\ndef extract_chunk(document,template_prompt):\n    prompt = template_prompt.replace('<document>',document)\n\n    messages = [\n            {\"role\": \"system\", \"content\": \"You help extract information from documents.\"},\n            {\"role\": \"user\", \"content\": prompt}\n            ]\n\n    response = client.chat.completions.create(\n            model='gpt-4', \n            messages=messages,\n            temperature=0,\n            max_tokens=1500,\n            top_p=1,\n            frequency_penalty=0,\n            presence_penalty=0\n        )\n    return \"1.\" + response.choices[0].message.content\n```\n\n\n```python\n# Initialise tokenizer\ntokenizer = tiktoken.get_encoding(\"cl100k_base\")\n\nresults = []\n    \nchunks = create_chunks(clean_text,1000,tokenizer)\ntext_chunks = [tokenizer.decode(chunk) for chunk in chunks]\n\nfor chunk in text_chunks:\n    results.append(extract_chunk(chunk,template_prompt))\n    #print(chunk)\n    print(results[-1])\n\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 5138e72e-ddc1-4e9c-9edd-53a5ea2a3bcd
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb", "title": "Long Document Content Extraction", "tokens": 2562, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"5138e72e-ddc1-4e9c-9edd-53a5ea2a3bcd\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"6f9bae17-92ff-4a94-b0ff-c442e0292a3e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"381db3223923ff44d2e90b9f6c7028e0d381b0d3c769c3586bf8b4a299d35de4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"436d98dc-334a-4fff-b571-515c3da9551d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e8bb8575446e109ea97a6a7795ee97de4e1af66c86e8aa7e637438d6b3a30165\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"b7bf15a3-7b40-422c-a123-d61fd8e0ab24\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1bfd9e3d24ef35de5fc0d193e2b9b9fae4757dc6571aaf858f457069ea1c473f\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4551, \"end_char_idx\": 7063, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "ref_doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "chroma:document": "```python\n# Initialise tokenizer\ntokenizer = tiktoken.get_encoding(\"cl100k_base\")\n\nresults = []\n    \nchunks = create_chunks(clean_text,1000,tokenizer)\ntext_chunks = [tokenizer.decode(chunk) for chunk in chunks]\n\nfor chunk in text_chunks:\n    results.append(extract_chunk(chunk,template_prompt))\n    #print(chunk)\n    print(results[-1])\n\n```\n\n\n```python\ngroups = [r.split('\\n') for r in results]\n\n# zip the groups together\nzipped = list(zip(*groups))\nzipped = [x for y in zipped for x in y if \"Not specified\" not in x and \"__\" not in x]\nzipped\n```\n\n\n\n\n    ['1. What is the amount of the \"Power Unit Cost Cap\" in USD, GBP and EUR: USD 95,000,000 (Page 2); GBP 76,459,000 (Page 2); EUR 90,210,000 (Page 2)',\n     '2. What is the value of External Manufacturing Costs in USD: US Dollars 20,000,000 in respect of each of the Full Year Reporting Periods ending on 31 December 2023, 31 December 2024 and 31 December 2025, adjusted for Indexation (Page 10)',\n     '3. What is the Capital Expenditure Limit in USD: US Dollars 30,000,000 (Page 32)']\n\n\n\n## Complex Entity Extraction\n\n\n```python\n# Example prompt - \ntemplate_prompt=f'''Extract key pieces of information from this regulation document.\nIf a particular piece of information is not present, output \\\"Not specified\\\".\nWhen you extract a key piece of information, include the closest page number.\nUse the following format:\\n0. Who is the author\\n1. How is a Minor Overspend Breach calculated\\n2. How is a Major Overspend Breach calculated\\n3. Which years do these financial regulations apply to\\n\\nDocument: \\\"\\\"\\\"<document>\\\"\\\"\\\"\\n\\n0. Who is the author: Tom Anderson (Page 1)\\n1.'''\nprint(template_prompt)\n```\n\n    Extract key pieces of information from this regulation document.\n    If a particular piece of information is not present, output \"Not specified\".\n    When you extract a key piece of information, include the closest page number.\n    Use the following format:\n    0. Who is the author\n    1. How is a Minor Overspend Breach calculated\n    2. How is a Major Overspend Breach calculated\n    3. Which years do these financial regulations apply to\n    \n    Document: \"\"\"<document>\"\"\"\n    \n    0. Who is the author: Tom Anderson (Page 1)\n    1.\n\n\n\n```python\nresults = []\n\nfor chunk in text_chunks:\n    results.append(extract_chunk(chunk,template_prompt))\n    \ngroups = [r.split('\\n') for r in results]\n\n# zip the groups together\nzipped = list(zip(*groups))\nzipped = [x for y in zipped for x in y if \"Not specified\" not in x and \"__\" not in x]\nzipped\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: b7bf15a3-7b40-422c-a123-d61fd8e0ab24
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb", "title": "Long Document Content Extraction", "tokens": 2562, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b7bf15a3-7b40-422c-a123-d61fd8e0ab24\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"6f9bae17-92ff-4a94-b0ff-c442e0292a3e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"381db3223923ff44d2e90b9f6c7028e0d381b0d3c769c3586bf8b4a299d35de4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"5138e72e-ddc1-4e9c-9edd-53a5ea2a3bcd\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d9c21d1109291eb68983e7c206e4383e6901381fde00051d736d7c2e91b10c0a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"df40e0f1-e075-4c2d-8010-cda51c406821\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"82da62b1640d4e5ac2daabf3916d5d5843d910ccdc3b814c2614bf2117cdd480\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5594, \"end_char_idx\": 9651, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "ref_doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "chroma:document": "## Complex Entity Extraction\n\n\n```python\n# Example prompt - \ntemplate_prompt=f'''Extract key pieces of information from this regulation document.\nIf a particular piece of information is not present, output \\\"Not specified\\\".\nWhen you extract a key piece of information, include the closest page number.\nUse the following format:\\n0. Who is the author\\n1. How is a Minor Overspend Breach calculated\\n2. How is a Major Overspend Breach calculated\\n3. Which years do these financial regulations apply to\\n\\nDocument: \\\"\\\"\\\"<document>\\\"\\\"\\\"\\n\\n0. Who is the author: Tom Anderson (Page 1)\\n1.'''\nprint(template_prompt)\n```\n\n    Extract key pieces of information from this regulation document.\n    If a particular piece of information is not present, output \"Not specified\".\n    When you extract a key piece of information, include the closest page number.\n    Use the following format:\n    0. Who is the author\n    1. How is a Minor Overspend Breach calculated\n    2. How is a Major Overspend Breach calculated\n    3. Which years do these financial regulations apply to\n    \n    Document: \"\"\"<document>\"\"\"\n    \n    0. Who is the author: Tom Anderson (Page 1)\n    1.\n\n\n\n```python\nresults = []\n\nfor chunk in text_chunks:\n    results.append(extract_chunk(chunk,template_prompt))\n    \ngroups = [r.split('\\n') for r in results]\n\n# zip the groups together\nzipped = list(zip(*groups))\nzipped = [x for y in zipped for x in y if \"Not specified\" not in x and \"__\" not in x]\nzipped\n```\n\n\n\n\n    ['1. How is a Minor Overspend Breach calculated: A Minor Overspend Breach arises when a Power Unit Manufacturer submits its Full Year Reporting Documentation and Relevant Costs reported therein exceed the Power Unit Cost Cap by less than 5% (Page 24)',\n     '2. How is a Major Overspend Breach calculated: A Material Overspend Breach arises when a Power Unit Manufacturer submits its Full Year Reporting Documentation and Relevant Costs reported therein exceed the Power Unit Cost Cap by 5% or more (Page 25)',\n     '3. Which years do these financial regulations apply to: 2026 onwards (Page 1)',\n     '3. Which years do these financial regulations apply to: 2023, 2024, 2025, 2026 and subsequent Full Year Reporting Periods (Page 2)',\n     '3. Which years do these financial regulations apply to: 2022-2025 (Page 6)',\n     '3. Which years do these financial regulations apply to: 2023, 2024, 2025, 2026 and subsequent Full Year Reporting Periods (Page 10)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 14)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 16)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 19)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 21)',\n     '3. Which years do these financial regulations apply to: 2026 onwards (Page 26)',\n     '3. Which years do these financial regulations apply to: 2026 (Page 2)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 30)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 32)',\n     '3. Which years do these financial regulations apply to: 2023, 2024 and 2025 (Page 1)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 37)',\n     '3. Which years do these financial regulations apply to: 2026 onwards (Page 40)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 1)',\n     '3. Which years do these financial regulations apply to: 2026 to 2030 seasons (Page 46)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 47)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 1)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 1)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 56)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 1)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 16)',\n     '3. Which years do these financial regulations apply to: 2022 (Page 16)']"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: df40e0f1-e075-4c2d-8010-cda51c406821
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb", "title": "Long Document Content Extraction", "tokens": 2562, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"df40e0f1-e075-4c2d-8010-cda51c406821\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"6f9bae17-92ff-4a94-b0ff-c442e0292a3e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"381db3223923ff44d2e90b9f6c7028e0d381b0d3c769c3586bf8b4a299d35de4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b7bf15a3-7b40-422c-a123-d61fd8e0ab24\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Entity_extraction_for_long_documents.ipynb\", \"title\": \"Long Document Content Extraction\", \"tokens\": 2562, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2840c5109d1270ea5e841856a87f5bee08464b6ccb5b158cea4ce31bdd145a63\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9655, \"end_char_idx\": 10502, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "ref_doc_id": "6f9bae17-92ff-4a94-b0ff-c442e0292a3e", "chroma:document": "## Consolidation\n\nWe've been able to extract the first two answers safely, while the third was confounded by the date that appeared on every page, though the correct answer is in there as well.\n\nTo tune this further you can consider experimenting with:\n- A more descriptive or specific prompt\n- If you have sufficient training data, fine-tuning a model to find a set of outputs very well\n- The way you chunk your data - we have gone for 1000 tokens with no overlap, but more intelligent chunking that breaks info into sections, cuts by tokens or similar may get better results\n\nHowever, with minimal tuning we have now answered 6 questions of varying difficulty using the contents of a long document, and have a reusable approach that we can apply to any long document requiring entity extraction. Look forward to seeing what you can do with this!"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6aa9db15-4523-4937-aefe-02693a331f4f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6aa9db15-4523-4937-aefe-02693a331f4f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"321f0f05-b099-4408-ab06-b59fce59b998\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"21b4b95f8086b8bc0a8d00f03fc67fb41afaabe28e7b17ee6009a282eb917812\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3808, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "# Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\n\n\nA lot of enterprise data is unstructured and locked up in difficult-to-use formats, e.g. PDFs, PPT, PNG, that are not optimized for use with LLMs or databases. As a result this type of data tends to be underutilized for analysis and product development, despite it being so valuable. The traditional way of extracting information from unstructured or non-ideal formats has been to use OCR, but OCR struggles with complex layouts and can have limited multilingual support. Moreover, manually applying transforms to data can be cumbersome and timeconsuming. \n\nThe multi-modal capabilities of GPT-4o enable new ways to extract and transform data because of GPT-4o's ability to adapt to different types of documents and to use reasoning for interpreting the content of documents. Here are some reasons why you would choose GPT-4o for your extraction and transformation workflows over traditional methods. \n\n\n| **Extraction**                                               | **Transformation**                                              |\n|---------------------------------------------------------------|------------------------------------------------------------------|\n| **Adaptable**: Handles complex document layouts better, reducing errors | **Schema Adaptability**: Easily transforms data to fit specific schemas for database ingestion |\n| **Multilingual Support**: Seamlessly processes documents in multiple languages | **Dynamic Data Mapping**: Adapts to different data structures and formats, providing flexible transformation rules |\n| **Contextual Understanding**: Extracts meaningful relationships and context, not just text | **Enhanced Insight Generation**: Applies reasoning to create more insightful transformations, enriching the dataset with derived metrics, metadata and relationships |\n| **Multimodality**: Processes various document elements, including images and tables |  |\n\n\nThis cookbook has three parts:\n1. How to extract data from multilingual PDFs \n2. How to transform data according to a schema for loading into a database\n3. How to load transformed data into a database for downstream analysis\n\nWe're going to mimic a simple ELT workflow where data is first extracted from PDFs into JSON using GPT-4o, stored in an unstructured format somewhere like a data lake, transformed to fit a schema using GPT-4o, and then finally ingested into a relational database for querying. It's worth noting that you can do all of this with the BatchAPI if you're interested in lowering the cost of this workflow. \n\n![](../images/elt_workflow.png)\n\nThe data we'll be using is a set of publicly available 2019 hotel invoices from Germany available on [Jens Walter's GitHub](https://github.com/JensWalter/my-receipts/tree/master/2019/de/hotel), (thank you Jens!). Though hotel invoices generally contain similar information (reservation details, charges, taxes etc.), you'll notice that the invoices present itemized information in different ways and are multilingual containing both German and English. Fortunately GPT-4o can adapt to a variety of different document styles without us having to specify formats and it can seamlessly handle a variety of languages, even in the same document. \nHere is what one of the invoices looks like: \n\n![](../images/sample_hotel_invoice.png)\n\n## Part 1: Extracting data from PDFs using GPT-4o's vision capabilities\nGPT-4o doesn't natively handle PDFs so before we extract any data we'll first need to convert each page into an image and then encode the images as base64. \n\n\n```python\nfrom openai import OpenAI\nimport fitz  # PyMuPDF\nimport io\nimport os\nfrom PIL import Image\nimport base64\nimport json\n\napi_key = os.getenv(\"OPENAI_API_KEY\")\nclient = OpenAI(api_key=api_key)"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 321f0f05-b099-4408-ab06-b59fce59b998
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"321f0f05-b099-4408-ab06-b59fce59b998\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"6aa9db15-4523-4937-aefe-02693a331f4f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6e88793457b1108dbfa97efb38b788420f9c473279d82fbde8783c12a7fcfbde\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"6197227d-ecca-4f5b-bb67-3b4cf4e93df4\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"edb704ccd4f00fa63d1f595c7a017798a77aa32674ec2b8dfd5c210ea2df79af\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3610, \"end_char_idx\": 4957, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "```python\nfrom openai import OpenAI\nimport fitz  # PyMuPDF\nimport io\nimport os\nfrom PIL import Image\nimport base64\nimport json\n\napi_key = os.getenv(\"OPENAI_API_KEY\")\nclient = OpenAI(api_key=api_key)\n\n\n@staticmethod\ndef encode_image(image_path):\n    with open(image_path, \"rb\") as image_file:\n        return base64.b64encode(image_file.read()).decode(\"utf-8\")\n\n\ndef pdf_to_base64_images(pdf_path):\n    #Handles PDFs with multiple pages\n    pdf_document = fitz.open(pdf_path)\n    base64_images = []\n    temp_image_paths = []\n\n    total_pages = len(pdf_document)\n\n    for page_num in range(total_pages):\n        page = pdf_document.load_page(page_num)\n        pix = page.get_pixmap()\n        img = Image.open(io.BytesIO(pix.tobytes()))\n        temp_image_path = f\"temp_page_{page_num}.png\"\n        img.save(temp_image_path, format=\"PNG\")\n        temp_image_paths.append(temp_image_path)\n        base64_image = encode_image(temp_image_path)\n        base64_images.append(base64_image)\n\n    for temp_image_path in temp_image_paths:\n        os.remove(temp_image_path)\n\n    return base64_images\n```\n\nWe can then pass each base64 encoded image in a GPT-4o LLM call, specifying a high level of detail and JSON as the response format. We're not concerned about enforcing a schema at this step, we just want all of the data to be extracted regardless of type."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6197227d-ecca-4f5b-bb67-3b4cf4e93df4
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6197227d-ecca-4f5b-bb67-3b4cf4e93df4\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"321f0f05-b099-4408-ab06-b59fce59b998\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1d43fc296867b7c2124834bab0923037a776d418510fb69ae64309ba683b7f89\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"71cb5c8e-7579-4b1c-a4d5-8b5db94de899\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"cdcc1014fa7593ba314c07f6ca9e0cc8c9278cef62446c9d15fd71b2a4e14931\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3610, \"end_char_idx\": 7089, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "```python\nfrom openai import OpenAI\nimport fitz  # PyMuPDF\nimport io\nimport os\nfrom PIL import Image\nimport base64\nimport json\n\napi_key = os.getenv(\"OPENAI_API_KEY\")\nclient = OpenAI(api_key=api_key)\n\n\n@staticmethod\ndef encode_image(image_path):\n    with open(image_path, \"rb\") as image_file:\n        return base64.b64encode(image_file.read()).decode(\"utf-8\")\n\n\ndef pdf_to_base64_images(pdf_path):\n    #Handles PDFs with multiple pages\n    pdf_document = fitz.open(pdf_path)\n    base64_images = []\n    temp_image_paths = []\n\n    total_pages = len(pdf_document)\n\n    for page_num in range(total_pages):\n        page = pdf_document.load_page(page_num)\n        pix = page.get_pixmap()\n        img = Image.open(io.BytesIO(pix.tobytes()))\n        temp_image_path = f\"temp_page_{page_num}.png\"\n        img.save(temp_image_path, format=\"PNG\")\n        temp_image_paths.append(temp_image_path)\n        base64_image = encode_image(temp_image_path)\n        base64_images.append(base64_image)\n\n    for temp_image_path in temp_image_paths:\n        os.remove(temp_image_path)\n\n    return base64_images\n```\n\nWe can then pass each base64 encoded image in a GPT-4o LLM call, specifying a high level of detail and JSON as the response format. We're not concerned about enforcing a schema at this step, we just want all of the data to be extracted regardless of type.\n\n\n```python\ndef extract_invoice_data(base64_image):\n    system_prompt = f\"\"\"\n    You are an OCR-like data extraction tool that extracts hotel invoice data from PDFs.\n   \n    1. Please extract the data in this hotel invoice, grouping data according to theme/sub groups, and then output into JSON.\n\n    2. Please keep the keys and values of the JSON in the original language. \n\n    3. The type of data you might encounter in the invoice includes but is not limited to: hotel information, guest information, invoice information,\n    room charges, taxes, and total charges etc. \n\n    4. If the page contains no charge data, please output an empty JSON object and don't make up any data.\n\n    5. If there are blank data fields in the invoice, please include them as \"null\" values in the JSON object.\n    \n    6. If there are tables in the invoice, capture all of the rows and columns in the JSON object. \n    Even if a column is blank, include it as a key in the JSON object with a null value.\n    \n    7. If a row is blank denote missing fields with \"null\" values. \n    \n    8. Don't interpolate or make up data.\n\n    9. Please maintain the table structure of the charges, i.e. capture all of the rows and columns in the JSON object.\n\n    \"\"\"\n    \n    response = client.chat.completions.create(\n        model=\"gpt-4o\",\n        response_format={ \"type\": \"json_object\" },\n        messages=[\n            {\n                \"role\": \"system\",\n                \"content\": system_prompt\n            },\n            {\n                \"role\": \"user\",\n                \"content\": [\n                    {\"type\": \"text\", \"text\": \"extract the data in this hotel invoice and output into JSON \"},\n                    {\"type\": \"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{base64_image}\", \"detail\": \"high\"}}\n                ]\n            }\n        ],\n        temperature=0.0,\n    )\n    return response.choices[0].message.content\n\n```\n\nBecause invoice data can span multiple pages in a PDF, we're going to produce JSON objects for each page in the invoice and then append them together. The final invoice extraction will be a single JSON file."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 71cb5c8e-7579-4b1c-a4d5-8b5db94de899
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"71cb5c8e-7579-4b1c-a4d5-8b5db94de899\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"6197227d-ecca-4f5b-bb67-3b4cf4e93df4\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b8d5ffde8077abb76f53980531a48dc513c9dbe84dab347767388c3d7137e000\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"eedff53d-a28a-47c8-be61-4e014f7474d7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"fd83903713e7f52cbbf8b53db6f352762af8bbb7002e5f8c92aa997269f680cd\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7092, \"end_char_idx\": 10103, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "```python\ndef extract_from_multiple_pages(base64_images, original_filename, output_directory):\n    entire_invoice = []\n\n    for base64_image in base64_images:\n        invoice_json = extract_invoice_data(base64_image)\n        invoice_data = json.loads(invoice_json)\n        entire_invoice.append(invoice_data)\n\n    # Ensure the output directory exists\n    os.makedirs(output_directory, exist_ok=True)\n\n    # Construct the output file path\n    output_filename = os.path.join(output_directory, original_filename.replace('.pdf', '_extracted.json'))\n    \n    # Save the entire_invoice list as a JSON file\n    with open(output_filename, 'w', encoding='utf-8') as f:\n        json.dump(entire_invoice, f, ensure_ascii=False, indent=4)\n    return output_filename\n\n\ndef main_extract(read_path, write_path):\n    for filename in os.listdir(read_path):\n        file_path = os.path.join(read_path, filename)\n        if os.path.isfile(file_path):\n            base64_images = pdf_to_base64_images(file_path)\n            extract_from_multiple_pages(base64_images, filename, write_path)\n\n\nread_path= \"./data/hotel_invoices/receipts_2019_de_hotel\"\nwrite_path= \"./data/hotel_invoices/extracted_invoice_json\"\n\nmain_extract(read_path, write_path)\n\n```\n\nEach invoice JSON will have different keys depending on what data the original invoice contained, so at this point you can store the unschematized JSON files in a data lake that can handle unstructured data. For simplicity though, we're going to store the files in a folder. Here is what one of the extracted JSON files looks like, you'll notice that even though we didn't specify a schema, GPT-4o was able to understand German and group similar information together. Moreover, if there was a blank field in the invoice GPT-4o transcribed that as \"null\". \n\n\n```python\n[\n    {\n        \"Hotel Information\": {\n            \"Name\": \"Hamburg City (Zentrum)\",\n            \"Address\": \"Willy-Brandt-Stra\u00dfe 21, 20457 Hamburg, Deutschland\",\n            \"Phone\": \"+49 (0) 40 3039 379 0\"\n        },\n        \"Guest Information\": {\n            \"Name\": \"APIMEISTER CONSULTING GmbH\",\n            \"Guest\": \"Herr Jens Walter\",\n            \"Address\": \"Friedrichstr. 123, 10117 Berlin\"\n        },\n        \"Invoice Information\": {\n            \"Rechnungsnummer\": \"GABC19014325\",\n            \"Rechnungsdatum\": \"23.09.19\",\n            \"Referenznummer\": \"GABC015452127\",\n            \"Buchungsnummer\": \"GABR15867\",\n            \"Ankunft\": \"23.09.19\",\n            \"Abreise\": \"27.09.19\",\n            \"N\u00e4chte\": 4,\n            \"Zimmer\": 626,\n            \"Kundereferenz\": 2\n        },\n        \"Charges\": [\n            {\n                \"Datum\": \"23.09.19\",\n                \"Uhrzeit\": \"16:36\",\n                \"Beschreibung\": \"\u00dcbernachtung\",\n                \"MwSt.%\": 7.0,\n                \"Betrag\": 77.0,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"24.09.19\",\n                \"Uhrzeit\": null,\n                \"Beschreibung\": \"\u00dcbernachtung\",\n                \"MwSt.%\": 7.0,"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: eedff53d-a28a-47c8-be61-4e014f7474d7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"eedff53d-a28a-47c8-be61-4e014f7474d7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"71cb5c8e-7579-4b1c-a4d5-8b5db94de899\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f4a611220a5e7d5fdc7d5f9f57c46bd3f01f40d9b74459e8c34017e7b65a9e1d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2e2f78fb-5246-41b7-b3d4-ac79de86dab8\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"0203665dd1f8aef346d506b29a65d2ddc8b9ba9f29bb15061d29b1d21ee4df96\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8881, \"end_char_idx\": 11401, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "```python\n[\n    {\n        \"Hotel Information\": {\n            \"Name\": \"Hamburg City (Zentrum)\",\n            \"Address\": \"Willy-Brandt-Stra\u00dfe 21, 20457 Hamburg, Deutschland\",\n            \"Phone\": \"+49 (0) 40 3039 379 0\"\n        },\n        \"Guest Information\": {\n            \"Name\": \"APIMEISTER CONSULTING GmbH\",\n            \"Guest\": \"Herr Jens Walter\",\n            \"Address\": \"Friedrichstr. 123, 10117 Berlin\"\n        },\n        \"Invoice Information\": {\n            \"Rechnungsnummer\": \"GABC19014325\",\n            \"Rechnungsdatum\": \"23.09.19\",\n            \"Referenznummer\": \"GABC015452127\",\n            \"Buchungsnummer\": \"GABR15867\",\n            \"Ankunft\": \"23.09.19\",\n            \"Abreise\": \"27.09.19\",\n            \"N\u00e4chte\": 4,\n            \"Zimmer\": 626,\n            \"Kundereferenz\": 2\n        },\n        \"Charges\": [\n            {\n                \"Datum\": \"23.09.19\",\n                \"Uhrzeit\": \"16:36\",\n                \"Beschreibung\": \"\u00dcbernachtung\",\n                \"MwSt.%\": 7.0,\n                \"Betrag\": 77.0,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"24.09.19\",\n                \"Uhrzeit\": null,\n                \"Beschreibung\": \"\u00dcbernachtung\",\n                \"MwSt.%\": 7.0,\n                \"Betrag\": 135.0,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"25.09.19\",\n                \"Uhrzeit\": null,\n                \"Beschreibung\": \"\u00dcbernachtung\",\n                \"MwSt.%\": 7.0,\n                \"Betrag\": 82.0,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"26.09.19\",\n                \"Uhrzeit\": null,\n                \"Beschreibung\": \"\u00dcbernachtung\",\n                \"MwSt.%\": 7.0,\n                \"Betrag\": 217.0,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"24.09.19\",\n                \"Uhrzeit\": \"9:50\",\n                \"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"25.09.19\",\n                \"Uhrzeit\": \"9:50\",\n                \"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"26.09.19\",\n                \"Uhrzeit\": \"9:50\",\n                \"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 2e2f78fb-5246-41b7-b3d4-ac79de86dab8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2e2f78fb-5246-41b7-b3d4-ac79de86dab8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"eedff53d-a28a-47c8-be61-4e014f7474d7\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba58a757e26943eac125cd331825fde886c7415897bb35a7430c94138767b9a7\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a5dc91b1-00bb-4bcb-92a9-3e7107475ce6\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5716c6457082c3f49eee969fd6abe79868d768629b07904ab59ef0b29ca5bd8f\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10101, \"end_char_idx\": 12728, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "0,\n                \"Betrag\": 135.0,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"25.09.19\",\n                \"Uhrzeit\": null,\n                \"Beschreibung\": \"\u00dcbernachtung\",\n                \"MwSt.%\": 7.0,\n                \"Betrag\": 82.0,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"26.09.19\",\n                \"Uhrzeit\": null,\n                \"Beschreibung\": \"\u00dcbernachtung\",\n                \"MwSt.%\": 7.0,\n                \"Betrag\": 217.0,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"24.09.19\",\n                \"Uhrzeit\": \"9:50\",\n                \"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"25.09.19\",\n                \"Uhrzeit\": \"9:50\",\n                \"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"26.09.19\",\n                \"Uhrzeit\": \"9:50\",\n                \"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"27.09.19\",\n                \"Uhrzeit\": \"9:50\",\n                \"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            }\n        ],\n        \"Payment Information\": {\n            \"Zahlung\": \"550,60\",\n            \"Gesamt (Rechnungsbetrag)\": \"550,60\",\n            \"Offener Betrag\": \"0,00\",\n            \"Bezahlart\": \"Mastercard-Kreditkarte\"\n        },\n        \"Tax Information\": {\n            \"MwSt.%\": [\n                {\n                    \"Rate\": 19.0,\n                    \"Netto\": 33.28,\n                    \"MwSt.\": 6.32,\n                    \"Brutto\": 39.6\n                },\n                {\n                    \"Rate\": 7.0,\n                    \"Netto\": 477.57,\n                    \"MwSt.\": 33.43,\n                    \"Brutto\": 511.0\n                }\n            ]\n        }\n    }\n]\n```\n\n## Part 2: Transforming data according to a schema \n\nYou've extracted data from PDFs and have likely loaded the unstructured extractions as JSON objects in a data lake. The next step in our ELT workflow is to use GPT-4o to transform the extractions according to our desired schema. This will enable us to ingest any resulting tables into a database."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: a5dc91b1-00bb-4bcb-92a9-3e7107475ce6
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a5dc91b1-00bb-4bcb-92a9-3e7107475ce6\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2e2f78fb-5246-41b7-b3d4-ac79de86dab8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ec2567bfe00d21f6efaf478810abf320e6ea29bccca8917b7152a9ab317a269f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"db9739ce-7174-4286-8a50-e3c215d53027\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a973d98aa1e3718e6f3fd2f385a287b1324024271a0ec60c31338ef2caf2c3ae\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11355, \"end_char_idx\": 13088, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "\"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            },\n            {\n                \"Datum\": \"27.09.19\",\n                \"Uhrzeit\": \"9:50\",\n                \"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            }\n        ],\n        \"Payment Information\": {\n            \"Zahlung\": \"550,60\",\n            \"Gesamt (Rechnungsbetrag)\": \"550,60\",\n            \"Offener Betrag\": \"0,00\",\n            \"Bezahlart\": \"Mastercard-Kreditkarte\"\n        },\n        \"Tax Information\": {\n            \"MwSt.%\": [\n                {\n                    \"Rate\": 19.0,\n                    \"Netto\": 33.28,\n                    \"MwSt.\": 6.32,\n                    \"Brutto\": 39.6\n                },\n                {\n                    \"Rate\": 7.0,\n                    \"Netto\": 477.57,\n                    \"MwSt.\": 33.43,\n                    \"Brutto\": 511.0\n                }\n            ]\n        }\n    }\n]\n```\n\n## Part 2: Transforming data according to a schema \n\nYou've extracted data from PDFs and have likely loaded the unstructured extractions as JSON objects in a data lake. The next step in our ELT workflow is to use GPT-4o to transform the extractions according to our desired schema. This will enable us to ingest any resulting tables into a database. We've decided upon the following schema that broadly covers most of the information we would have seen across the different invoices. This schema will be used to process each raw JSON extraction into our desired schematized JSON and can specify particular formats such as \"date\": \"YYYY-MM-DD\". We're also going to translate the data into English at this step."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: db9739ce-7174-4286-8a50-e3c215d53027
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"db9739ce-7174-4286-8a50-e3c215d53027\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a5dc91b1-00bb-4bcb-92a9-3e7107475ce6\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b3bf9dc8185b731b88e6659f57d620228910601d5b1beebdf4b1d189fee4ffa3\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"b9d43aa3-8c09-410b-b312-69d1ba8a5a8d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"41eb3815c43db3942efe7545245f747249cf906321e11dd9c568688d222e875b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11551, \"end_char_idx\": 14751, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "\"Beschreibung\": \"Premier Inn Fr\u00fchst\u00fccksbuffet\",\n                \"MwSt.%\": 19.0,\n                \"Betrag\": 9.9,\n                \"Zahlung\": null\n            }\n        ],\n        \"Payment Information\": {\n            \"Zahlung\": \"550,60\",\n            \"Gesamt (Rechnungsbetrag)\": \"550,60\",\n            \"Offener Betrag\": \"0,00\",\n            \"Bezahlart\": \"Mastercard-Kreditkarte\"\n        },\n        \"Tax Information\": {\n            \"MwSt.%\": [\n                {\n                    \"Rate\": 19.0,\n                    \"Netto\": 33.28,\n                    \"MwSt.\": 6.32,\n                    \"Brutto\": 39.6\n                },\n                {\n                    \"Rate\": 7.0,\n                    \"Netto\": 477.57,\n                    \"MwSt.\": 33.43,\n                    \"Brutto\": 511.0\n                }\n            ]\n        }\n    }\n]\n```\n\n## Part 2: Transforming data according to a schema \n\nYou've extracted data from PDFs and have likely loaded the unstructured extractions as JSON objects in a data lake. The next step in our ELT workflow is to use GPT-4o to transform the extractions according to our desired schema. This will enable us to ingest any resulting tables into a database. We've decided upon the following schema that broadly covers most of the information we would have seen across the different invoices. This schema will be used to process each raw JSON extraction into our desired schematized JSON and can specify particular formats such as \"date\": \"YYYY-MM-DD\". We're also going to translate the data into English at this step. \n\n\n\n```python\n[\n    {\n        \"hotel_information\": {\n            \"name\": \"string\",\n            \"address\": {\n                \"street\": \"string\",\n                \"city\": \"string\",\n                \"country\": \"string\",\n                \"postal_code\": \"string\"\n            },\n            \"contact\": {\n                \"phone\": \"string\",\n                \"fax\": \"string\",\n                \"email\": \"string\",\n                \"website\": \"string\"\n            }\n        },\n        \"guest_information\": {\n            \"company\": \"string\",\n            \"address\": \"string\",\n            \"guest_name\": \"string\"\n        },\n        \"invoice_information\": {\n            \"invoice_number\": \"string\",\n            \"reservation_number\": \"string\",\n            \"date\": \"YYYY-MM-DD\",  \n            \"room_number\": \"string\",\n            \"check_in_date\": \"YYYY-MM-DD\",  \n            \"check_out_date\": \"YYYY-MM-DD\"  \n        },\n        \"charges\": [\n            {\n                \"date\": \"YYYY-MM-DD\", \n                \"description\": \"string\",\n                \"charge\": \"number\",\n                \"credit\": \"number\"\n            }\n        ],\n        \"totals_summary\": {\n            \"currency\": \"string\",\n            \"total_net\": \"number\",\n            \"total_tax\": \"number\",\n            \"total_gross\": \"number\",\n            \"total_charge\": \"number\",\n            \"total_credit\": \"number\",\n            \"balance_due\": \"number\"\n        },\n        \"taxes\": [\n            {\n                \"tax_type\": \"string\",\n                \"tax_rate\": \"string\",\n                \"net_amount\": \"number\",\n                \"tax_amount\": \"number\",\n                \"gross_amount\": \"number\"\n            }\n        ]\n    }\n]\n\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: b9d43aa3-8c09-410b-b312-69d1ba8a5a8d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b9d43aa3-8c09-410b-b312-69d1ba8a5a8d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"db9739ce-7174-4286-8a50-e3c215d53027\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7f19e8b4a78ddca1fd7fbaa3fe7cba959ff20f582466df8ebd2c050dcded12b3\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"28df222e-23e6-4c58-b7be-ed756822404b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9eb1e0a24f3d52e555cc8d653af7d597d48c078ad28ce290f5d89f6b9ed717e5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 12863, \"end_char_idx\": 16009, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "This schema will be used to process each raw JSON extraction into our desired schematized JSON and can specify particular formats such as \"date\": \"YYYY-MM-DD\". We're also going to translate the data into English at this step. \n\n\n\n```python\n[\n    {\n        \"hotel_information\": {\n            \"name\": \"string\",\n            \"address\": {\n                \"street\": \"string\",\n                \"city\": \"string\",\n                \"country\": \"string\",\n                \"postal_code\": \"string\"\n            },\n            \"contact\": {\n                \"phone\": \"string\",\n                \"fax\": \"string\",\n                \"email\": \"string\",\n                \"website\": \"string\"\n            }\n        },\n        \"guest_information\": {\n            \"company\": \"string\",\n            \"address\": \"string\",\n            \"guest_name\": \"string\"\n        },\n        \"invoice_information\": {\n            \"invoice_number\": \"string\",\n            \"reservation_number\": \"string\",\n            \"date\": \"YYYY-MM-DD\",  \n            \"room_number\": \"string\",\n            \"check_in_date\": \"YYYY-MM-DD\",  \n            \"check_out_date\": \"YYYY-MM-DD\"  \n        },\n        \"charges\": [\n            {\n                \"date\": \"YYYY-MM-DD\", \n                \"description\": \"string\",\n                \"charge\": \"number\",\n                \"credit\": \"number\"\n            }\n        ],\n        \"totals_summary\": {\n            \"currency\": \"string\",\n            \"total_net\": \"number\",\n            \"total_tax\": \"number\",\n            \"total_gross\": \"number\",\n            \"total_charge\": \"number\",\n            \"total_credit\": \"number\",\n            \"balance_due\": \"number\"\n        },\n        \"taxes\": [\n            {\n                \"tax_type\": \"string\",\n                \"tax_rate\": \"string\",\n                \"net_amount\": \"number\",\n                \"tax_amount\": \"number\",\n                \"gross_amount\": \"number\"\n            }\n        ]\n    }\n]\n\n```\n\n\n```python\ndef transform_invoice_data(json_raw, json_schema):\n    system_prompt = f\"\"\"\n    You are a data transformation tool that takes in JSON data and a reference JSON schema, and outputs JSON data according to the schema.\n    Not all of the data in the input JSON will fit the schema, so you may need to omit some data or add null values to the output JSON.\n    Translate all data into English if not already in English.\n    Ensure values are formatted as specified in the schema (e.g. dates as YYYY-MM-DD).\n    Here is the schema:\n    {json_schema}\n\n    \"\"\"\n    \n    response = client.chat.completions.create(\n        model=\"gpt-4o\",\n        response_format={ \"type\": \"json_object\" },\n        messages=[\n            {\n                \"role\": \"system\",\n                \"content\": system_prompt\n            },\n            {\n                \"role\": \"user\",\n                \"content\": [\n                    {\"type\": \"text\", \"text\": f\"Transform the following raw JSON data according to the provided schema. Ensure all data is in English and formatted as specified by values in the schema. Here is the raw JSON: {json_raw}\"}\n                ]\n            }\n        ],\n        temperature=0.0,\n    )\n    return json.loads(response.choices[0].message.content)"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 28df222e-23e6-4c58-b7be-ed756822404b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"28df222e-23e6-4c58-b7be-ed756822404b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b9d43aa3-8c09-410b-b312-69d1ba8a5a8d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e30fcbd0d02641d03e5cecdb0a5bae76aa1a0958f6d229bf479433e77af76440\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"aa8e372a-cf1f-45e6-8991-c4608423670d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f996a492764e68041203a34087e4cce37dd28dddfcc3296ea1a8a325c75c647a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14754, \"end_char_idx\": 17787, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "```python\ndef transform_invoice_data(json_raw, json_schema):\n    system_prompt = f\"\"\"\n    You are a data transformation tool that takes in JSON data and a reference JSON schema, and outputs JSON data according to the schema.\n    Not all of the data in the input JSON will fit the schema, so you may need to omit some data or add null values to the output JSON.\n    Translate all data into English if not already in English.\n    Ensure values are formatted as specified in the schema (e.g. dates as YYYY-MM-DD).\n    Here is the schema:\n    {json_schema}\n\n    \"\"\"\n    \n    response = client.chat.completions.create(\n        model=\"gpt-4o\",\n        response_format={ \"type\": \"json_object\" },\n        messages=[\n            {\n                \"role\": \"system\",\n                \"content\": system_prompt\n            },\n            {\n                \"role\": \"user\",\n                \"content\": [\n                    {\"type\": \"text\", \"text\": f\"Transform the following raw JSON data according to the provided schema. Ensure all data is in English and formatted as specified by values in the schema. Here is the raw JSON: {json_raw}\"}\n                ]\n            }\n        ],\n        temperature=0.0,\n    )\n    return json.loads(response.choices[0].message.content)\n\n\n\ndef main_transform(extracted_invoice_json_path, json_schema_path, save_path):\n    # Load the JSON schema\n    with open(json_schema_path, 'r', encoding='utf-8') as f:\n        json_schema = json.load(f)\n\n    # Ensure the save directory exists\n    os.makedirs(save_path, exist_ok=True)\n\n    # Process each JSON file in the extracted invoices directory\n    for filename in os.listdir(extracted_invoice_json_path):\n        if filename.endswith(\".json\"):\n            file_path = os.path.join(extracted_invoice_json_path, filename)\n\n            # Load the extracted JSON\n            with open(file_path, 'r', encoding='utf-8') as f:\n                json_raw = json.load(f)\n\n            # Transform the JSON data\n            transformed_json = transform_invoice_data(json_raw, json_schema)\n\n            # Save the transformed JSON to the save directory\n            transformed_filename = f\"transformed_{filename}\"\n            transformed_file_path = os.path.join(save_path, transformed_filename)\n            with open(transformed_file_path, 'w', encoding='utf-8') as f:\n                json.dump(transformed_json, f, ensure_ascii=False, indent=2)\n\n   \n    extracted_invoice_json_path = \"./data/hotel_invoices/extracted_invoice_json\"\n    json_schema_path = \"./data/hotel_invoices/invoice_schema.json\"\n    save_path = \"./data/hotel_invoices/transformed_invoice_json\"\n\n    main_transform(extracted_invoice_json_path, json_schema_path, save_path)\n```\n\n## Part 3: Loading transformed data into a database \n\nNow that we've schematized all of our data, we can segment it into tables for ingesting into a relational database. In particular, we're going to create four tables: Hotels, Invoices, Charges and Taxes. All of the invoices pertained to one guest, so we won't create a guest table."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: aa8e372a-cf1f-45e6-8991-c4608423670d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"aa8e372a-cf1f-45e6-8991-c4608423670d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"28df222e-23e6-4c58-b7be-ed756822404b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"eebbb3079ae0f0ea4931d303c8b85141a44c57f311c6b346bcae1fcbcb930131\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"0894407e-994a-4592-bce6-b932c6fe7df7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"46c7fcf323fc762bc6bf73ede1fabf6d65400ced1ebcca66e2d4029d3895960a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 16013, \"end_char_idx\": 20164, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "def main_transform(extracted_invoice_json_path, json_schema_path, save_path):\n    # Load the JSON schema\n    with open(json_schema_path, 'r', encoding='utf-8') as f:\n        json_schema = json.load(f)\n\n    # Ensure the save directory exists\n    os.makedirs(save_path, exist_ok=True)\n\n    # Process each JSON file in the extracted invoices directory\n    for filename in os.listdir(extracted_invoice_json_path):\n        if filename.endswith(\".json\"):\n            file_path = os.path.join(extracted_invoice_json_path, filename)\n\n            # Load the extracted JSON\n            with open(file_path, 'r', encoding='utf-8') as f:\n                json_raw = json.load(f)\n\n            # Transform the JSON data\n            transformed_json = transform_invoice_data(json_raw, json_schema)\n\n            # Save the transformed JSON to the save directory\n            transformed_filename = f\"transformed_{filename}\"\n            transformed_file_path = os.path.join(save_path, transformed_filename)\n            with open(transformed_file_path, 'w', encoding='utf-8') as f:\n                json.dump(transformed_json, f, ensure_ascii=False, indent=2)\n\n   \n    extracted_invoice_json_path = \"./data/hotel_invoices/extracted_invoice_json\"\n    json_schema_path = \"./data/hotel_invoices/invoice_schema.json\"\n    save_path = \"./data/hotel_invoices/transformed_invoice_json\"\n\n    main_transform(extracted_invoice_json_path, json_schema_path, save_path)\n```\n\n## Part 3: Loading transformed data into a database \n\nNow that we've schematized all of our data, we can segment it into tables for ingesting into a relational database. In particular, we're going to create four tables: Hotels, Invoices, Charges and Taxes. All of the invoices pertained to one guest, so we won't create a guest table. \n\n\n```python\nimport os\nimport json\nimport sqlite3\n\ndef ingest_transformed_jsons(json_folder_path, db_path):\n    conn = sqlite3.connect(db_path)\n    cursor = conn.cursor()\n\n    # Create necessary tables\n    cursor.execute('''\n    CREATE TABLE IF NOT EXISTS Hotels (\n        hotel_id INTEGER PRIMARY KEY AUTOINCREMENT,\n        name TEXT,\n        street TEXT,\n        city TEXT,\n        country TEXT,\n        postal_code TEXT,\n        phone TEXT,\n        fax TEXT,\n        email TEXT,\n        website TEXT\n    )\n    ''')\n\n    cursor.execute('''\n    CREATE TABLE IF NOT EXISTS Invoices (\n        invoice_id INTEGER PRIMARY KEY AUTOINCREMENT,\n        hotel_id INTEGER,\n        invoice_number TEXT,\n        reservation_number TEXT,\n        date TEXT,\n        room_number TEXT,\n        check_in_date TEXT,\n        check_out_date TEXT,\n        currency TEXT,\n        total_net REAL,\n        total_tax REAL,\n        total_gross REAL,\n        total_charge REAL,\n        total_credit REAL,\n        balance_due REAL,\n        guest_company TEXT,\n        guest_address TEXT,\n        guest_name TEXT,\n        FOREIGN KEY(hotel_id) REFERENCES Hotels(hotel_id)\n    )\n    ''')\n\n    cursor.execute('''\n    CREATE TABLE IF NOT EXISTS Charges (\n        charge_id INTEGER PRIMARY KEY AUTOINCREMENT,\n        invoice_id INTEGER,\n        date TEXT,\n        description TEXT,\n        charge REAL,\n        credit REAL,\n        FOREIGN KEY(invoice_id) REFERENCES Invoices(invoice_id)\n    )\n    ''')\n\n    cursor.execute('''\n    CREATE TABLE IF NOT EXISTS Taxes (\n        tax_id INTEGER PRIMARY KEY AUTOINCREMENT,\n        invoice_id INTEGER,\n        tax_type TEXT,\n        tax_rate TEXT,\n        net_amount REAL,\n        tax_amount REAL,\n        gross_amount REAL,\n        FOREIGN KEY(invoice_id) REFERENCES Invoices(invoice_id)\n    )\n    ''')\n\n    # Loop over all JSON files in the specified folder\n    for filename in os.listdir(json_folder_path):\n        if filename.endswith(\".json\"):\n            file_path = os.path.join(json_folder_path, filename)\n\n            # Load the JSON data\n            with open(file_path, 'r', encoding='utf-8') as f:\n                data = json.load(f)\n\n            # Insert Hotel Information\n            cursor.execute('''\n            INSERT INTO Hotels (name, street, city, country, postal_code, phone, fax, email, website) \n            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 0894407e-994a-4592-bce6-b932c6fe7df7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0894407e-994a-4592-bce6-b932c6fe7df7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"aa8e372a-cf1f-45e6-8991-c4608423670d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f7037b64d1790500a8d6713ad58ca596d5cc436bd11b2ac4ff173d98ae47bc45\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"11cef8ec-2ee4-4f6d-9e4a-7dfaac13210d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"aa996aac1153766ead665b28cf095b8f0d5297ffb55a8e6b498a3e04e88715c1\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 20177, \"end_char_idx\": 23714, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "''', (\n                data[\"hotel_information\"][\"name\"],\n                data[\"hotel_information\"][\"address\"][\"street\"],\n                data[\"hotel_information\"][\"address\"][\"city\"],\n                data[\"hotel_information\"][\"address\"][\"country\"],\n                data[\"hotel_information\"][\"address\"][\"postal_code\"],\n                data[\"hotel_information\"][\"contact\"][\"phone\"],\n                data[\"hotel_information\"][\"contact\"][\"fax\"],\n                data[\"hotel_information\"][\"contact\"][\"email\"],\n                data[\"hotel_information\"][\"contact\"][\"website\"]\n            ))\n            hotel_id = cursor.lastrowid\n\n            # Insert Invoice Information\n            cursor.execute('''\n            INSERT INTO Invoices (hotel_id, invoice_number, reservation_number, date, room_number, check_in_date, check_out_date, currency, total_net, total_tax, total_gross, total_charge, total_credit, balance_due, guest_company, guest_address, guest_name)\n            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n            ''', (\n                hotel_id,\n                data[\"invoice_information\"][\"invoice_number\"],\n                data[\"invoice_information\"][\"reservation_number\"],\n                data[\"invoice_information\"][\"date\"],\n                data[\"invoice_information\"][\"room_number\"],\n                data[\"invoice_information\"][\"check_in_date\"],\n                data[\"invoice_information\"][\"check_out_date\"],\n                data[\"totals_summary\"][\"currency\"],\n                data[\"totals_summary\"][\"total_net\"],\n                data[\"totals_summary\"][\"total_tax\"],\n                data[\"totals_summary\"][\"total_gross\"],\n                data[\"totals_summary\"][\"total_charge\"],\n                data[\"totals_summary\"][\"total_credit\"],\n                data[\"totals_summary\"][\"balance_due\"],\n                data[\"guest_information\"][\"company\"],\n                data[\"guest_information\"][\"address\"],\n                data[\"guest_information\"][\"guest_name\"]\n            ))\n            invoice_id = cursor.lastrowid\n\n            # Insert Charges\n            for charge in data[\"charges\"]:\n                cursor.execute('''\n                INSERT INTO Charges (invoice_id, date, description, charge, credit) \n                VALUES (?, ?, ?, ?, ?)\n                ''', (\n                    invoice_id,\n                    charge[\"date\"],\n                    charge[\"description\"],\n                    charge[\"charge\"],\n                    charge[\"credit\"]\n                ))\n\n            # Insert Taxes\n            for tax in data[\"taxes\"]:\n                cursor.execute('''\n                INSERT INTO Taxes (invoice_id, tax_type, tax_rate, net_amount, tax_amount, gross_amount) \n                VALUES (?, ?, ?, ?, ?, ?)\n                ''', (\n                    invoice_id,\n                    tax[\"tax_type\"],\n                    tax[\"tax_rate\"],\n                    tax[\"net_amount\"],\n                    tax[\"tax_amount\"],\n                    tax[\"gross_amount\"]\n                ))\n\n    conn.commit()\n    conn.close()\n\n\n```\n\nNow let's check that we've correctly ingested the data by running a sample SQL query to determine the most expensive hotel stay and the same of the hotel!  \nYou can even automate the generation of SQL queries at this step by using function calling, check out our [cookbook on function calling with model generated arguments](https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models#how-to-call-functions-with-model-generated-arguments) to learn how to do that."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 11cef8ec-2ee4-4f6d-9e4a-7dfaac13210d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb", "title": "Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative", "tokens": 5588, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"11cef8ec-2ee4-4f6d-9e4a-7dfaac13210d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"b3208930-1208-4c3e-897b-d2d9a6d9751d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c5aafccd5656c280e661d3ef3fcbfcc93b5dbf7c14ea277183d9a8f594db66c9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0894407e-994a-4592-bce6-b932c6fe7df7\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Data_extraction_transformation.ipynb\", \"title\": \"Data Extraction and Transformation in ELT Workflows using GPT-4o as an OCR Alternative\", \"tokens\": 5588, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1aeb5cf768435f14a7c4bcc423742864da53c08513e8135043d17c39b503a06\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 22465, \"end_char_idx\": 25559, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "ref_doc_id": "b3208930-1208-4c3e-897b-d2d9a6d9751d", "chroma:document": "''', (\n                    invoice_id,\n                    charge[\"date\"],\n                    charge[\"description\"],\n                    charge[\"charge\"],\n                    charge[\"credit\"]\n                ))\n\n            # Insert Taxes\n            for tax in data[\"taxes\"]:\n                cursor.execute('''\n                INSERT INTO Taxes (invoice_id, tax_type, tax_rate, net_amount, tax_amount, gross_amount) \n                VALUES (?, ?, ?, ?, ?, ?)\n                ''', (\n                    invoice_id,\n                    tax[\"tax_type\"],\n                    tax[\"tax_rate\"],\n                    tax[\"net_amount\"],\n                    tax[\"tax_amount\"],\n                    tax[\"gross_amount\"]\n                ))\n\n    conn.commit()\n    conn.close()\n\n\n```\n\nNow let's check that we've correctly ingested the data by running a sample SQL query to determine the most expensive hotel stay and the same of the hotel!  \nYou can even automate the generation of SQL queries at this step by using function calling, check out our [cookbook on function calling with model generated arguments](https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models#how-to-call-functions-with-model-generated-arguments) to learn how to do that. \n\n\n```python\n\ndef execute_query(db_path, query, params=()):\n    \"\"\"\n    Execute a SQL query and return the results.\n\n    Parameters:\n    db_path (str): Path to the SQLite database file.\n    query (str): SQL query to be executed.\n    params (tuple): Parameters to be passed to the query (default is an empty tuple).\n\n    Returns:\n    list: List of rows returned by the query.\n    \"\"\"\n    try:\n        # Connect to the SQLite database\n        conn = sqlite3.connect(db_path)\n        cursor = conn.cursor()\n\n        # Execute the query with parameters\n        cursor.execute(query, params)\n        results = cursor.fetchall()\n\n        # Commit if it's an INSERT/UPDATE/DELETE query\n        if query.strip().upper().startswith(('INSERT', 'UPDATE', 'DELETE')):\n            conn.commit()\n\n        return results\n    except sqlite3.Error as e:\n        print(f\"An error occurred: {e}\")\n        return []\n    finally:\n        # Close the connection\n        if conn:\n            conn.close()\n\n\n# Example usage\ntransformed_invoices_path = \"./data/hotel_invoices/transformed_invoice_json\"\ndb_path = \"./data/hotel_invoices/hotel_DB.db\"\ningest_transformed_jsons(transformed_invoices_path, db_path)\n\nquery = '''\n    SELECT \n        h.name AS hotel_name,\n        i.total_gross AS max_spent\n    FROM \n        Invoices i\n    JOIN \n        Hotels h ON i.hotel_id = h.hotel_id\n    ORDER BY \n        i.total_gross DESC\n    LIMIT 1;\n    '''\n\nresults = execute_query(db_path, query)\nfor row in results:\n    print(row)\n```\n\n    ('Citadines Michel Hamburg', 903.63)\n\n\nTo recap in this cookbook we showed you how to use GPT-4o for extracting and transforming data that would otherwise be inaccessible for data analysis. If you don't need these workflows to happen in real-time, you can take advantage of OpenAI's BatchAPI to run jobs asynchronously at a much lower cost!"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: f40f496f-4d26-4b2f-8850-e42d3b697304
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb", "title": "Addressing transcription misspellings: prompt vs post-processing", "tokens": 3290, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"f40f496f-4d26-4b2f-8850-e42d3b697304\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"aae74d07-7672-4eb7-a7b3-ab3900f787b3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39c2d8f1b8978601ba8107c272786d8fcace4edc2e74c2d8e8fef500e3320128\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2858e862-67eb-4e04-b2ce-098fbd85b845\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"7b518ba9e713ebc66e02c467319789a95edfc35d2c051671e94c5413a284cb7d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3242, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "ref_doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "chroma:document": "# Addressing transcription misspellings: prompt vs post-processing\n\nWe are addressing the problem of enhancing the precision of transcriptions, particularly when it comes to company names and product references. Our solution involves a dual strategy that utilizes both the Whisper prompt parameter and GPT-4's post-processing capabilities. \n\nTwo approaches to correct inaccuracies are:\n\n- We input a list of correct spellings directly into Whisper's prompt parameter to guide the initial transcription.\n\n- We utilized GPT-4 to fix misspellings post transcription, again using the same list of correct spellings in the prompt.\n\nThese strategies aimed at ensuring precise transcription of unfamilar proper nouns.\n\n## Setup\n\nTo get started, let's:\n\n- Import the OpenAI Python library (if you don't have it, you'll need to install it with ```pip install openai```)\n- Download the audio file example\n\n\n```python\n# imports\nfrom openai import OpenAI  # for making OpenAI API calls\nimport urllib  # for downloading example audio files\nimport os  # for accessing environment variables\n\nclient = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as env var>\"))\n```\n\n\n```python\n# set download paths\nZyntriQix_remote_filepath = \"https://cdn.openai.com/API/examples/data/ZyntriQix.wav\"\n\n\n# set local save locations\nZyntriQix_filepath = \"data/ZyntriQix.wav\"\n\n# download example audio files and save locally\nurllib.request.urlretrieve(ZyntriQix_remote_filepath, ZyntriQix_filepath)\n\n```\n\n\n\n\n    ('data/ZyntriQix.wav', <http.client.HTTPMessage at 0x10559a910>)\n\n\n\n## Setting our baseline with a fictitious audio recording\n\nOur reference point is a monologue, which was generated by ChatGPT from prompts given by the author. The author then voiced this content. So, the author both guided the ChatGPT's output with prompts and brought it to life by speaking it.\n\nOur fictitious company, ZyntriQix, offers a range of tech products. These include Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, and DigiFractal Matrix. We also spearhead several initiatives such as PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., and F.L.I.N.T.\n\n\n```python\n# define a wrapper function for seeing how prompts affect transcriptions\ndef transcribe(prompt: str, audio_filepath) -> str:\n    \"\"\"Given a prompt, transcribe the audio file.\"\"\"\n    transcript = client.audio.transcriptions.create(\n        file=open(audio_filepath, \"rb\"),\n        model=\"whisper-1\",\n        prompt=prompt,\n    )\n    return transcript.text\n\n```\n\n\n```python\n# baseline transcription with no prompt\ntranscribe(prompt=\"\", audio_filepath=ZyntriQix_filepath)\n```\n\n\n\n\n    \"Have you heard of ZentricX? This tech giant boasts products like Digi-Q+, Synapse 5, VortiCore V8, Echo Nix Array, and not to forget the latest Orbital Link 7 and Digifractal Matrix. Their innovation arsenal also includes the Pulse framework, Wrapped system, they've developed a brick infrastructure court system, and launched the Flint initiative, all highlighting their commitment to relentless innovation. ZentricX, in just 30 years, has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\""}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 2858e862-67eb-4e04-b2ce-098fbd85b845
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb", "title": "Addressing transcription misspellings: prompt vs post-processing", "tokens": 3290, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2858e862-67eb-4e04-b2ce-098fbd85b845\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"aae74d07-7672-4eb7-a7b3-ab3900f787b3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39c2d8f1b8978601ba8107c272786d8fcace4edc2e74c2d8e8fef500e3320128\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"f40f496f-4d26-4b2f-8850-e42d3b697304\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c82ac258985a205e1af48d8530015cc25ed4ec3c9a7c3eefe25926a99f171d77\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c3eecdda-d294-46b5-88d2-104e4ca303b8\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"fd1aa4e1e4d91e7b080e337c003778275707283af1308e288d0bfba1c798ae51\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1579, \"end_char_idx\": 4437, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "ref_doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "chroma:document": "## Setting our baseline with a fictitious audio recording\n\nOur reference point is a monologue, which was generated by ChatGPT from prompts given by the author. The author then voiced this content. So, the author both guided the ChatGPT's output with prompts and brought it to life by speaking it.\n\nOur fictitious company, ZyntriQix, offers a range of tech products. These include Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, and DigiFractal Matrix. We also spearhead several initiatives such as PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., and F.L.I.N.T.\n\n\n```python\n# define a wrapper function for seeing how prompts affect transcriptions\ndef transcribe(prompt: str, audio_filepath) -> str:\n    \"\"\"Given a prompt, transcribe the audio file.\"\"\"\n    transcript = client.audio.transcriptions.create(\n        file=open(audio_filepath, \"rb\"),\n        model=\"whisper-1\",\n        prompt=prompt,\n    )\n    return transcript.text\n\n```\n\n\n```python\n# baseline transcription with no prompt\ntranscribe(prompt=\"\", audio_filepath=ZyntriQix_filepath)\n```\n\n\n\n\n    \"Have you heard of ZentricX? This tech giant boasts products like Digi-Q+, Synapse 5, VortiCore V8, Echo Nix Array, and not to forget the latest Orbital Link 7 and Digifractal Matrix. Their innovation arsenal also includes the Pulse framework, Wrapped system, they've developed a brick infrastructure court system, and launched the Flint initiative, all highlighting their commitment to relentless innovation. ZentricX, in just 30 years, has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\"\n\n\n\nWhisper transcribed our company name, product names, and miscapitalized our acronyms incorrectly. Let's pass the correct names as a list in the prompt. \n\n\n```python\n# add the correct spelling names to the prompt\ntranscribe(\n    prompt=\"ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.\",\n    audio_filepath=ZyntriQix_filepath,\n)\n\n```\n\n\n\n\n    \"Have you heard of ZyntriQix? This tech giant boasts products like Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, and not to forget the latest OrbitalLink Seven and DigiFractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system. They've developed a B.R.I.C.K. infrastructure, Q.U.A.R.T. system, and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZyntriQix in just 30 years has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\"\n\n\n\nWhen passing the list of product names, some of the product names are transcribed correctly while others are still misspelled."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: c3eecdda-d294-46b5-88d2-104e4ca303b8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb", "title": "Addressing transcription misspellings: prompt vs post-processing", "tokens": 3290, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c3eecdda-d294-46b5-88d2-104e4ca303b8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"aae74d07-7672-4eb7-a7b3-ab3900f787b3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39c2d8f1b8978601ba8107c272786d8fcace4edc2e74c2d8e8fef500e3320128\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2858e862-67eb-4e04-b2ce-098fbd85b845\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"120eb3beefd1a332e5b68ab37aa743165ec35d9d832587a1e4ab4bb7e7f63bd4\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"54d8facf-c37f-41a1-8f49-39914a816da7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d9d0e44e73f00959b21b3088dfdbf91c5264dd0bd68ed2cf6c3966c6a65d04f4\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3246, \"end_char_idx\": 5845, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "ref_doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "chroma:document": "Whisper transcribed our company name, product names, and miscapitalized our acronyms incorrectly. Let's pass the correct names as a list in the prompt. \n\n\n```python\n# add the correct spelling names to the prompt\ntranscribe(\n    prompt=\"ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.\",\n    audio_filepath=ZyntriQix_filepath,\n)\n\n```\n\n\n\n\n    \"Have you heard of ZyntriQix? This tech giant boasts products like Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, and not to forget the latest OrbitalLink Seven and DigiFractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system. They've developed a B.R.I.C.K. infrastructure, Q.U.A.R.T. system, and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZyntriQix in just 30 years has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\"\n\n\n\nWhen passing the list of product names, some of the product names are transcribed correctly while others are still misspelled. \n\n\n```python\n# add a full product list to the prompt\ntranscribe(\n    prompt=\"ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, AstroPixel Array, QuantumFlare Five, CyberPulse Six, VortexDrive Matrix, PhotonLink Ten, TriCircuit Array, PentaSync Seven, UltraWave Eight, QuantumVertex Nine, HyperHelix X, DigiSpiral Z, PentaQuark Eleven, TetraCube Twelve, GigaPhase Thirteen, EchoNeuron Fourteen, FusionPulse V15, MetaQuark Sixteen, InfiniCircuit Seventeen, TeraPulse Eighteen, ExoMatrix Nineteen, OrbiSync Twenty, QuantumHelix TwentyOne, NanoPhase TwentyTwo, TeraFractal TwentyThree, PentaHelix TwentyFour, ExoCircuit TwentyFive, HyperQuark TwentySix, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.\",\n    audio_filepath=ZyntriQix_filepath,\n)\n\n```\n\n\n\n\n    \"Have you heard of ZentricX? This tech giant boasts products like DigiCube Plus, Synapse 5, VortiCore V8, EchoNix Array, and not to forget the latest Orbital Link 7 and Digifractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system. They've developed a brick infrastructure court system and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZentricX in just 30 years has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\""}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 54d8facf-c37f-41a1-8f49-39914a816da7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb", "title": "Addressing transcription misspellings: prompt vs post-processing", "tokens": 3290, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"54d8facf-c37f-41a1-8f49-39914a816da7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"aae74d07-7672-4eb7-a7b3-ab3900f787b3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39c2d8f1b8978601ba8107c272786d8fcace4edc2e74c2d8e8fef500e3320128\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c3eecdda-d294-46b5-88d2-104e4ca303b8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0d604539fcecff4a4682430a4c4c45f690d9414319ffd51782dab42fac52fbd4\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"12f53668-dd28-4729-8c11-e1f0ff23ba1c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"34e3709e95c510a3fbac983bed67593d5d1728b131ac4787947e0b123661bed9\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4441, \"end_char_idx\": 7027, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "ref_doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "chroma:document": "```python\n# add a full product list to the prompt\ntranscribe(\n    prompt=\"ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, AstroPixel Array, QuantumFlare Five, CyberPulse Six, VortexDrive Matrix, PhotonLink Ten, TriCircuit Array, PentaSync Seven, UltraWave Eight, QuantumVertex Nine, HyperHelix X, DigiSpiral Z, PentaQuark Eleven, TetraCube Twelve, GigaPhase Thirteen, EchoNeuron Fourteen, FusionPulse V15, MetaQuark Sixteen, InfiniCircuit Seventeen, TeraPulse Eighteen, ExoMatrix Nineteen, OrbiSync Twenty, QuantumHelix TwentyOne, NanoPhase TwentyTwo, TeraFractal TwentyThree, PentaHelix TwentyFour, ExoCircuit TwentyFive, HyperQuark TwentySix, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.\",\n    audio_filepath=ZyntriQix_filepath,\n)\n\n```\n\n\n\n\n    \"Have you heard of ZentricX? This tech giant boasts products like DigiCube Plus, Synapse 5, VortiCore V8, EchoNix Array, and not to forget the latest Orbital Link 7 and Digifractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system. They've developed a brick infrastructure court system and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZentricX in just 30 years has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\"\n\n\n\n## You can use GPT-4 to fix spelling mistakes\n\nLeveraging GPT-4 proves especially useful when the speech content is unknown beforehand and we have a list of product names readily available.\n\nThe post-processing technique using GPT-4 is notably more scalable than depending solely on Whisper's prompt parameter, which has a token limit of 244. GPT-4 allows us to process larger lists of correct spellings, making it a more robust method for handling extensive product lists.\n\nHowever, this post-processing technique isn't without limitations. It's constrained by the context window of the chosen model, which may pose challenges when dealing with vast numbers of unique terms. For instance, companies with thousands of SKUs may find that the context window of GPT-4 is insufficient to handle their requirements, and they might need to explore alternative solutions.\n\nInterestingly, the GPT-4 post-processing technique seems more reliable than using Whisper alone. This method, which leverages a product list, enhances the reliability of our results. However, this increased reliability comes at a price, as using this approach can increase costs and can result in higher latency."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 12f53668-dd28-4729-8c11-e1f0ff23ba1c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb", "title": "Addressing transcription misspellings: prompt vs post-processing", "tokens": 3290, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"12f53668-dd28-4729-8c11-e1f0ff23ba1c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"aae74d07-7672-4eb7-a7b3-ab3900f787b3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39c2d8f1b8978601ba8107c272786d8fcace4edc2e74c2d8e8fef500e3320128\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"54d8facf-c37f-41a1-8f49-39914a816da7\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3c4cc78804260ad43e3a3419ab78868f66578662a62093d5143f6c83462fc708\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"5e6fae27-501d-4f01-8007-49756ff0fbaf\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"08631eea4fe162b308a406487cd4892769003c55a54090867b11928d676b21b7\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5250, \"end_char_idx\": 7992, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "ref_doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "chroma:document": "\"Have you heard of ZentricX? This tech giant boasts products like DigiCube Plus, Synapse 5, VortiCore V8, EchoNix Array, and not to forget the latest Orbital Link 7 and Digifractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system. They've developed a brick infrastructure court system and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZentricX in just 30 years has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\"\n\n\n\n## You can use GPT-4 to fix spelling mistakes\n\nLeveraging GPT-4 proves especially useful when the speech content is unknown beforehand and we have a list of product names readily available.\n\nThe post-processing technique using GPT-4 is notably more scalable than depending solely on Whisper's prompt parameter, which has a token limit of 244. GPT-4 allows us to process larger lists of correct spellings, making it a more robust method for handling extensive product lists.\n\nHowever, this post-processing technique isn't without limitations. It's constrained by the context window of the chosen model, which may pose challenges when dealing with vast numbers of unique terms. For instance, companies with thousands of SKUs may find that the context window of GPT-4 is insufficient to handle their requirements, and they might need to explore alternative solutions.\n\nInterestingly, the GPT-4 post-processing technique seems more reliable than using Whisper alone. This method, which leverages a product list, enhances the reliability of our results. However, this increased reliability comes at a price, as using this approach can increase costs and can result in higher latency.\n\n\n```python\n# define a wrapper function for seeing how prompts affect transcriptions\ndef transcribe_with_spellcheck(system_message, audio_filepath):\n    completion = client.chat.completions.create(\n        model=\"gpt-4\",\n        temperature=0,\n        messages=[\n            {\"role\": \"system\", \"content\": system_message},\n            {\n                \"role\": \"user\",\n                \"content\": transcribe(prompt=\"\", audio_filepath=audio_filepath),\n            },\n        ],\n    )\n    return completion.choices[0].message.content\n\n```\n\nNow, let's input the original product list into GPT-4 and evaluate its performance. By doing so, we aim to assess the AI model's ability to correctly spell the proprietary product names, even with no prior knowledge of the exact terms to appear in the transcription. In our experiment, GPT-4 was successful in correctly spelling our product names, confirming its potential as a reliable tool for ensuring transcription accuracy."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 5e6fae27-501d-4f01-8007-49756ff0fbaf
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb", "title": "Addressing transcription misspellings: prompt vs post-processing", "tokens": 3290, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"5e6fae27-501d-4f01-8007-49756ff0fbaf\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"aae74d07-7672-4eb7-a7b3-ab3900f787b3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39c2d8f1b8978601ba8107c272786d8fcace4edc2e74c2d8e8fef500e3320128\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"12f53668-dd28-4729-8c11-e1f0ff23ba1c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"21dee670c7a32672241e95d158bfdf1370b36c9158cde574de22b46ea8a8bab3\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"5ec2bde4-3989-4440-a4ce-6f7e834eae11\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e37ba35fed2a810b7c0bfda41a09100fc726f6062b6574ec1f734284e3a3dc02\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7030, \"end_char_idx\": 9500, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "ref_doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "chroma:document": "```python\n# define a wrapper function for seeing how prompts affect transcriptions\ndef transcribe_with_spellcheck(system_message, audio_filepath):\n    completion = client.chat.completions.create(\n        model=\"gpt-4\",\n        temperature=0,\n        messages=[\n            {\"role\": \"system\", \"content\": system_message},\n            {\n                \"role\": \"user\",\n                \"content\": transcribe(prompt=\"\", audio_filepath=audio_filepath),\n            },\n        ],\n    )\n    return completion.choices[0].message.content\n\n```\n\nNow, let's input the original product list into GPT-4 and evaluate its performance. By doing so, we aim to assess the AI model's ability to correctly spell the proprietary product names, even with no prior knowledge of the exact terms to appear in the transcription. In our experiment, GPT-4 was successful in correctly spelling our product names, confirming its potential as a reliable tool for ensuring transcription accuracy.\n\n\n```python\nsystem_prompt = \"You are a helpful assistant for the company ZyntriQix. Your task is to correct any spelling discrepancies in the transcribed text. Make sure that the names of the following products are spelled correctly: ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.\"\nnew_text = transcribe_with_spellcheck(system_prompt, audio_filepath=ZyntriQix_filepath)\nprint(new_text)\n\n```\n\n    Have you heard of ZyntriQix? This tech giant boasts products like Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, and not to forget the latest OrbitalLink Seven and DigiFractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system, they've developed a B.R.I.C.K. infrastructure court system, and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZyntriQix, in just 30 years, has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\n\n\nIn this case, we supplied a comprehensive product list that included all the previously used spellings, along with additional new names. This scenario simulates a real-life situation where we have a substantial SKU list and uncertain about the exact terms to appear in the transcription. Feeding this extensive list of product names into the system resulted in a correctly transcribed output."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 5ec2bde4-3989-4440-a4ce-6f7e834eae11
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb", "title": "Addressing transcription misspellings: prompt vs post-processing", "tokens": 3290, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"5ec2bde4-3989-4440-a4ce-6f7e834eae11\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"aae74d07-7672-4eb7-a7b3-ab3900f787b3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39c2d8f1b8978601ba8107c272786d8fcace4edc2e74c2d8e8fef500e3320128\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"5e6fae27-501d-4f01-8007-49756ff0fbaf\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f51832ab7e5e77be96791ddd6af50989883525df05d289cd6a19b792b5ec37db\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"52e72084-e565-4d03-b0fa-387272348ae7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"3fbc8c2519418cd8c7731db08c34443dd02a39e7d926e674b5ff3d47bfebccaa\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7995, \"end_char_idx\": 11339, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "ref_doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "chroma:document": "```python\nsystem_prompt = \"You are a helpful assistant for the company ZyntriQix. Your task is to correct any spelling discrepancies in the transcribed text. Make sure that the names of the following products are spelled correctly: ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.\"\nnew_text = transcribe_with_spellcheck(system_prompt, audio_filepath=ZyntriQix_filepath)\nprint(new_text)\n\n```\n\n    Have you heard of ZyntriQix? This tech giant boasts products like Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, and not to forget the latest OrbitalLink Seven and DigiFractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system, they've developed a B.R.I.C.K. infrastructure court system, and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZyntriQix, in just 30 years, has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?\n\n\nIn this case, we supplied a comprehensive product list that included all the previously used spellings, along with additional new names. This scenario simulates a real-life situation where we have a substantial SKU list and uncertain about the exact terms to appear in the transcription. Feeding this extensive list of product names into the system resulted in a correctly transcribed output.\n\n\n```python\nsystem_prompt = \"You are a helpful assistant for the company ZyntriQix. Your task is to correct any spelling discrepancies in the transcribed text. Make sure that the names of the following products are spelled correctly: ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array,  OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, AstroPixel Array, QuantumFlare Five, CyberPulse Six, VortexDrive Matrix, PhotonLink Ten, TriCircuit Array, PentaSync Seven, UltraWave Eight, QuantumVertex Nine, HyperHelix X, DigiSpiral Z, PentaQuark Eleven, TetraCube Twelve, GigaPhase Thirteen, EchoNeuron Fourteen, FusionPulse V15, MetaQuark Sixteen, InfiniCircuit Seventeen, TeraPulse Eighteen, ExoMatrix Nineteen, OrbiSync Twenty, QuantumHelix TwentyOne, NanoPhase TwentyTwo, TeraFractal TwentyThree, PentaHelix TwentyFour, ExoCircuit TwentyFive, HyperQuark TwentySix, GigaLink TwentySeven, FusionMatrix TwentyEight, InfiniFractal TwentyNine, MetaSync Thirty, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T. Only add necessary punctuation such as periods, commas, and capitalization, and use only the context provided.\"\nnew_text = transcribe_with_spellcheck(system_prompt, audio_filepath=ZyntriQix_filepath)\nprint(new_text)\n\n```\n\n    Have you heard of ZyntriQix? This tech giant boasts products like Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, and not to forget the latest OrbitalLink Seven and DigiFractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system, they've developed a B.R.I.C.K. infrastructure court system, and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZyntriQix, in just 30 years, has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 52e72084-e565-4d03-b0fa-387272348ae7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb", "title": "Addressing transcription misspellings: prompt vs post-processing", "tokens": 3290, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"52e72084-e565-4d03-b0fa-387272348ae7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"aae74d07-7672-4eb7-a7b3-ab3900f787b3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39c2d8f1b8978601ba8107c272786d8fcace4edc2e74c2d8e8fef500e3320128\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"5ec2bde4-3989-4440-a4ce-6f7e834eae11\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_correct_misspelling.ipynb\", \"title\": \"Addressing transcription misspellings: prompt vs post-processing\", \"tokens\": 3290, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"163524f91e9753f42b8f52ccbc5af73aa663b419d3d1dba8823afe22a5e08870\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11342, \"end_char_idx\": 13546, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "ref_doc_id": "aae74d07-7672-4eb7-a7b3-ab3900f787b3", "chroma:document": "We are employing GPT-4 as a spell checker, using the same list of correct spellings that was previously used in the prompt.\n\n\n```python\nsystem_prompt = \"You are a helpful assistant for the company ZyntriQix. Your first task is to list the words that are not spelled correctly according to the list provided to you and to tell me the number of misspelled words. Your next task is to insert those correct words in place of the misspelled ones. List: ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array,  OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, AstroPixel Array, QuantumFlare Five, CyberPulse Six, VortexDrive Matrix, PhotonLink Ten, TriCircuit Array, PentaSync Seven, UltraWave Eight, QuantumVertex Nine, HyperHelix X, DigiSpiral Z, PentaQuark Eleven, TetraCube Twelve, GigaPhase Thirteen, EchoNeuron Fourteen, FusionPulse V15, MetaQuark Sixteen, InfiniCircuit Seventeen, TeraPulse Eighteen, ExoMatrix Nineteen, OrbiSync Twenty, QuantumHelix TwentyOne, NanoPhase TwentyTwo, TeraFractal TwentyThree, PentaHelix TwentyFour, ExoCircuit TwentyFive, HyperQuark TwentySix, GigaLink TwentySeven, FusionMatrix TwentyEight, InfiniFractal TwentyNine, MetaSync Thirty, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T.\"\nnew_text = transcribe_with_spellcheck(system_prompt, audio_filepath=ZyntriQix_filepath)\nprint(new_text)\n\n```\n\n    The misspelled words are: ZentricX, Digi-Q+, Synapse 5, VortiCore V8, Echo Nix Array, Orbital Link 7, Digifractal Matrix, Pulse, Wrapped, brick, Flint, and 30. The total number of misspelled words is 12.\n    \n    The corrected paragraph is:\n    \n    Have you heard of ZyntriQix? This tech giant boasts products like Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, and not to forget the latest OrbitalLink Seven and DigiFractal Matrix. Their innovation arsenal also includes the PULSE framework, RAPT system, they've developed a B.R.I.C.K. infrastructure court system, and launched the F.L.I.N.T. initiative, all highlighting their commitment to relentless innovation. ZyntriQix, in just MetaSync Thirty years, has soared from a startup to a tech titan, serving us tech marvels alongside a stimulating linguistic challenge. Quite an adventure, wouldn't you agree?"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 4448a0e0-0064-4694-aa19-685711d16e03
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4448a0e0-0064-4694-aa19-685711d16e03\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"6abf644d-e803-4bc9-a4c7-068dc8da10ab\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8613fc587dc5f0687342e251142ddb1a0570a2d2168a234a4d50623cff80ac4d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 646, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "# How to count tokens with tiktoken\n\n[`tiktoken`](https://github.com/openai/tiktoken/blob/main/README.md) is a fast open-source tokenizer by OpenAI.\n\nGiven a text string (e.g., `\"tiktoken is great!\"`) and an encoding (e.g., `\"cl100k_base\"`), a tokenizer can split the text string into a list of tokens (e.g., `[\"t\", \"ik\", \"token\", \" is\", \" great\", \"!\"]`).\n\nSplitting text strings into tokens is useful because GPT models see text in the form of tokens. Knowing how many tokens are in a text string can tell you (a) whether the string is too long for a text model to process and (b) how much an OpenAI API call costs (as usage is priced by token)."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6abf644d-e803-4bc9-a4c7-068dc8da10ab
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6abf644d-e803-4bc9-a4c7-068dc8da10ab\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"4448a0e0-0064-4694-aa19-685711d16e03\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d21c256f0142935079ecb204caa0fe0182e8872428f564aa7a1e96e52953d79a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e71ff8b0-df40-452a-a575-1de982615cd3\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"10214300116a4c8c575510b9d1bd2b46991a22d87826684dd10576fb6696694e\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2854, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "# How to count tokens with tiktoken\n\n[`tiktoken`](https://github.com/openai/tiktoken/blob/main/README.md) is a fast open-source tokenizer by OpenAI.\n\nGiven a text string (e.g., `\"tiktoken is great!\"`) and an encoding (e.g., `\"cl100k_base\"`), a tokenizer can split the text string into a list of tokens (e.g., `[\"t\", \"ik\", \"token\", \" is\", \" great\", \"!\"]`).\n\nSplitting text strings into tokens is useful because GPT models see text in the form of tokens. Knowing how many tokens are in a text string can tell you (a) whether the string is too long for a text model to process and (b) how much an OpenAI API call costs (as usage is priced by token).\n\n\n## Encodings\n\nEncodings specify how text is converted into tokens. Different models use different encodings.\n\n`tiktoken` supports three encodings used by OpenAI models:\n\n| Encoding name           | OpenAI models                                       |\n|-------------------------|-----------------------------------------------------|\n| `cl100k_base`           | `gpt-4`, `gpt-3.5-turbo`, `text-embedding-ada-002`, `text-embedding-3-small`, `text-embedding-3-large`  |\n| `p50k_base`             | Codex models, `text-davinci-002`, `text-davinci-003`|\n| `r50k_base` (or `gpt2`) | GPT-3 models like `davinci`                         |\n\nYou can retrieve the encoding for a model using `tiktoken.encoding_for_model()` as follows:\n```python\nencoding = tiktoken.encoding_for_model('gpt-3.5-turbo')\n```\n\nNote that `p50k_base` overlaps substantially with `r50k_base`, and for non-code applications, they will usually give the same tokens.\n\n## Tokenizer libraries by language\n\nFor `cl100k_base` and `p50k_base` encodings:\n- Python: [tiktoken](https://github.com/openai/tiktoken/blob/main/README.md)\n- .NET / C#: [SharpToken](https://github.com/dmitry-brazhenko/SharpToken), [TiktokenSharp](https://github.com/aiqinxuancai/TiktokenSharp)\n- Java: [jtokkit](https://github.com/knuddelsgmbh/jtokkit)\n- Golang: [tiktoken-go](https://github.com/pkoukk/tiktoken-go)\n- Rust: [tiktoken-rs](https://github.com/zurawiki/tiktoken-rs)\n\nFor `r50k_base` (`gpt2`) encodings, tokenizers are available in many languages.\n- Python: [tiktoken](https://github.com/openai/tiktoken/blob/main/README.md) (or alternatively [GPT2TokenizerFast](https://huggingface.co/docs/transformers/model_doc/gpt2#transformers.GPT2TokenizerFast))\n- JavaScript: [gpt-3-encoder](https://www.npmjs.com/package/gpt-3-encoder)\n- .NET / C#: [GPT Tokenizer](https://github.com/dluc/openai-tools)\n- Java: [gpt2-tokenizer-java](https://github.com/hyunwoongko/gpt2-tokenizer-java)\n- PHP: [GPT-3-Encoder-PHP](https://github.com/CodeRevolutionPlugins/GPT-3-Encoder-PHP)\n- Golang: [tiktoken-go](https://github.com/pkoukk/tiktoken-go)\n- Rust: [tiktoken-rs](https://github.com/zurawiki/tiktoken-rs)\n\n(OpenAI makes no endorsements or guarantees of third-party libraries.)"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: e71ff8b0-df40-452a-a575-1de982615cd3
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e71ff8b0-df40-452a-a575-1de982615cd3\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"6abf644d-e803-4bc9-a4c7-068dc8da10ab\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e14ca7e9409b843d24ecb8140be860f9a04babf89455793fcae1eb4ebfe89a77\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e396d4f6-66b2-4d94-a5e4-b0bc872760a9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5f20f0adf8ce5bceb5ac15a2519bd4e9c85075280992b6b721c8234f6bbc2a9d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2857, \"end_char_idx\": 5611, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "## How strings are typically tokenized\n\nIn English, tokens commonly range in length from one character to one word (e.g., `\"t\"` or `\" great\"`), though in some languages tokens can be shorter than one character or longer than one word. Spaces are usually grouped with the starts of words (e.g., `\" is\"` instead of `\"is \"` or `\" \"`+`\"is\"`). You can quickly check how a string is tokenized at the [OpenAI Tokenizer](https://beta.openai.com/tokenizer), or the third-party [Tiktokenizer](https://tiktokenizer.vercel.app/) webapp.\n\n## 0. Install `tiktoken`\n\nIf needed, install `tiktoken` with `pip`:\n\n\n```python\n%pip install --upgrade tiktoken\n%pip install --upgrade openai\n```\n\n## 1. Import `tiktoken`\n\n\n```python\nimport tiktoken\n```\n\n## 2. Load an encoding\n\nUse `tiktoken.get_encoding()` to load an encoding by name.\n\nThe first time this runs, it will require an internet connection to download. Later runs won't need an internet connection.\n\n\n```python\nencoding = tiktoken.get_encoding(\"cl100k_base\")\n\n```\n\nUse `tiktoken.encoding_for_model()` to automatically load the correct encoding for a given model name.\n\n\n```python\nencoding = tiktoken.encoding_for_model(\"gpt-3.5-turbo\")\n```\n\n## 3. Turn text into tokens with `encoding.encode()`\n\n\n\nThe `.encode()` method converts a text string into a list of token integers.\n\n\n```python\nencoding.encode(\"tiktoken is great!\")\n\n```\n\n\n\n\n    [83, 1609, 5963, 374, 2294, 0]\n\n\n\nCount tokens by counting the length of the list returned by `.encode()`.\n\n\n```python\ndef num_tokens_from_string(string: str, encoding_name: str) -> int:\n    \"\"\"Returns the number of tokens in a text string.\"\"\"\n    encoding = tiktoken.get_encoding(encoding_name)\n    num_tokens = len(encoding.encode(string))\n    return num_tokens\n\n```\n\n\n```python\nnum_tokens_from_string(\"tiktoken is great!\", \"cl100k_base\")\n\n```\n\n\n\n\n    6\n\n\n\n## 4. Turn tokens into text with `encoding.decode()`\n\n`.decode()` converts a list of token integers to a string.\n\n\n```python\nencoding.decode([83, 1609, 5963, 374, 2294, 0])\n\n```\n\n\n\n\n    'tiktoken is great!'\n\n\n\nWarning: although `.decode()` can be applied to single tokens, beware that it can be lossy for tokens that aren't on utf-8 boundaries.\n\nFor single tokens, `.decode_single_token_bytes()` safely converts a single integer token to the bytes it represents.\n\n\n```python\n[encoding.decode_single_token_bytes(token) for token in [83, 1609, 5963, 374, 2294, 0]]\n\n```\n\n\n\n\n    [b't', b'ik', b'token', b' is', b' great', b'!']\n\n\n\n(The `b` in front of the strings indicates that the strings are byte strings.)\n\n## 5. Comparing encodings\n\nDifferent encodings vary in how they split words, group spaces, and handle non-English characters. Using the methods above, we can compare different encodings on a few example strings."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: e396d4f6-66b2-4d94-a5e4-b0bc872760a9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e396d4f6-66b2-4d94-a5e4-b0bc872760a9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"e71ff8b0-df40-452a-a575-1de982615cd3\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"83d0d3ab376671102c64307526a4a1c9732831c178981ec59269372844d5b798\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"3c36ceb9-588f-49fd-8371-5d115edaa79f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a90d6f1720873c9224df6a0a2322a0f531f2c1ac4743b5f2246e57fac9b830ad\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4093, \"end_char_idx\": 6398, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "The `.encode()` method converts a text string into a list of token integers.\n\n\n```python\nencoding.encode(\"tiktoken is great!\")\n\n```\n\n\n\n\n    [83, 1609, 5963, 374, 2294, 0]\n\n\n\nCount tokens by counting the length of the list returned by `.encode()`.\n\n\n```python\ndef num_tokens_from_string(string: str, encoding_name: str) -> int:\n    \"\"\"Returns the number of tokens in a text string.\"\"\"\n    encoding = tiktoken.get_encoding(encoding_name)\n    num_tokens = len(encoding.encode(string))\n    return num_tokens\n\n```\n\n\n```python\nnum_tokens_from_string(\"tiktoken is great!\", \"cl100k_base\")\n\n```\n\n\n\n\n    6\n\n\n\n## 4. Turn tokens into text with `encoding.decode()`\n\n`.decode()` converts a list of token integers to a string.\n\n\n```python\nencoding.decode([83, 1609, 5963, 374, 2294, 0])\n\n```\n\n\n\n\n    'tiktoken is great!'\n\n\n\nWarning: although `.decode()` can be applied to single tokens, beware that it can be lossy for tokens that aren't on utf-8 boundaries.\n\nFor single tokens, `.decode_single_token_bytes()` safely converts a single integer token to the bytes it represents.\n\n\n```python\n[encoding.decode_single_token_bytes(token) for token in [83, 1609, 5963, 374, 2294, 0]]\n\n```\n\n\n\n\n    [b't', b'ik', b'token', b' is', b' great', b'!']\n\n\n\n(The `b` in front of the strings indicates that the strings are byte strings.)\n\n## 5. Comparing encodings\n\nDifferent encodings vary in how they split words, group spaces, and handle non-English characters. Using the methods above, we can compare different encodings on a few example strings.\n\n\n```python\ndef compare_encodings(example_string: str) -> None:\n    \"\"\"Prints a comparison of three string encodings.\"\"\"\n    # print the example string\n    print(f'\\nExample string: \"{example_string}\"')\n    # for each encoding, print the # of tokens, the token integers, and the token bytes\n    for encoding_name in [\"r50k_base\", \"p50k_base\", \"cl100k_base\"]:\n        encoding = tiktoken.get_encoding(encoding_name)\n        token_integers = encoding.encode(example_string)\n        num_tokens = len(token_integers)\n        token_bytes = [encoding.decode_single_token_bytes(token) for token in token_integers]\n        print()\n        print(f\"{encoding_name}: {num_tokens} tokens\")\n        print(f\"token integers: {token_integers}\")\n        print(f\"token bytes: {token_bytes}\")\n        \n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 3c36ceb9-588f-49fd-8371-5d115edaa79f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3c36ceb9-588f-49fd-8371-5d115edaa79f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"e396d4f6-66b2-4d94-a5e4-b0bc872760a9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3c928bba23d1fcc40943b534432d3c96a95f29d25514e572de8415f0d15118c8\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a4e7d9c7-1444-4c92-bd8a-96b69fccba5a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1039ed747ba0ca3a4d91e1254dbe0f924726afa76a334329a3b983e79a8c10d2\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4807, \"end_char_idx\": 6990, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "```python\nencoding.decode([83, 1609, 5963, 374, 2294, 0])\n\n```\n\n\n\n\n    'tiktoken is great!'\n\n\n\nWarning: although `.decode()` can be applied to single tokens, beware that it can be lossy for tokens that aren't on utf-8 boundaries.\n\nFor single tokens, `.decode_single_token_bytes()` safely converts a single integer token to the bytes it represents.\n\n\n```python\n[encoding.decode_single_token_bytes(token) for token in [83, 1609, 5963, 374, 2294, 0]]\n\n```\n\n\n\n\n    [b't', b'ik', b'token', b' is', b' great', b'!']\n\n\n\n(The `b` in front of the strings indicates that the strings are byte strings.)\n\n## 5. Comparing encodings\n\nDifferent encodings vary in how they split words, group spaces, and handle non-English characters. Using the methods above, we can compare different encodings on a few example strings.\n\n\n```python\ndef compare_encodings(example_string: str) -> None:\n    \"\"\"Prints a comparison of three string encodings.\"\"\"\n    # print the example string\n    print(f'\\nExample string: \"{example_string}\"')\n    # for each encoding, print the # of tokens, the token integers, and the token bytes\n    for encoding_name in [\"r50k_base\", \"p50k_base\", \"cl100k_base\"]:\n        encoding = tiktoken.get_encoding(encoding_name)\n        token_integers = encoding.encode(example_string)\n        num_tokens = len(token_integers)\n        token_bytes = [encoding.decode_single_token_bytes(token) for token in token_integers]\n        print()\n        print(f\"{encoding_name}: {num_tokens} tokens\")\n        print(f\"token integers: {token_integers}\")\n        print(f\"token bytes: {token_bytes}\")\n        \n```\n\n\n```python\ncompare_encodings(\"antidisestablishmentarianism\")\n\n```\n\n    \n    Example string: \"antidisestablishmentarianism\"\n    \n    r50k_base: 5 tokens\n    token integers: [415, 29207, 44390, 3699, 1042]\n    token bytes: [b'ant', b'idis', b'establishment', b'arian', b'ism']\n    \n    p50k_base: 5 tokens\n    token integers: [415, 29207, 44390, 3699, 1042]\n    token bytes: [b'ant', b'idis', b'establishment', b'arian', b'ism']\n    \n    cl100k_base: 6 tokens\n    token integers: [519, 85342, 34500, 479, 8997, 2191]\n    token bytes: [b'ant', b'idis', b'establish', b'ment', b'arian', b'ism']"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: a4e7d9c7-1444-4c92-bd8a-96b69fccba5a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a4e7d9c7-1444-4c92-bd8a-96b69fccba5a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"3c36ceb9-588f-49fd-8371-5d115edaa79f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c1669c9b11ae9f19e393246178c7e2ae0f6d8c2b6daa3493324d93bd4a49b667\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"670420e5-8e8d-4feb-a498-240d887a74ca\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"fcdb6a13cd4eaaab477aacdaf26f46c51eb9596640f2e6e919a676a3abf1fa52\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5614, \"end_char_idx\": 7477, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "```python\ndef compare_encodings(example_string: str) -> None:\n    \"\"\"Prints a comparison of three string encodings.\"\"\"\n    # print the example string\n    print(f'\\nExample string: \"{example_string}\"')\n    # for each encoding, print the # of tokens, the token integers, and the token bytes\n    for encoding_name in [\"r50k_base\", \"p50k_base\", \"cl100k_base\"]:\n        encoding = tiktoken.get_encoding(encoding_name)\n        token_integers = encoding.encode(example_string)\n        num_tokens = len(token_integers)\n        token_bytes = [encoding.decode_single_token_bytes(token) for token in token_integers]\n        print()\n        print(f\"{encoding_name}: {num_tokens} tokens\")\n        print(f\"token integers: {token_integers}\")\n        print(f\"token bytes: {token_bytes}\")\n        \n```\n\n\n```python\ncompare_encodings(\"antidisestablishmentarianism\")\n\n```\n\n    \n    Example string: \"antidisestablishmentarianism\"\n    \n    r50k_base: 5 tokens\n    token integers: [415, 29207, 44390, 3699, 1042]\n    token bytes: [b'ant', b'idis', b'establishment', b'arian', b'ism']\n    \n    p50k_base: 5 tokens\n    token integers: [415, 29207, 44390, 3699, 1042]\n    token bytes: [b'ant', b'idis', b'establishment', b'arian', b'ism']\n    \n    cl100k_base: 6 tokens\n    token integers: [519, 85342, 34500, 479, 8997, 2191]\n    token bytes: [b'ant', b'idis', b'establish', b'ment', b'arian', b'ism']\n\n\n\n```python\ncompare_encodings(\"2 + 2 = 4\")\n\n```\n\n    \n    Example string: \"2 + 2 = 4\"\n    \n    r50k_base: 5 tokens\n    token integers: [17, 1343, 362, 796, 604]\n    token bytes: [b'2', b' +', b' 2', b' =', b' 4']\n    \n    p50k_base: 5 tokens\n    token integers: [17, 1343, 362, 796, 604]\n    token bytes: [b'2', b' +', b' 2', b' =', b' 4']\n    \n    cl100k_base: 7 tokens\n    token integers: [17, 489, 220, 17, 284, 220, 19]\n    token bytes: [b'2', b' +', b' ', b'2', b' =', b' ', b'4']"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 670420e5-8e8d-4feb-a498-240d887a74ca
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"670420e5-8e8d-4feb-a498-240d887a74ca\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a4e7d9c7-1444-4c92-bd8a-96b69fccba5a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a9023ee099a1f5924470f3e973643aae7c362640a60961cdaee43476721d1e80\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7d36950b-3740-41e2-8dbe-9ac584771765\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"3d309d032a9d1d00db9e8c43a44bfff0e5da75aac5aa1f59a8afc31d3bd971fe\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6994, \"end_char_idx\": 8509, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "```python\ncompare_encodings(\"2 + 2 = 4\")\n\n```\n\n    \n    Example string: \"2 + 2 = 4\"\n    \n    r50k_base: 5 tokens\n    token integers: [17, 1343, 362, 796, 604]\n    token bytes: [b'2', b' +', b' 2', b' =', b' 4']\n    \n    p50k_base: 5 tokens\n    token integers: [17, 1343, 362, 796, 604]\n    token bytes: [b'2', b' +', b' 2', b' =', b' 4']\n    \n    cl100k_base: 7 tokens\n    token integers: [17, 489, 220, 17, 284, 220, 19]\n    token bytes: [b'2', b' +', b' ', b'2', b' =', b' ', b'4']\n\n\n\n```python\ncompare_encodings(\"\u304a\u8a95\u751f\u65e5\u304a\u3081\u3067\u3068\u3046\")\n\n```\n\n    \n    Example string: \"\u304a\u8a95\u751f\u65e5\u304a\u3081\u3067\u3068\u3046\"\n    \n    r50k_base: 14 tokens\n    token integers: [2515, 232, 45739, 243, 37955, 33768, 98, 2515, 232, 1792, 223, 30640, 30201, 29557]\n    token bytes: [b'\\xe3\\x81', b'\\x8a', b'\\xe8\\xaa', b'\\x95', b'\\xe7\\x94\\x9f', b'\\xe6\\x97', b'\\xa5', b'\\xe3\\x81', b'\\x8a', b'\\xe3\\x82', b'\\x81', b'\\xe3\\x81\\xa7', b'\\xe3\\x81\\xa8', b'\\xe3\\x81\\x86']\n    \n    p50k_base: 14 tokens\n    token integers: [2515, 232, 45739, 243, 37955, 33768, 98, 2515, 232, 1792, 223, 30640, 30201, 29557]\n    token bytes: [b'\\xe3\\x81', b'\\x8a', b'\\xe8\\xaa', b'\\x95', b'\\xe7\\x94\\x9f', b'\\xe6\\x97', b'\\xa5', b'\\xe3\\x81', b'\\x8a', b'\\xe3\\x82', b'\\x81', b'\\xe3\\x81\\xa7', b'\\xe3\\x81\\xa8', b'\\xe3\\x81\\x86']\n    \n    cl100k_base: 9 tokens\n    token integers: [33334, 45918, 243, 21990, 9080, 33334, 62004, 16556, 78699]\n    token bytes: [b'\\xe3\\x81\\x8a', b'\\xe8\\xaa', b'\\x95', b'\\xe7\\x94\\x9f', b'\\xe6\\x97\\xa5', b'\\xe3\\x81\\x8a', b'\\xe3\\x82\\x81', b'\\xe3\\x81\\xa7', b'\\xe3\\x81\\xa8\\xe3\\x81\\x86']"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 7d36950b-3740-41e2-8dbe-9ac584771765
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7d36950b-3740-41e2-8dbe-9ac584771765\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"670420e5-8e8d-4feb-a498-240d887a74ca\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"9254417df6db12cea38894e11aefd727dbe57ea073d75ff5c3d6c10aed996732\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7e631eff-5953-44b8-ab78-c2125a747bee\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"c28e869a313ffc9a25786287c99c77ba796ee77d7bca037aa452a37ea352531d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8512, \"end_char_idx\": 10942, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "## 6. Counting tokens for chat completions API calls\n\nChatGPT models like `gpt-3.5-turbo` and `gpt-4` use tokens in the same way as older completions models, but because of their message-based formatting, it's more difficult to count how many tokens will be used by a conversation.\n\nBelow is an example function for counting tokens for messages passed to `gpt-3.5-turbo` or `gpt-4`.\n\nNote that the exact way that tokens are counted from messages may change from model to model. Consider the counts from the function below an estimate, not a timeless guarantee.\n\nIn particular, requests that use the optional functions input will consume extra tokens on top of the estimates calculated below.\n\n\n```python\ndef num_tokens_from_messages(messages, model=\"gpt-3.5-turbo-0613\"):\n    \"\"\"Return the number of tokens used by a list of messages.\"\"\"\n    try:\n        encoding = tiktoken.encoding_for_model(model)\n    except KeyError:\n        print(\"Warning: model not found. Using cl100k_base encoding.\")\n        encoding = tiktoken.get_encoding(\"cl100k_base\")\n    if model in {\n        \"gpt-3.5-turbo-0613\",\n        \"gpt-3.5-turbo-16k-0613\",\n        \"gpt-4-0314\",\n        \"gpt-4-32k-0314\",\n        \"gpt-4-0613\",\n        \"gpt-4-32k-0613\",\n        }:\n        tokens_per_message = 3\n        tokens_per_name = 1\n    elif model == \"gpt-3.5-turbo-0301\":\n        tokens_per_message = 4  # every message follows <|start|>{role/name}\\n{content}<|end|>\\n\n        tokens_per_name = -1  # if there's a name, the role is omitted\n    elif \"gpt-3.5-turbo\" in model:\n        print(\"Warning: gpt-3.5-turbo may update over time. Returning num tokens assuming gpt-3.5-turbo-0613.\")\n        return num_tokens_from_messages(messages, model=\"gpt-3.5-turbo-0613\")\n    elif \"gpt-4\" in model:\n        print(\"Warning: gpt-4 may update over time. Returning num tokens assuming gpt-4-0613.\")\n        return num_tokens_from_messages(messages, model=\"gpt-4-0613\")\n    else:\n        raise NotImplementedError(\n            f\"\"\"num_tokens_from_messages() is not implemented for model {model}.\"\"\"\n        )\n    num_tokens = 0\n    for message in messages:\n        num_tokens += tokens_per_message\n        for key, value in message.items():\n            num_tokens += len(encoding.encode(value))\n            if key == \"name\":\n                num_tokens += tokens_per_name\n    num_tokens += 3  # every reply is primed with <|start|>assistant<|message|>\n    return num_tokens\n\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 7e631eff-5953-44b8-ab78-c2125a747bee
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb", "title": "How to count tokens with tiktoken", "tokens": 4040, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7e631eff-5953-44b8-ab78-c2125a747bee\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7975c8a7-a812-476d-8b57-ec5955526040\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75578ea97075a1210a2c40a6776cf0b9153a7aeb2fb6dd52d5f0f84c303bd94b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"7d36950b-3740-41e2-8dbe-9ac584771765\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb\", \"title\": \"How to count tokens with tiktoken\", \"tokens\": 4040, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"91ee38ccde15f2fa87758bf7a9897dca83a6be988aaf6bbc36a3c0b23373ed6a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10945, \"end_char_idx\": 13748, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7975c8a7-a812-476d-8b57-ec5955526040", "doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "ref_doc_id": "7975c8a7-a812-476d-8b57-ec5955526040", "chroma:document": "```python\n# let's verify the function above matches the OpenAI API response\n\nfrom openai import OpenAI\nimport os\n\nclient = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as env var>\"))\n\nexample_messages = [\n    {\n        \"role\": \"system\",\n        \"content\": \"You are a helpful, pattern-following assistant that translates corporate jargon into plain English.\",\n    },\n    {\n        \"role\": \"system\",\n        \"name\": \"example_user\",\n        \"content\": \"New synergies will help drive top-line growth.\",\n    },\n    {\n        \"role\": \"system\",\n        \"name\": \"example_assistant\",\n        \"content\": \"Things working well together will increase revenue.\",\n    },\n    {\n        \"role\": \"system\",\n        \"name\": \"example_user\",\n        \"content\": \"Let's circle back when we have more bandwidth to touch base on opportunities for increased leverage.\",\n    },\n    {\n        \"role\": \"system\",\n        \"name\": \"example_assistant\",\n        \"content\": \"Let's talk later when we're less busy about how to do better.\",\n    },\n    {\n        \"role\": \"user\",\n        \"content\": \"This late pivot means we don't have time to boil the ocean for the client deliverable.\",\n    },\n]\n\nfor model in [\n    \"gpt-3.5-turbo-0301\",\n    \"gpt-3.5-turbo-0613\",\n    \"gpt-3.5-turbo\",\n    \"gpt-4-0314\",\n    \"gpt-4-0613\",\n    \"gpt-4\",\n    ]:\n    print(model)\n    # example token count from the function defined above\n    print(f\"{num_tokens_from_messages(example_messages, model)} prompt tokens counted by num_tokens_from_messages().\")\n    # example token count from the OpenAI API\n    response = client.chat.completions.create(model=model,\n    messages=example_messages,\n    temperature=0,\n    max_tokens=1)\n    print(f'{response.usage.prompt_tokens} prompt tokens counted by the OpenAI API.')\n    print()\n\n```\n\n    gpt-3.5-turbo-0301\n    127 prompt tokens counted by num_tokens_from_messages().\n    127 prompt tokens counted by the OpenAI API.\n    \n    gpt-3.5-turbo-0613\n    129 prompt tokens counted by num_tokens_from_messages().\n    129 prompt tokens counted by the OpenAI API.\n    \n    gpt-3.5-turbo\n    Warning: gpt-3.5-turbo may update over time. Returning num tokens assuming gpt-3.5-turbo-0613.\n    129 prompt tokens counted by num_tokens_from_messages().\n    129 prompt tokens counted by the OpenAI API.\n    \n    gpt-4-0314\n    129 prompt tokens counted by num_tokens_from_messages().\n    129 prompt tokens counted by the OpenAI API.\n    \n    gpt-4-0613\n    129 prompt tokens counted by num_tokens_from_messages().\n    129 prompt tokens counted by the OpenAI API.\n    \n    gpt-4\n    Warning: gpt-4 may update over time. Returning num tokens assuming gpt-4-0613.\n    129 prompt tokens counted by num_tokens_from_messages().\n    129 prompt tokens counted by the OpenAI API.\n    \n\n\n\n```python\n\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 155c7bbe-4604-452a-8f64-fe96718a3ff6
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"155c7bbe-4604-452a-8f64-fe96718a3ff6\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e401e314-adda-45d3-8bdb-63677aa5f69d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"768ce9614a37a0961decf109e2f9951a976a1b692d4b3178fedb2ff0c78da317\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3070, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "# How to build a tool-using agent with LangChain\n\nThis notebook takes you through how to use LangChain to augment an OpenAI model with access to external tools. In particular, you'll be able to create LLM agents that use custom tools to answer user queries.\n\n\n## What is Langchain?\n[LangChain](https://python.langchain.com/en/latest/index.html) is a framework for developing applications powered by language models. Their framework enables you to build layered LLM-powered applications that are context-aware and able to interact dynamically with their environment as agents, leading to simplified code for you and a more dynamic user experience for your customers.\n\n## Why do LLMs need to use Tools?\nOne of the most common challenges with LLMs is overcoming the lack of recency and specificity in their training data - answers can be out of date, and they are prone to hallucinations given the huge variety in their knowledge base. Tools are a great method of allowing an LLM to answer within a controlled context that draws on your existing knowledge bases and internal APIs - instead of trying to prompt engineer the LLM all the way to your intended answer, you allow it access to tools that it calls on dynamically for info, parses, and serves to customer. \n\nProviding LLMs access to tools can enable them to answer questions with context directly from search engines, APIs or your own databases. Instead of answering directly, an LLM with access to tools can perform intermediate steps to gather relevant information. Tools can also be used in combination. [For example](https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html), a language model can be made to use a search tool to lookup quantitative information and a calculator to execute calculations.\n\n## Notebook Sections\n\n- **Setup:** Import packages and connect to a Pinecone vector database.\n- **LLM Agent:** Build an agent that leverages a modified version of the [ReAct](https://react-lm.github.io/) framework to do chain-of-thought reasoning.\n- **LLM Agent with History:** Provide the LLM with access to previous steps in the conversation.\n- **Knowledge Base:** Create a knowledge base of \"Stuff You Should Know\" podcast episodes, to be accessed through a tool.\n- **LLM Agent with Tools:** Extend the agent with access to multiple tools and test that it uses them to answer questions.\n\n\n```python\n%load_ext autoreload\n%autoreload 2\n```\n\n    The autoreload extension is already loaded. To reload it, use:\n      %reload_ext autoreload\n\n\n# Setup\n\nImport libraries and set up a connection to a [Pinecone](https://www.pinecone.io) vector database.\n\nYou can substitute Pinecone for any other vectorstore or database - there are a [selection](https://python.langchain.com/en/latest/modules/indexes/vectorstores.html) that are supported by Langchain natively, while other connectors will need to be developed yourself.\n\n\n```python\n!pip install openai\n!pip install pinecone-client\n!pip install pandas\n!pip install typing\n!pip install tqdm\n!pip install langchain\n!pip install wget\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: e401e314-adda-45d3-8bdb-63677aa5f69d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e401e314-adda-45d3-8bdb-63677aa5f69d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"155c7bbe-4604-452a-8f64-fe96718a3ff6\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"1f433d1a2417f70ff7e35944d4073bb747e2c6237e18e0354c34d9525a188be8\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"8532508b-1775-4c10-879a-cf52a4799325\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"516dc9106fd66ade7ab5d0e495a38626a671e05ac5a9e8398db05b02a19ac6b3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2383, \"end_char_idx\": 4468, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\n%load_ext autoreload\n%autoreload 2\n```\n\n    The autoreload extension is already loaded. To reload it, use:\n      %reload_ext autoreload\n\n\n# Setup\n\nImport libraries and set up a connection to a [Pinecone](https://www.pinecone.io) vector database.\n\nYou can substitute Pinecone for any other vectorstore or database - there are a [selection](https://python.langchain.com/en/latest/modules/indexes/vectorstores.html) that are supported by Langchain natively, while other connectors will need to be developed yourself.\n\n\n```python\n!pip install openai\n!pip install pinecone-client\n!pip install pandas\n!pip install typing\n!pip install tqdm\n!pip install langchain\n!pip install wget\n```\n\n\n```python\nimport datetime\nimport json\nimport openai\nimport os\nimport pandas as pd\nimport pinecone\nimport re\nfrom tqdm.auto import tqdm\nfrom typing import List, Union\nimport zipfile\n\n# Langchain imports\nfrom langchain.agents import Tool, AgentExecutor, LLMSingleActionAgent, AgentOutputParser\nfrom langchain.prompts import BaseChatPromptTemplate, ChatPromptTemplate\nfrom langchain import SerpAPIWrapper, LLMChain\nfrom langchain.schema import AgentAction, AgentFinish, HumanMessage, SystemMessage\n# LLM wrapper\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain import OpenAI\n# Conversational memory\nfrom langchain.memory import ConversationBufferWindowMemory\n# Embeddings and vectorstore\nfrom langchain.embeddings.openai import OpenAIEmbeddings\nfrom langchain.vectorstores import Pinecone\n\n# Vectorstore Index\nindex_name = 'podcasts'\n```\n\nFor acquiring an API key to connect with Pinecone, you can set up a [free account](https://app.pinecone.io/) and store it in the `api_key` variable below or in your environment variables under `PINECONE_API_KEY`\n\n\n```python\napi_key = os.getenv(\"PINECONE_API_KEY\") or \"PINECONE_API_KEY\"\n\n# find environment next to your API key in the Pinecone console\nenv = os.getenv(\"PINECONE_ENVIRONMENT\") or \"PINECONE_ENVIRONMENT\"\n\npinecone.init(api_key=api_key, environment=env)\npinecone.whoami()\n```\n\n\n```python\npinecone.list_indexes()\n```\n\n\n\n\n    ['podcasts']"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 8532508b-1775-4c10-879a-cf52a4799325
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"8532508b-1775-4c10-879a-cf52a4799325\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"e401e314-adda-45d3-8bdb-63677aa5f69d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"c6e0f40c3571b202b6679870739189583ad0baf9cc2a079065e5ae32fd0c2ff9\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"570d61ff-b15d-48d4-963c-af923782747c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"2e6a215fee870c25a15ef52856536ccc0ae11a09e95c6914720444f40132400d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2909, \"end_char_idx\": 6927, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\n!pip install openai\n!pip install pinecone-client\n!pip install pandas\n!pip install typing\n!pip install tqdm\n!pip install langchain\n!pip install wget\n```\n\n\n```python\nimport datetime\nimport json\nimport openai\nimport os\nimport pandas as pd\nimport pinecone\nimport re\nfrom tqdm.auto import tqdm\nfrom typing import List, Union\nimport zipfile\n\n# Langchain imports\nfrom langchain.agents import Tool, AgentExecutor, LLMSingleActionAgent, AgentOutputParser\nfrom langchain.prompts import BaseChatPromptTemplate, ChatPromptTemplate\nfrom langchain import SerpAPIWrapper, LLMChain\nfrom langchain.schema import AgentAction, AgentFinish, HumanMessage, SystemMessage\n# LLM wrapper\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain import OpenAI\n# Conversational memory\nfrom langchain.memory import ConversationBufferWindowMemory\n# Embeddings and vectorstore\nfrom langchain.embeddings.openai import OpenAIEmbeddings\nfrom langchain.vectorstores import Pinecone\n\n# Vectorstore Index\nindex_name = 'podcasts'\n```\n\nFor acquiring an API key to connect with Pinecone, you can set up a [free account](https://app.pinecone.io/) and store it in the `api_key` variable below or in your environment variables under `PINECONE_API_KEY`\n\n\n```python\napi_key = os.getenv(\"PINECONE_API_KEY\") or \"PINECONE_API_KEY\"\n\n# find environment next to your API key in the Pinecone console\nenv = os.getenv(\"PINECONE_ENVIRONMENT\") or \"PINECONE_ENVIRONMENT\"\n\npinecone.init(api_key=api_key, environment=env)\npinecone.whoami()\n```\n\n\n```python\npinecone.list_indexes()\n```\n\n\n\n\n    ['podcasts']\n\n\n\nRun this code block if you want to clear the index, or if the index doesn't exist yet\n\n```\n# Check whether the index with the same name already exists - if so, delete it\nif index_name in pinecone.list_indexes():\n    pinecone.delete_index(index_name)\n    \n# Creates new index\npinecone.create_index(name=index_name, dimension=1536)\nindex = pinecone.Index(index_name=index_name)\n\n# Confirm our index was created\npinecone.list_indexes()\n```\n\n## LLM Agent\n\nAn [LLM agent](https://python.langchain.com/docs/modules/agents/) in Langchain has many configurable components, which are detailed in the Langchain documentation.\n\nWe'll employ a few of the core concepts to make an agent that talks in the way we want, can use tools to answer questions, and uses the appropriate language model to power the conversation.\n- **Prompt Template:** The input template to control the LLM's behaviour and how it accepts inputs and produces outputs - this is the brain that drives your application ([docs](https://python.langchain.com/en/latest/modules/prompts/prompt_templates.html)).\n- **Output Parser:** A method of parsing the output from the prompt. If the LLM produces output using certain headers, you can enable complex interactions where variables are generated by the LLM in their response and passed into the next step of the chain ([docs](https://python.langchain.com/en/latest/modules/prompts/output_parsers.html)).\n- **LLM Chain:** A Chain brings together a prompt template with an LLM that will execute it - in this case we'll be using ```gpt-3.5-turbo``` but this framework can be used with OpenAI completions models, or other LLMs entirely ([docs](https://python.langchain.com/en/latest/modules/chains.html)).\n- **Tool:** An external service that the LLM can use to retrieve information or execute commands should the user require it ([docs](https://python.langchain.com/en/latest/modules/agents/tools.html)).\n- **Agent:** The glue that brings all of this together, an agent can call multiple LLM Chains, each with their own tools. Agents can be extended with your own logic to allow retries, error handling and any other methods you choose to add reliability to your application ([docs](https://python.langchain.com/en/latest/modules/agents.html)).\n\n**NB:** Before using this cookbook with the Search tool you'll need to sign up on https://serpapi.com/ and generate an API key. Once you have it, store it in an environment variable named ```SERPAPI_API_KEY```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 570d61ff-b15d-48d4-963c-af923782747c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"570d61ff-b15d-48d4-963c-af923782747c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"8532508b-1775-4c10-879a-cf52a4799325\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"69d2dc254a35579e1796ad65754008992082faeb6e4c54d457deaa424355b431\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"74116c2f-6c86-4660-ba03-dac4bc72c31b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a5902baf3d62b4762b17a3c3128b311b534d4d05d86c950bdc695e8338fa4a90\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6930, \"end_char_idx\": 9600, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\n# Initiate a Search tool - note you'll need to have set SERPAPI_API_KEY as an environment variable as per the above instructions\nsearch = SerpAPIWrapper()\n\n# Define a list of tools\ntools = [\n    Tool(\n        name = \"Search\",\n        func=search.run,\n        description=\"useful for when you need to answer questions about current events\"\n    )\n]\n```\n\n\n```python\n# Set up the prompt with input variables for tools, user input and a scratchpad for the model to record its workings\ntemplate = \"\"\"Answer the following questions as best you can, but speaking as a pirate might speak. You have access to the following tools:\n\n{tools}\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin! Remember to speak as a pirate when giving your final answer. Use lots of \"Arg\"s\n\nQuestion: {input}\n{agent_scratchpad}\"\"\"\n```\n\n\n```python\n# Set up a prompt template\nclass CustomPromptTemplate(BaseChatPromptTemplate):\n    # The template to use\n    template: str\n    # The list of tools available\n    tools: List[Tool]\n    \n    def format_messages(self, **kwargs) -> str:\n        # Get the intermediate steps (AgentAction, Observation tuples)\n        \n        # Format them in a particular way\n        intermediate_steps = kwargs.pop(\"intermediate_steps\")\n        thoughts = \"\"\n        for action, observation in intermediate_steps:\n            thoughts += action.log\n            thoughts += f\"\\nObservation: {observation}\\nThought: \"\n            \n        # Set the agent_scratchpad variable to that value\n        kwargs[\"agent_scratchpad\"] = thoughts\n        \n        # Create a tools variable from the list of tools provided\n        kwargs[\"tools\"] = \"\\n\".join([f\"{tool.name}: {tool.description}\" for tool in self.tools])\n        \n        # Create a list of tool names for the tools provided\n        kwargs[\"tool_names\"] = \", \".join([tool.name for tool in self.tools])\n        formatted = self.template.format(**kwargs)\n        return [HumanMessage(content=formatted)]\n    \nprompt = CustomPromptTemplate(\n    template=template,\n    tools=tools,\n    # This omits the `agent_scratchpad`, `tools`, and `tool_names` variables because those are generated dynamically\n    # This includes the `intermediate_steps` variable because that is needed\n    input_variables=[\"input\", \"intermediate_steps\"]\n)\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 74116c2f-6c86-4660-ba03-dac4bc72c31b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"74116c2f-6c86-4660-ba03-dac4bc72c31b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"570d61ff-b15d-48d4-963c-af923782747c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"4ff239492596d2ec5aa6d12c2e23483c2b123cbd1653502de2670561c2d9f3c2\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"5319a987-40da-4ad6-b371-915fd1336700\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9f19d647a7e2edfb89b7fc39aa6f7719c85fbeccf00f5b83101b78b1c8b70a2b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8132, \"end_char_idx\": 10904, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\n# Set up a prompt template\nclass CustomPromptTemplate(BaseChatPromptTemplate):\n    # The template to use\n    template: str\n    # The list of tools available\n    tools: List[Tool]\n    \n    def format_messages(self, **kwargs) -> str:\n        # Get the intermediate steps (AgentAction, Observation tuples)\n        \n        # Format them in a particular way\n        intermediate_steps = kwargs.pop(\"intermediate_steps\")\n        thoughts = \"\"\n        for action, observation in intermediate_steps:\n            thoughts += action.log\n            thoughts += f\"\\nObservation: {observation}\\nThought: \"\n            \n        # Set the agent_scratchpad variable to that value\n        kwargs[\"agent_scratchpad\"] = thoughts\n        \n        # Create a tools variable from the list of tools provided\n        kwargs[\"tools\"] = \"\\n\".join([f\"{tool.name}: {tool.description}\" for tool in self.tools])\n        \n        # Create a list of tool names for the tools provided\n        kwargs[\"tool_names\"] = \", \".join([tool.name for tool in self.tools])\n        formatted = self.template.format(**kwargs)\n        return [HumanMessage(content=formatted)]\n    \nprompt = CustomPromptTemplate(\n    template=template,\n    tools=tools,\n    # This omits the `agent_scratchpad`, `tools`, and `tool_names` variables because those are generated dynamically\n    # This includes the `intermediate_steps` variable because that is needed\n    input_variables=[\"input\", \"intermediate_steps\"]\n)\n```\n\n\n```python\nclass CustomOutputParser(AgentOutputParser):\n    \n    def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]:\n        \n        # Check if agent should finish\n        if \"Final Answer:\" in llm_output:\n            return AgentFinish(\n                # Return values is generally always a dictionary with a single `output` key\n                # It is not recommended to try anything else at the moment :)\n                return_values={\"output\": llm_output.split(\"Final Answer:\")[-1].strip()},\n                log=llm_output,\n            )\n        \n        # Parse out the action and action input\n        regex = r\"Action: (.*?)[\\n]*Action Input:[\\s]*(.*)\"\n        match = re.search(regex, llm_output, re.DOTALL)\n        \n        # If it can't parse the output it raises an error\n        # You can add your own logic here to handle errors in a different way i.e. pass to a human, give a canned response\n        if not match:\n            raise ValueError(f\"Could not parse LLM output: `{llm_output}`\")\n        action = match.group(1).strip()\n        action_input = match.group(2)\n        \n        # Return the action and action input\n        return AgentAction(tool=action, tool_input=action_input.strip(\" \").strip('\"'), log=llm_output)\n    \noutput_parser = CustomOutputParser()\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 5319a987-40da-4ad6-b371-915fd1336700
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"5319a987-40da-4ad6-b371-915fd1336700\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"74116c2f-6c86-4660-ba03-dac4bc72c31b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"b790999ad5e81a3ed4676b0b0cd58359e11d3b65ab99a4ddac74646b59d13fbd\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"bbeec2a8-7c74-44b6-b042-61ad438a1fa8\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9e544c0adb82452014db2ebad37b3332a6cc0b5d566103bd9ce65f378ec20021\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9603, \"end_char_idx\": 11750, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\nclass CustomOutputParser(AgentOutputParser):\n    \n    def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]:\n        \n        # Check if agent should finish\n        if \"Final Answer:\" in llm_output:\n            return AgentFinish(\n                # Return values is generally always a dictionary with a single `output` key\n                # It is not recommended to try anything else at the moment :)\n                return_values={\"output\": llm_output.split(\"Final Answer:\")[-1].strip()},\n                log=llm_output,\n            )\n        \n        # Parse out the action and action input\n        regex = r\"Action: (.*?)[\\n]*Action Input:[\\s]*(.*)\"\n        match = re.search(regex, llm_output, re.DOTALL)\n        \n        # If it can't parse the output it raises an error\n        # You can add your own logic here to handle errors in a different way i.e. pass to a human, give a canned response\n        if not match:\n            raise ValueError(f\"Could not parse LLM output: `{llm_output}`\")\n        action = match.group(1).strip()\n        action_input = match.group(2)\n        \n        # Return the action and action input\n        return AgentAction(tool=action, tool_input=action_input.strip(\" \").strip('\"'), log=llm_output)\n    \noutput_parser = CustomOutputParser()\n```\n\n\n```python\n# Initiate our LLM - default is 'gpt-3.5-turbo'\nllm = ChatOpenAI(temperature=0)\n\n# LLM chain consisting of the LLM and a prompt\nllm_chain = LLMChain(llm=llm, prompt=prompt)\n\n# Using tools, the LLM chain and output_parser to make an agent\ntool_names = [tool.name for tool in tools]\n\nagent = LLMSingleActionAgent(\n    llm_chain=llm_chain, \n    output_parser=output_parser,\n    # We use \"Observation\" as our stop sequence so it will stop when it receives Tool output\n    # If you change your prompt template you'll need to adjust this as well\n    stop=[\"\\nObservation:\"], \n    allowed_tools=tool_names\n)\n```\n\n\n```python\n# Initiate the agent that will respond to our queries\n# Set verbose=True to share the CoT reasoning the LLM goes through\nagent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True)\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: bbeec2a8-7c74-44b6-b042-61ad438a1fa8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"bbeec2a8-7c74-44b6-b042-61ad438a1fa8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"5319a987-40da-4ad6-b371-915fd1336700\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"4e764be97f53cc4d0d95320617c4f4e543badd232fbe700f15642ccaf555bf90\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"4bb22ea0-59f3-4c70-ba43-902c85710fc5\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"05ed5f0bdcf08d03187e4a332d9936a064a28b5773dfb464bd2d261aa18d5536\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10907, \"end_char_idx\": 12702, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\n# Initiate our LLM - default is 'gpt-3.5-turbo'\nllm = ChatOpenAI(temperature=0)\n\n# LLM chain consisting of the LLM and a prompt\nllm_chain = LLMChain(llm=llm, prompt=prompt)\n\n# Using tools, the LLM chain and output_parser to make an agent\ntool_names = [tool.name for tool in tools]\n\nagent = LLMSingleActionAgent(\n    llm_chain=llm_chain, \n    output_parser=output_parser,\n    # We use \"Observation\" as our stop sequence so it will stop when it receives Tool output\n    # If you change your prompt template you'll need to adjust this as well\n    stop=[\"\\nObservation:\"], \n    allowed_tools=tool_names\n)\n```\n\n\n```python\n# Initiate the agent that will respond to our queries\n# Set verbose=True to share the CoT reasoning the LLM goes through\nagent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True)\n```\n\n\n```python\nagent_executor.run(\"How many people live in canada as of 2023?\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: Hmm, I be not sure of the answer to that one. Let me think.\n    Action: Search\n    Action Input: \"Canada population 2023\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3m39,566,248\u001b[0m\u001b[32;1m\u001b[1;3mAhoy, that be a lot of people! But I need to make sure this be true.\n    Action: Search\n    Action Input: \"Canada population 2023 official source\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mThe current population of Canada is 38,664,637 as of Wednesday, April 19, 2023, based on Worldometer elaboration of the latest United Nations data.\u001b[0m\u001b[32;1m\u001b[1;3mArrr, that be the official number! I be confident in me answer now.\n    Final Answer: The population of Canada as of 2023 is 38,664,637. Arg!\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m\n\n\n\n\n\n    'The population of Canada as of 2023 is 38,664,637. Arg!'"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 4bb22ea0-59f3-4c70-ba43-902c85710fc5
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4bb22ea0-59f3-4c70-ba43-902c85710fc5\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"bbeec2a8-7c74-44b6-b042-61ad438a1fa8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"94645a092007a62f379d8cc18e1ccfaeb1f56512318ca1fb482a3b21ba814a13\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"bfc41c2b-179e-473a-a974-c45a1ad69f6f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a24bf5a116023d0d5c7608de4af83b53a2b1d177b1c00c93ae0b53fb8813233b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11524, \"end_char_idx\": 14159, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\n# Initiate the agent that will respond to our queries\n# Set verbose=True to share the CoT reasoning the LLM goes through\nagent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True)\n```\n\n\n```python\nagent_executor.run(\"How many people live in canada as of 2023?\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: Hmm, I be not sure of the answer to that one. Let me think.\n    Action: Search\n    Action Input: \"Canada population 2023\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3m39,566,248\u001b[0m\u001b[32;1m\u001b[1;3mAhoy, that be a lot of people! But I need to make sure this be true.\n    Action: Search\n    Action Input: \"Canada population 2023 official source\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mThe current population of Canada is 38,664,637 as of Wednesday, April 19, 2023, based on Worldometer elaboration of the latest United Nations data.\u001b[0m\u001b[32;1m\u001b[1;3mArrr, that be the official number! I be confident in me answer now.\n    Final Answer: The population of Canada as of 2023 is 38,664,637. Arg!\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m\n\n\n\n\n\n    'The population of Canada as of 2023 is 38,664,637. Arg!'\n\n\n\n\n```python\nagent_executor.run(\"How many in 2022?\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: Hmm, I'm not sure what this question is asking about. I better use the search tool.\n    Action: Search\n    Action Input: \"2022 events\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3m8. Humanitarian Crises Deepen \u00b7 7. Latin America Moves Left. \u00b7 6. Iranians Protest. \u00b7 5. COVID Eases. \u00b7 4. Inflation Returns. \u00b7 3. Climate Change ...\u001b[0m\u001b[32;1m\u001b[1;3mAhoy, it looks like this be a question about what be happenin' in 2022. Let me search again.\n    Action: Search\n    Action Input: \"2022 calendar\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mUnited States 2022 \u2013 Calendar with American holidays. Yearly calendar showing months for the year 2022. Calendars \u2013 online and print friendly \u2013 for any year ...\u001b[0m\u001b[32;1m\u001b[1;3mShiver me timbers, it looks like this be a question about the year 2022. Let me search one more time.\n    Action: Search\n    Action Input: \"What be happenin' in 2022?\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3m8. Humanitarian Crises Deepen \u00b7 7. Latin America Moves Left. \u00b7 6. Iranians Protest. \u00b7 5. COVID Eases. \u00b7 4. Inflation Returns. \u00b7 3. Climate Change ...\u001b[0m\u001b[32;1m\u001b[1;3mAvast ye, it looks like the same results be comin' up. I reckon there be no clear answer to this question.\n    Final Answer: Arg, I be sorry matey, but I can't give ye a clear answer to that question.\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: bfc41c2b-179e-473a-a974-c45a1ad69f6f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"bfc41c2b-179e-473a-a974-c45a1ad69f6f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"4bb22ea0-59f3-4c70-ba43-902c85710fc5\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"db04eaa4b74ebb1dc0da09694f9897273fc605e875175b9cd7d1c2f7bd086713\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"97d231e5-68c8-4aee-9f1c-bd603ed395d5\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4011a19a0fd058d63775b68d24f42afb2de7e75092b56cb66bf54f0ab3bf4453\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14169, \"end_char_idx\": 16441, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "\"Arg, I be sorry matey, but I can't give ye a clear answer to that question.\"\n\n\n\n## LLM Agent with History\n\nExtend the LLM Agent with the ability to retain a [memory](https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html#adding-memory) and use it as context as it continues the conversation.\n\nWe use a simple ```ConversationBufferWindowMemory``` for this example that keeps a rolling window of the last two conversation turns. LangChain has other [memory options](https://python.langchain.com/en/latest/modules/memory.html), with different tradeoffs suitable for different use cases.\n\n\n```python\n# Set up a prompt template which can interpolate the history\ntemplate_with_history = \"\"\"You are SearchGPT, a professional search engine who provides informative answers to users. Answer the following questions as best you can. You have access to the following tools:\n\n{tools}\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin! Remember to give detailed, informative answers\n\nPrevious conversation history:\n{history}\n\nNew question: {input}\n{agent_scratchpad}\"\"\"\n```\n\n\n```python\nprompt_with_history = CustomPromptTemplate(\n    template=template_with_history,\n    tools=tools,\n    # The history template includes \"history\" as an input variable so we can interpolate it into the prompt\n    input_variables=[\"input\", \"intermediate_steps\", \"history\"]\n)\n\nllm_chain = LLMChain(llm=llm, prompt=prompt_with_history)\ntool_names = [tool.name for tool in tools]\nagent = LLMSingleActionAgent(\n    llm_chain=llm_chain, \n    output_parser=output_parser,\n    stop=[\"\\nObservation:\"], \n    allowed_tools=tool_names\n)\n```\n\n\n```python\n# Initiate the memory with k=2 to keep the last two turns\n# Provide the memory to the agent\nmemory = ConversationBufferWindowMemory(k=2)\nagent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory)\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 97d231e5-68c8-4aee-9f1c-bd603ed395d5
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"97d231e5-68c8-4aee-9f1c-bd603ed395d5\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"bfc41c2b-179e-473a-a974-c45a1ad69f6f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"1bfcb0beaadb45d96da191962c3c12d0c11c349e0ab69f11facb4c79fb2f1767\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"52ab4778-06a7-41e0-897b-a38f60db992b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d72580d1daba0e695a9dd8feecd2aa7c9c79e736f65b003ca673015c7992b219\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14784, \"end_char_idx\": 17516, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\n# Set up a prompt template which can interpolate the history\ntemplate_with_history = \"\"\"You are SearchGPT, a professional search engine who provides informative answers to users. Answer the following questions as best you can. You have access to the following tools:\n\n{tools}\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin! Remember to give detailed, informative answers\n\nPrevious conversation history:\n{history}\n\nNew question: {input}\n{agent_scratchpad}\"\"\"\n```\n\n\n```python\nprompt_with_history = CustomPromptTemplate(\n    template=template_with_history,\n    tools=tools,\n    # The history template includes \"history\" as an input variable so we can interpolate it into the prompt\n    input_variables=[\"input\", \"intermediate_steps\", \"history\"]\n)\n\nllm_chain = LLMChain(llm=llm, prompt=prompt_with_history)\ntool_names = [tool.name for tool in tools]\nagent = LLMSingleActionAgent(\n    llm_chain=llm_chain, \n    output_parser=output_parser,\n    stop=[\"\\nObservation:\"], \n    allowed_tools=tool_names\n)\n```\n\n\n```python\n# Initiate the memory with k=2 to keep the last two turns\n# Provide the memory to the agent\nmemory = ConversationBufferWindowMemory(k=2)\nagent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory)\n```\n\n\n```python\nagent_executor.run(\"How many people live in canada as of 2023?\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: I need to find the most recent population data for Canada.\n    Action: Search\n    Action Input: \"Canada population 2023\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3m39,566,248\u001b[0m\u001b[32;1m\u001b[1;3mThis data seems reliable, but I should double-check the source.\n    Action: Search\n    Action Input: \"Source of Canada population 2023\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mThe current population of Canada is 38,664,637 as of Wednesday, April 19, 2023, based on Worldometer elaboration of the latest United Nations data. Canada 2020 population is estimated at 37,742,154 people at mid year according to UN data. Canada population is equivalent to 0.48% of the total world population.\u001b[0m\u001b[32;1m\u001b[1;3mI now know the final answer\n    Final Answer: As of April 19, 2023, the population of Canada is 38,664,637.\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m\n\n\n\n\n\n    'As of April 19, 2023, the population of Canada is 38,664,637.'"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 52ab4778-06a7-41e0-897b-a38f60db992b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"52ab4778-06a7-41e0-897b-a38f60db992b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"97d231e5-68c8-4aee-9f1c-bd603ed395d5\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"59ccb3997ac9896ba9fffee0e46dea53a187d868eb4f9394f19db17f1ef1caef\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1daae759-9412-4d69-b24d-bf763a8ca506\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5cd4d08ff5a58f634f6211014b1a1ef9867431cd29e898afa6a9d9e20442f767\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 16184, \"end_char_idx\": 18538, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\n# Initiate the memory with k=2 to keep the last two turns\n# Provide the memory to the agent\nmemory = ConversationBufferWindowMemory(k=2)\nagent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory)\n```\n\n\n```python\nagent_executor.run(\"How many people live in canada as of 2023?\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: I need to find the most recent population data for Canada.\n    Action: Search\n    Action Input: \"Canada population 2023\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3m39,566,248\u001b[0m\u001b[32;1m\u001b[1;3mThis data seems reliable, but I should double-check the source.\n    Action: Search\n    Action Input: \"Source of Canada population 2023\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mThe current population of Canada is 38,664,637 as of Wednesday, April 19, 2023, based on Worldometer elaboration of the latest United Nations data. Canada 2020 population is estimated at 37,742,154 people at mid year according to UN data. Canada population is equivalent to 0.48% of the total world population.\u001b[0m\u001b[32;1m\u001b[1;3mI now know the final answer\n    Final Answer: As of April 19, 2023, the population of Canada is 38,664,637.\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m\n\n\n\n\n\n    'As of April 19, 2023, the population of Canada is 38,664,637.'\n\n\n\n\n```python\nagent_executor.run(\"how about in mexico?\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: I need to search for the current population of Mexico.\n    Action: Search\n    Action Input: \"current population of Mexico\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mMexico, officially the United Mexican States, is a country in the southern portion of North America. It is bordered to the north by the United States; to the south and west by the Pacific Ocean; to the southeast by Guatemala, Belize, and the Caribbean Sea; and to the east by the Gulf of Mexico.\u001b[0m\u001b[32;1m\u001b[1;3mThat's not the answer to the question, I need to refine my search.\n    Action: Search\n    Action Input: \"population of Mexico 2023\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3m132,709,512\u001b[0m\u001b[32;1m\u001b[1;3mI now know the final answer.\n    Final Answer: As of 2023, the population of Mexico is 132,709,512.\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m\n\n\n\n\n\n    'As of 2023, the population of Mexico is 132,709,512.'"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 1daae759-9412-4d69-b24d-bf763a8ca506
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1daae759-9412-4d69-b24d-bf763a8ca506\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"52ab4778-06a7-41e0-897b-a38f60db992b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"5d7d4576874d35abbb16473270b0be9b8c4594f7851f5357fd688372d7d09ccc\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"b31613e3-17df-462b-b104-d66b769651d8\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b82962f082c93df6e40a88b28beb18b90be450e954f8f0ff53780ce2f3b0c8c6\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 17453, \"end_char_idx\": 20222, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "'As of April 19, 2023, the population of Canada is 38,664,637.'\n\n\n\n\n```python\nagent_executor.run(\"how about in mexico?\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: I need to search for the current population of Mexico.\n    Action: Search\n    Action Input: \"current population of Mexico\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mMexico, officially the United Mexican States, is a country in the southern portion of North America. It is bordered to the north by the United States; to the south and west by the Pacific Ocean; to the southeast by Guatemala, Belize, and the Caribbean Sea; and to the east by the Gulf of Mexico.\u001b[0m\u001b[32;1m\u001b[1;3mThat's not the answer to the question, I need to refine my search.\n    Action: Search\n    Action Input: \"population of Mexico 2023\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3m132,709,512\u001b[0m\u001b[32;1m\u001b[1;3mI now know the final answer.\n    Final Answer: As of 2023, the population of Mexico is 132,709,512.\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m\n\n\n\n\n\n    'As of 2023, the population of Mexico is 132,709,512.'\n\n\n\n## Knowledge base\n\nCreate a custom vectorstore for the Agent to use as a tool to answer questions with. We'll store the results in [Pinecone](https://docs.pinecone.io/docs/quickstart), which is supported by LangChain ([Docs](https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/pinecone.html), [API reference](https://python.langchain.com/en/latest/reference/modules/vectorstore.html)). For help getting started with Pinecone or other vector databases, we have a [cookbook](https://github.com/openai/openai-cookbook/blob/colin/examples/vector_databases/Using_vector_databases_for_embeddings_search.ipynb) to help you get started.\n\nYou can check the LangChain documentation to see what other [vectorstores](https://python.langchain.com/en/latest/modules/indexes/vectorstores.html) and [databases](https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html) are available.\n\nFor this example we'll use the transcripts of the Stuff You Should Know podcast, which was provided thanks to OSF DOI [10.17605/OSF.IO/VM9NT](https://doi.org/10.17605/OSF.IO/VM9NT)\n\n\n```python\nimport wget\n\n# Here is a URL to a zip archive containing the transcribed podcasts\n# Note that this data has already been split into chunks and embeddings from OpenAI's `text-embedding-3-small` embedding model are included\ncontent_url = 'https://cdn.openai.com/API/examples/data/sysk_podcast_transcripts_embedded.json.zip'\n\n# Download the file (it is ~541 MB so this will take some time)\nwget.download(content_url)\n```\n\n    100% [......................................................................] 571275039 / 571275039\n\n\n\n\n    'sysk_podcast_transcripts_embedded.json.zip'"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: b31613e3-17df-462b-b104-d66b769651d8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b31613e3-17df-462b-b104-d66b769651d8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1daae759-9412-4d69-b24d-bf763a8ca506\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"83b9ffa64a06d84e361033060c1617889008ac076b9251bec6ddc23427bc22c0\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"dc0be983-9942-4dd4-8b8b-ef0c4a3d5b67\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"174ae9ba68021ffe4352f49a6370a345e279f5faa5bce4e261b02ae474f9ce54\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": null, \"end_char_idx\": null, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "## Knowledge base\n\nCreate a custom vectorstore for the Agent to use as a tool to answer questions with. We'll store the results in [Pinecone](https://docs.pinecone.io/docs/quickstart), which is supported by LangChain ([Docs](https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/pinecone.html), [API reference](https://python.langchain.com/en/latest/reference/modules/vectorstore.html)). For help getting started with Pinecone or other vector databases, we have a [cookbook](https://github.com/openai/openai-cookbook/blob/colin/examples/vector_databases/Using_vector_databases_for_embeddings_search.ipynb) to help you get started.\n\nYou can check the LangChain documentation to see what other [vectorstores](https://python.langchain.com/en/latest/modules/indexes/vectorstores.html) and [databases](https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html) are available.\n\nFor this example we'll use the transcripts of the Stuff You Should Know podcast, which was provided thanks to OSF DOI [10.17605/OSF.IO/VM9NT](https://doi.org/10.17605/OSF.IO/VM9NT)\n\n\n```python\nimport wget\n\n# Here is a URL to a zip archive containing the transcribed podcasts\n# Note that this data has already been split into chunks and embeddings from OpenAI's `text-embedding-3-small` embedding model are included\ncontent_url = 'https://cdn.openai.com/API/examples/data/sysk_podcast_transcripts_embedded.json.zip'\n\n# Download the file (it is ~541 MB so this will take some time)\nwget.download(content_url)\n```\n\n    100% [......................................................................] 571275039 / 571275039\n\n\n\n\n    'sysk_podcast_transcripts_embedded.json.zip'\n\n\n\n\n```python\n# Load podcasts\nwith zipfile.ZipFile(\"sysk_podcast_transcripts_embedded.json.zip\",\"r\") as zip_ref:\n    zip_ref.extractall(\"./data\")\nf = open('./data/sysk_podcast_transcripts_embedded.json')\nprocessed_podcasts = json.load(f)\n```\n\n\n```python\n# Have a look at the contents\npd.DataFrame(processed_podcasts).head()\n```\n\n\n\n\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>filename</th>\n      <th>title</th>\n      <th>url</th>\n      <th>text_chunk</th>\n      <th>embedding</th>\n      <th>cleaned_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.021279960870742798,"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: dc0be983-9942-4dd4-8b8b-ef0c4a3d5b67
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"dc0be983-9942-4dd4-8b8b-ef0c4a3d5b67\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b31613e3-17df-462b-b104-d66b769651d8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"24cd79ba97cdc5d4fe7d9456886ac72c6d01ee2f22bd45c499bf6aea4d28a233\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"cf9cc66b-fb6a-4663-911b-f7800740c75e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f23efa80eb90156ee4238529f9d7f59e891ecc21466e8d08ec56e7cb00d57d4c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": null, \"end_char_idx\": null, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "'sysk_podcast_transcripts_embedded.json.zip'\n\n\n\n\n```python\n# Load podcasts\nwith zipfile.ZipFile(\"sysk_podcast_transcripts_embedded.json.zip\",\"r\") as zip_ref:\n    zip_ref.extractall(\"./data\")\nf = open('./data/sysk_podcast_transcripts_embedded.json')\nprocessed_podcasts = json.load(f)\n```\n\n\n```python\n# Have a look at the contents\npd.DataFrame(processed_podcasts).head()\n```\n\n\n\n\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>filename</th>\n      <th>title</th>\n      <th>url</th>\n      <th>text_chunk</th>\n      <th>embedding</th>\n      <th>cleaned_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.021279960870742798, -0.005817972123622894, .</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.013859338127076626, 0.00857278611510992, 0.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.015242221765220165, 0.016030369326472282, 0.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: cf9cc66b-fb6a-4663-911b-f7800740c75e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"cf9cc66b-fb6a-4663-911b-f7800740c75e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"dc0be983-9942-4dd4-8b8b-ef0c4a3d5b67\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"e7ee0a511fe744537f31528feec32b9ea7f86696756c3b9096d55370649f4013\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"96f04acf-77e2-494a-bfc3-5fd4f811192c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"7ac1ce2afddc1e51a1ef78273be050aa7b1f4c8dcd6253f71cfae8d5981988ff\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": null, \"end_char_idx\": null, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "</td>\n      <td>[0.021279960870742798, -0.005817972123622894, .</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.013859338127076626, 0.00857278611510992, 0.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.015242221765220165, 0.016030369326472282, 0.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.004371842369437218, -0.003036574460566044, .</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.017309172078967094, 0.015154214575886726, 0.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n  </tbody>\n</table>\n</div>"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 96f04acf-77e2-494a-bfc3-5fd4f811192c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"96f04acf-77e2-494a-bfc3-5fd4f811192c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"cf9cc66b-fb6a-4663-911b-f7800740c75e\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"c26059937c7036c1eb048049a482c41b86eb79990b99724aa14c33dd6d120ca6\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1a63deb7-c619-48bf-b3d7-d097924ddff0\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f3be76813358c0853ae470b01edca39e153751821521806878ac62fadea80158\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": null, \"end_char_idx\": null, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "015242221765220165, 0.016030369326472282, 0.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.004371842369437218, -0.003036574460566044, .</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n      <td>\\n\\nSYSK Selects How Crime Scene Cleanup Works</td>\n      <td>https://chtbl.com/track/5899E/podtrac.com/pts/.</td>\n      <td>Title: sysk_with_transcripts_SYSK Selects How .</td>\n      <td>[0.017309172078967094, 0.015154214575886726, 0.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\n\n```python\n# Add the text embeddings to Pinecone\n\nbatch_size = 100  # how many embeddings we create and insert at once\n\nfor i in tqdm(range(0, len(processed_podcasts), batch_size)):\n    # find end of batch\n    i_end = min(len(processed_podcasts), i+batch_size)\n    meta_batch = processed_podcasts[i:i_end]\n    # get ids\n    ids_batch = [x['cleaned_id'] for x in meta_batch]\n    # get texts to encode\n    texts = [x['text_chunk'] for x in meta_batch]\n    # add embeddings\n    embeds = [x['embedding'] for x in meta_batch]\n    # cleanup metadata\n    meta_batch = [{\n        'filename': x['filename'],\n        'title': x['title'],\n        'text_chunk': x['text_chunk'],\n        'url': x['url']\n    } for x in meta_batch]\n    to_upsert = list(zip(ids_batch, embeds, meta_batch))\n    # upsert to Pinecone\n    index.upsert(vectors=to_upsert)\n```\n\n\n```python\n# Configuring the embeddings to be used by our retriever to be OpenAI Embeddings, matching our embedded corpus\nembeddings = OpenAIEmbeddings()\n\n\n# Loads a docsearch object from an existing Pinecone index so we can retrieve from it\ndocsearch = Pinecone.from_existing_index(index_name,embeddings,text_key='text_chunk')\n```\n\n\n```python\nretriever = docsearch.as_retriever()\n```\n\n\n```python\nquery_docs = retriever.get_relevant_documents(\"can you live without a bank account\")\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 1a63deb7-c619-48bf-b3d7-d097924ddff0
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1a63deb7-c619-48bf-b3d7-d097924ddff0\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"96f04acf-77e2-494a-bfc3-5fd4f811192c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ca5e8412817a99ae212c5fb8011707d4ff950865786c8db10dcfa88d287c4c5\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"58aa0957-c0c8-4cf8-a817-12f23a88295a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5cbcd43d7fcbee90ae1b82bcfc7638505b02b6f0838d45c0e4d9780e50592c8c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": null, \"end_char_idx\": null, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "0.015154214575886726, 0.</td>\n      <td>sysk_with_transcripts_SYSK Selects How Crime S.</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\n\n```python\n# Add the text embeddings to Pinecone\n\nbatch_size = 100  # how many embeddings we create and insert at once\n\nfor i in tqdm(range(0, len(processed_podcasts), batch_size)):\n    # find end of batch\n    i_end = min(len(processed_podcasts), i+batch_size)\n    meta_batch = processed_podcasts[i:i_end]\n    # get ids\n    ids_batch = [x['cleaned_id'] for x in meta_batch]\n    # get texts to encode\n    texts = [x['text_chunk'] for x in meta_batch]\n    # add embeddings\n    embeds = [x['embedding'] for x in meta_batch]\n    # cleanup metadata\n    meta_batch = [{\n        'filename': x['filename'],\n        'title': x['title'],\n        'text_chunk': x['text_chunk'],\n        'url': x['url']\n    } for x in meta_batch]\n    to_upsert = list(zip(ids_batch, embeds, meta_batch))\n    # upsert to Pinecone\n    index.upsert(vectors=to_upsert)\n```\n\n\n```python\n# Configuring the embeddings to be used by our retriever to be OpenAI Embeddings, matching our embedded corpus\nembeddings = OpenAIEmbeddings()\n\n\n# Loads a docsearch object from an existing Pinecone index so we can retrieve from it\ndocsearch = Pinecone.from_existing_index(index_name,embeddings,text_key='text_chunk')\n```\n\n\n```python\nretriever = docsearch.as_retriever()\n```\n\n\n```python\nquery_docs = retriever.get_relevant_documents(\"can you live without a bank account\")\n```\n\n\n```python\n# Print out the title and content for the most relevant retrieved documents\nprint(\"\\n\".join(['Title: ' + x.metadata['title'].strip() + '\\n\\n' + x.page_content + '\\n\\n' for x in query_docs]))\n```\n\n    Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  And if you had a life, you didn't necessarily rectify your bank checkbook every day. Oh, wait, what is balancing a checkbook mean? Seriously? Yeah. Thank God for my wife. So another reason you might avoid a bank is philosophically. There may be a longstanding distrust of banks in your family that you don't want to put your money in, or you may just want to be like, you know what? I don't want to take part in this modern society. I want to kind of drop out a bit. And a really good first move is to shut your bank account down. That's a big statement. Oh, yeah, it is. But a lot of people that are underbanked and don't have accounts aren't there on purpose. It's not some philosophical statement. A lot of times it's simply because they are poor and they don't have a lot of alternatives. Yeah. And the other thing about not having a bank account, not only do you not have a bank account, you also are, like, basically just avoiding banks altogether. There's plenty of other things that banks offer, like loans and mortgage, lollipops, stuff like that. Yeah. Maybe some free nasty coffee."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 58aa0957-c0c8-4cf8-a817-12f23a88295a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"58aa0957-c0c8-4cf8-a817-12f23a88295a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1a63deb7-c619-48bf-b3d7-d097924ddff0\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"837aa519a6b1c8f1bbb227fd695c04764d1bfd1a5de3fa039e6a16160063d124\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"f722ce67-b52d-4376-9f48-6189f22abac1\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9f51523ea4d94182ff7118ebe48746e0ecc1de80e1facdef07389e336cbc613b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 24777, \"end_char_idx\": 27953, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\nquery_docs = retriever.get_relevant_documents(\"can you live without a bank account\")\n```\n\n\n```python\n# Print out the title and content for the most relevant retrieved documents\nprint(\"\\n\".join(['Title: ' + x.metadata['title'].strip() + '\\n\\n' + x.page_content + '\\n\\n' for x in query_docs]))\n```\n\n    Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  And if you had a life, you didn't necessarily rectify your bank checkbook every day. Oh, wait, what is balancing a checkbook mean? Seriously? Yeah. Thank God for my wife. So another reason you might avoid a bank is philosophically. There may be a longstanding distrust of banks in your family that you don't want to put your money in, or you may just want to be like, you know what? I don't want to take part in this modern society. I want to kind of drop out a bit. And a really good first move is to shut your bank account down. That's a big statement. Oh, yeah, it is. But a lot of people that are underbanked and don't have accounts aren't there on purpose. It's not some philosophical statement. A lot of times it's simply because they are poor and they don't have a lot of alternatives. Yeah. And the other thing about not having a bank account, not only do you not have a bank account, you also are, like, basically just avoiding banks altogether. There's plenty of other things that banks offer, like loans and mortgage, lollipops, stuff like that. Yeah. Maybe some free nasty coffee. So when you don't have a banking account, that's like the most basic unit of the banking world. Right. If you don't have that, you obviously aren't going to be exposed to all these other things that can help. Things like build your credit history through like a revolving loan or a mortgage or a car loan or something like that that you can build up your credit for and ultimately save money. So when you don't have a bank account, for whatever reason, you are effectively out of the banking system. The problem is you can live parallel to the banking system outside of it, but it can be really dangerous, especially if you're just dealing with cash, because that cash has to stay somewhere, whether it's on you or in your mattress or in a coffee can in your backyard. You're exposed for having that readily available to anybody who finds it or comes into your house with a gun to get it. Yes.\n    \n    \n    Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  And it doesn't have to be an everyday thing. You can host when you want. Like, let's say you're taking a week's vacation. Why not host your home? Because that money could go toward paying for your current vacation or towards your retirement fund or even towards your kids college fund. Yeah. For anything. And listen, if you're worried about your stuff, don't be. Air cover for hosts. Let hosts welcome guests into their home without having to worry. You get $1 million in damage protection anytime you're hosting. Plus pet damage protection and income loss protection, too. And are you ready for this?"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: f722ce67-b52d-4376-9f48-6189f22abac1
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"f722ce67-b52d-4376-9f48-6189f22abac1\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"58aa0957-c0c8-4cf8-a817-12f23a88295a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"d68aa45d23c582c203c50c25c01a88b44ce25691db442efd93b7b1913716a7bd\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"bc795230-f2c0-462b-90b2-e196ca612884\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"650d8eaa0dcfee76980ffb53cdb3430b5c6db4a249d25d7695f4fcd2c19e1998\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 26276, \"end_char_idx\": 29595, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "Yeah. Maybe some free nasty coffee. So when you don't have a banking account, that's like the most basic unit of the banking world. Right. If you don't have that, you obviously aren't going to be exposed to all these other things that can help. Things like build your credit history through like a revolving loan or a mortgage or a car loan or something like that that you can build up your credit for and ultimately save money. So when you don't have a bank account, for whatever reason, you are effectively out of the banking system. The problem is you can live parallel to the banking system outside of it, but it can be really dangerous, especially if you're just dealing with cash, because that cash has to stay somewhere, whether it's on you or in your mattress or in a coffee can in your backyard. You're exposed for having that readily available to anybody who finds it or comes into your house with a gun to get it. Yes.\n    \n    \n    Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  And it doesn't have to be an everyday thing. You can host when you want. Like, let's say you're taking a week's vacation. Why not host your home? Because that money could go toward paying for your current vacation or towards your retirement fund or even towards your kids college fund. Yeah. For anything. And listen, if you're worried about your stuff, don't be. Air cover for hosts. Let hosts welcome guests into their home without having to worry. You get $1 million in damage protection anytime you're hosting. Plus pet damage protection and income loss protection, too. And are you ready for this? Air cover for host is completely free every time you host on airbnb. Free with a capital F, with air cover for Host. It makes hosting a no brainer, and the benefits really start adding up. So learn more and host with peace of mind at Airbnb comaircoverforhosts. Capital One offers commercial solutions you can bank on. Now more than ever, your business faces specific challenges and unique opportunities. That's why Capital One offers a comprehensive suite of financial services custom tailored to your short and long term goals, backed by the expertise, strategy and resources of a top ten commercial bank, a dedicated team works with you to support your success and help you achieve your goals. Explore the possibilities at CapitalOne. comCOMMERCIAL all right, so if you live in modern society today, it is pretty tough to get by without a bank. Most cases these days you have well, I don't know about most cases, but in many cases you have automatic deposits of your work checks. Sure. A lot of people pay their bills wirelessly, online, directly from their bank. You might have a student loan, you might have a car loan, you might have your house mortgage, you might pay your credit card bills. All this stuff is running through a bank, most likely. And you would think it's probably impossible to not have a bank account these days. And I would say pretty much all Americans have them. Not true. Well, pretty much all Americans do. Like 93% do. Yeah, but that's not all. No, it's true.\n    \n    \n    Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  Yeah."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: bc795230-f2c0-462b-90b2-e196ca612884
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"bc795230-f2c0-462b-90b2-e196ca612884\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"f722ce67-b52d-4376-9f48-6189f22abac1\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"4a010337d318c0320820282b3d7e975189573e9e3a51f8acd2097090a06c44fa\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1ea6abc5-5124-4ac5-851d-2f5c99ae3d22\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8f8519773341e2a6e67457d31b059ed24b095ae5cd64625a4cefefccec2286a5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 27866, \"end_char_idx\": 31049, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "Plus pet damage protection and income loss protection, too. And are you ready for this? Air cover for host is completely free every time you host on airbnb. Free with a capital F, with air cover for Host. It makes hosting a no brainer, and the benefits really start adding up. So learn more and host with peace of mind at Airbnb comaircoverforhosts. Capital One offers commercial solutions you can bank on. Now more than ever, your business faces specific challenges and unique opportunities. That's why Capital One offers a comprehensive suite of financial services custom tailored to your short and long term goals, backed by the expertise, strategy and resources of a top ten commercial bank, a dedicated team works with you to support your success and help you achieve your goals. Explore the possibilities at CapitalOne. comCOMMERCIAL all right, so if you live in modern society today, it is pretty tough to get by without a bank. Most cases these days you have well, I don't know about most cases, but in many cases you have automatic deposits of your work checks. Sure. A lot of people pay their bills wirelessly, online, directly from their bank. You might have a student loan, you might have a car loan, you might have your house mortgage, you might pay your credit card bills. All this stuff is running through a bank, most likely. And you would think it's probably impossible to not have a bank account these days. And I would say pretty much all Americans have them. Not true. Well, pretty much all Americans do. Like 93% do. Yeah, but that's not all. No, it's true.\n    \n    \n    Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  Yeah. 7% of Americans do not have bank accounts. About 9 million people last year in 2015 did not have bank accounts. 9 million people is a lot of people. No, it really is. And apparently that's household sorry, not people. Yeah, right. You're that is a big distinction, too. And the FDIC said, man, that's the lowest since we've been tracking this by far. And someone said, well, how long have you been tracking this? They said, well, the last six years. Really? Yeah, which I'm like. Really? That's when they started tracking it, but apparently so 2009. So if you want another number, the 9 million American households don't have bank accounts at all, then there are 25 million households in addition to that. So that makes almost like 34 million households, which that's a substantial number at this point. Sure. The 25 million are what's called underbanked, meaning they may have a bank account, but they don't use the bank account. Yeah. They don't use it because they are probably afraid of overdraft fees. Or they have maybe a bank account that got grandfathered in so that they don't have to pay minimum amount fees. And who knows? There's all sorts of reasons for people to not use a bank account that they have, but probably cheap among them is overdressed, which you'll talk more about. Yeah. And the majority of these underbank people in the United States are poor, usually. A lot of times they're minorities, a lot of times they're less educated."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 1ea6abc5-5124-4ac5-851d-2f5c99ae3d22
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1ea6abc5-5124-4ac5-851d-2f5c99ae3d22\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"bc795230-f2c0-462b-90b2-e196ca612884\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"09e4ec8af13d5079b6fcf0a16d23216453c1df2dbcf46659b2815c1171bbaabb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2524b0ce-edff-4e39-a7a3-1b189f669bf7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"601fd64233a60c86e14375014cf0910febbbc3f0a0096658e509aa8eae6a93ef\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 29459, \"end_char_idx\": 32432, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  Yeah. 7% of Americans do not have bank accounts. About 9 million people last year in 2015 did not have bank accounts. 9 million people is a lot of people. No, it really is. And apparently that's household sorry, not people. Yeah, right. You're that is a big distinction, too. And the FDIC said, man, that's the lowest since we've been tracking this by far. And someone said, well, how long have you been tracking this? They said, well, the last six years. Really? Yeah, which I'm like. Really? That's when they started tracking it, but apparently so 2009. So if you want another number, the 9 million American households don't have bank accounts at all, then there are 25 million households in addition to that. So that makes almost like 34 million households, which that's a substantial number at this point. Sure. The 25 million are what's called underbanked, meaning they may have a bank account, but they don't use the bank account. Yeah. They don't use it because they are probably afraid of overdraft fees. Or they have maybe a bank account that got grandfathered in so that they don't have to pay minimum amount fees. And who knows? There's all sorts of reasons for people to not use a bank account that they have, but probably cheap among them is overdressed, which you'll talk more about. Yeah. And the majority of these underbank people in the United States are poor, usually. A lot of times they're minorities, a lot of times they're less educated. And these communities, there's a few reasons why they may not want to use a bank one. Maybe they don't trust banks. And if you look in the history of the United States or certainly even we're just talking about the Wells Fargo scandal, when you see stuff like that on the news, it should be upsetting to everyone. But obviously if you're poor and you don't have a lot of money, that may scare you into not wanting to use a bank at all. Right? Yeah.\n    \n    \n    Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  Maybe at the time, I might be making it up. I seem to remember them saying that, and I was like, I don't want that. Just let the check bounce and I'll take it up with them. Yes. The way it was marketed, though, was like, hey, we value you. We want to make sure that you can pay all your bills. So if something happens and you're overdrafted we'll cover it. We're just going to charge you a fee. And it sounds good, but again, when you go from high to low and all of a sudden your overdraft fees go from one to four or five or however many, that's a huge problem. Well, and the people that are overdrafting and the people that are at least able to afford those fees. Exactly. So it's a disproportionate burden on the poor, which makes it, as a scam, one of the more evil scams around. Yes."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 2524b0ce-edff-4e39-a7a3-1b189f669bf7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2524b0ce-edff-4e39-a7a3-1b189f669bf7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1ea6abc5-5124-4ac5-851d-2f5c99ae3d22\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"c2c35f6da0b7649f623e9ae0cd01c549a6e071da0e5b9b2e5c44d354dc174800\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"f3a80d8f-e1fb-40c5-9771-dc8a69c2e696\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4faa7e8b1aadbf25a859371a3cf53430cd8fd72f31b41cb676e9c34b1b5d3694\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 30888, \"end_char_idx\": 33868, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "Yeah. And the majority of these underbank people in the United States are poor, usually. A lot of times they're minorities, a lot of times they're less educated. And these communities, there's a few reasons why they may not want to use a bank one. Maybe they don't trust banks. And if you look in the history of the United States or certainly even we're just talking about the Wells Fargo scandal, when you see stuff like that on the news, it should be upsetting to everyone. But obviously if you're poor and you don't have a lot of money, that may scare you into not wanting to use a bank at all. Right? Yeah.\n    \n    \n    Title: sysk: Can You Live Without a Bank Account?\n    \n    Title: sysk_with_transcripts_Can you live without a bank account.json;  Maybe at the time, I might be making it up. I seem to remember them saying that, and I was like, I don't want that. Just let the check bounce and I'll take it up with them. Yes. The way it was marketed, though, was like, hey, we value you. We want to make sure that you can pay all your bills. So if something happens and you're overdrafted we'll cover it. We're just going to charge you a fee. And it sounds good, but again, when you go from high to low and all of a sudden your overdraft fees go from one to four or five or however many, that's a huge problem. Well, and the people that are overdrafting and the people that are at least able to afford those fees. Exactly. So it's a disproportionate burden on the poor, which makes it, as a scam, one of the more evil scams around. Yes. It's just wrong, then the idea that if you open an account, you should not opt in for overdraft protection. And it's easy to say when you're talking about checks for, like you're writing a check for a Mountain Dew and some cheetos. Yeah, who cares if you're short for that? You can go without that. But when you're talking about your rent check or like an actual grocery bill or something like that, it sucks that you can't get that stuff. But it's better to have to put a couple of things back than to pay $35 for one $2 item that you went over by, right? Yeah, that's a good point. And this was in my case, too. This is also back in the day when you I mean, a lot of times it was a mystery how much you had in your account. Right. Like, you couldn't just get on your phone before you write the check and be like, oh, well, no, I don't have enough money to cover this. Yeah, because even if you balanced your checkbook, sometimes you forgot to carry the one, it wasn't always 100% accurate.\n    \n    \n\n\n## LLM Agent with Tools\n\nExtend our list of tools by creating a [RetrievalQA](https://python.langchain.com/en/latest/modules/chains/index_examples/vector_db_qa.html) chain leveraging our Pinecone knowledge base.\n\n\n```python\nfrom langchain.chains import RetrievalQA\n\nretrieval_llm = OpenAI(temperature=0)\n\npodcast_retriever = RetrievalQA.from_chain_type(llm=retrieval_llm, chain_type=\"stuff\", retriever=docsearch.as_retriever())\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: f3a80d8f-e1fb-40c5-9771-dc8a69c2e696
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"f3a80d8f-e1fb-40c5-9771-dc8a69c2e696\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2524b0ce-edff-4e39-a7a3-1b189f669bf7\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"4eeb28eb70d181b202d91975f673672a6662f3e521665b442dd2a45497143997\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"6107c28d-3773-4eb6-9b87-d5e7df4a6a1a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"945a04e7dca5025c082282e3c1d34917bbb7e30946a48c1dd9af344a38d41ea8\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 32319, \"end_char_idx\": 35351, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "So it's a disproportionate burden on the poor, which makes it, as a scam, one of the more evil scams around. Yes. It's just wrong, then the idea that if you open an account, you should not opt in for overdraft protection. And it's easy to say when you're talking about checks for, like you're writing a check for a Mountain Dew and some cheetos. Yeah, who cares if you're short for that? You can go without that. But when you're talking about your rent check or like an actual grocery bill or something like that, it sucks that you can't get that stuff. But it's better to have to put a couple of things back than to pay $35 for one $2 item that you went over by, right? Yeah, that's a good point. And this was in my case, too. This is also back in the day when you I mean, a lot of times it was a mystery how much you had in your account. Right. Like, you couldn't just get on your phone before you write the check and be like, oh, well, no, I don't have enough money to cover this. Yeah, because even if you balanced your checkbook, sometimes you forgot to carry the one, it wasn't always 100% accurate.\n    \n    \n\n\n## LLM Agent with Tools\n\nExtend our list of tools by creating a [RetrievalQA](https://python.langchain.com/en/latest/modules/chains/index_examples/vector_db_qa.html) chain leveraging our Pinecone knowledge base.\n\n\n```python\nfrom langchain.chains import RetrievalQA\n\nretrieval_llm = OpenAI(temperature=0)\n\npodcast_retriever = RetrievalQA.from_chain_type(llm=retrieval_llm, chain_type=\"stuff\", retriever=docsearch.as_retriever())\n```\n\n\n```python\nexpanded_tools = [\n    Tool(\n        name = \"Search\",\n        func=search.run,\n        description=\"useful for when you need to answer questions about current events\"\n    ),\n    Tool(\n        name = 'Knowledge Base',\n        func=podcast_retriever.run,\n        description=\"Useful for general questions about how to do things and for details on interesting topics. Input should be a fully formed question.\"\n    )\n]\n```\n\n\n```python\n# Re-initialize the agent with our new list of tools\nprompt_with_history = CustomPromptTemplate(\n    template=template_with_history,\n    tools=expanded_tools,\n    input_variables=[\"input\", \"intermediate_steps\", \"history\"]\n)\nllm_chain = LLMChain(llm=llm, prompt=prompt_with_history)\nmulti_tool_names = [tool.name for tool in expanded_tools]\nmulti_tool_agent = LLMSingleActionAgent(\n    llm_chain=llm_chain, \n    output_parser=output_parser,\n    stop=[\"\\nObservation:\"], \n    allowed_tools=multi_tool_names\n)\n```\n\n\n```python\nmulti_tool_memory = ConversationBufferWindowMemory(k=2)\nmulti_tool_executor = AgentExecutor.from_agent_and_tools(agent=multi_tool_agent, tools=expanded_tools, verbose=True, memory=multi_tool_memory)\n```\n\n\n```python\nmulti_tool_executor.run(\"Hi, I'd like to know how you can live without a bank account\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: This is an interesting question. I'm not sure if I have the answer in my knowledge base, so I might need to search for it."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6107c28d-3773-4eb6-9b87-d5e7df4a6a1a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6107c28d-3773-4eb6-9b87-d5e7df4a6a1a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"f3a80d8f-e1fb-40c5-9771-dc8a69c2e696\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f6b3188838f0b3a1789e2db275fe43e481e4ee58c4f64c7f469bc01d03f53be4\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1c705ab5-586a-4e93-894a-08d88621a223\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e5b3c21ec308a8bc1da90066fe09cb8e517991588f5bce019648479121fc6e30\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 33871, \"end_char_idx\": 37148, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "```python\nexpanded_tools = [\n    Tool(\n        name = \"Search\",\n        func=search.run,\n        description=\"useful for when you need to answer questions about current events\"\n    ),\n    Tool(\n        name = 'Knowledge Base',\n        func=podcast_retriever.run,\n        description=\"Useful for general questions about how to do things and for details on interesting topics. Input should be a fully formed question.\"\n    )\n]\n```\n\n\n```python\n# Re-initialize the agent with our new list of tools\nprompt_with_history = CustomPromptTemplate(\n    template=template_with_history,\n    tools=expanded_tools,\n    input_variables=[\"input\", \"intermediate_steps\", \"history\"]\n)\nllm_chain = LLMChain(llm=llm, prompt=prompt_with_history)\nmulti_tool_names = [tool.name for tool in expanded_tools]\nmulti_tool_agent = LLMSingleActionAgent(\n    llm_chain=llm_chain, \n    output_parser=output_parser,\n    stop=[\"\\nObservation:\"], \n    allowed_tools=multi_tool_names\n)\n```\n\n\n```python\nmulti_tool_memory = ConversationBufferWindowMemory(k=2)\nmulti_tool_executor = AgentExecutor.from_agent_and_tools(agent=multi_tool_agent, tools=expanded_tools, verbose=True, memory=multi_tool_memory)\n```\n\n\n```python\nmulti_tool_executor.run(\"Hi, I'd like to know how you can live without a bank account\")\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: This is an interesting question. I'm not sure if I have the answer in my knowledge base, so I might need to search for it.\n    Action: Search\n    Action Input: \"How to live without a bank account\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mUnderbanked households have a checking or savings account but also use alternative financial services such as money orders, check cashing, international remittances, payday loans, refund anticipation loans, rent-to-own services, pawnshop loans, or auto title loans, according to the FDIC.\u001b[0m\u001b[32;1m\u001b[1;3mIt seems like there are alternative financial services available for those who don't have a bank account. I should look into this further to provide a more comprehensive answer.\n    Action: Search\n    Action Input: \"Alternative financial services for those without a bank account\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mInstead, people who are unbanked use alternative financial services\u2014payday loans, money orders, check cashing services, pawnshop loans, and the like\u2014to meet their banking needs. These financial services fill an important role for unbanked individuals, but they can also cause further financial hardship.\u001b[0m\u001b[32;1m\u001b[1;3mIt's important to note that while there are alternatives to having a bank account, relying solely on these services can lead to financial difficulties. I should provide some information on the potential drawbacks of not having a bank account.\n    Action: Knowledge Base\n    Action Input: \"What are the drawbacks of not having a bank account?\"\u001b[0m\n    \n    Observation:\u001b[33;1m\u001b[1;3m Not having a bank account can be dangerous, as the cash has to be stored somewhere and can be exposed to anyone who finds it or comes into the house with a gun to get it. Additionally, not having a bank account means not being exposed to other things that can help, such as building credit history through loans or mortgages, which can ultimately save money."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 1c705ab5-586a-4e93-894a-08d88621a223
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1c705ab5-586a-4e93-894a-08d88621a223\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"6107c28d-3773-4eb6-9b87-d5e7df4a6a1a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"03f90a464312e28a8b4ffd2e8ffce976a3c1a333a4a9cd77eca45193480212fb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"eefeccd3-4aee-4798-84b8-8474d04a1dd3\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"df88a50aa3030a45df8c7672208a2e90a851eddb94658dc3f7cd005304f8e864\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 35875, \"end_char_idx\": 39132, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "I should look into this further to provide a more comprehensive answer.\n    Action: Search\n    Action Input: \"Alternative financial services for those without a bank account\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mInstead, people who are unbanked use alternative financial services\u2014payday loans, money orders, check cashing services, pawnshop loans, and the like\u2014to meet their banking needs. These financial services fill an important role for unbanked individuals, but they can also cause further financial hardship.\u001b[0m\u001b[32;1m\u001b[1;3mIt's important to note that while there are alternatives to having a bank account, relying solely on these services can lead to financial difficulties. I should provide some information on the potential drawbacks of not having a bank account.\n    Action: Knowledge Base\n    Action Input: \"What are the drawbacks of not having a bank account?\"\u001b[0m\n    \n    Observation:\u001b[33;1m\u001b[1;3m Not having a bank account can be dangerous, as the cash has to be stored somewhere and can be exposed to anyone who finds it or comes into the house with a gun to get it. Additionally, not having a bank account means not being exposed to other things that can help, such as building credit history through loans or mortgages, which can ultimately save money. Finally, not having a bank account can be a disproportionate burden on the poor, as overdraft fees can be expensive.\u001b[0m\u001b[32;1m\u001b[1;3mIt's important to provide some resources for those who may be interested in learning more about alternative financial services or how to open a bank account. \n    Action: Knowledge Base\n    Action Input: \"Resources for alternative financial services or opening a bank account\"\u001b[0m\n    \n    Observation:\u001b[33;1m\u001b[1;3m There are a few resources available for alternative financial services or opening a bank account. Prepaid credit cards are becoming more popular and can be found at convenience stores. Capital One offers commercial solutions and a comprehensive suite of financial services tailored to short and long term goals. Airbnb also offers Air Cover for Hosts, which provides $1 million in damage protection, pet damage protection, and income loss protection.\u001b[0m\u001b[32;1m\u001b[1;3mIt's important to note that while prepaid credit cards and alternative financial services can be helpful, they may not offer the same level of protection and benefits as a traditional bank account. It's also important to do research and compare options before making a decision. \n    Final Answer: While it is possible to live without a bank account by using alternative financial services, it may come with potential drawbacks and limitations. It's important to do research and compare options before making a decision, and there are resources available for those who may be interested in opening a bank account or exploring alternative financial services.\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m\n\n\n\n\n\n    \"While it is possible to live without a bank account by using alternative financial services, it may come with potential drawbacks and limitations. It's important to do research and compare options before making a decision, and there are resources available for those who may be interested in opening a bank account or exploring alternative financial services.\""}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: eefeccd3-4aee-4798-84b8-8474d04a1dd3
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"eefeccd3-4aee-4798-84b8-8474d04a1dd3\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1c705ab5-586a-4e93-894a-08d88621a223\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"cda52334f67825acf10eb4e0fdf530b35d7fe7a4fd6a2a195eec133c0419fbb1\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"062e85c4-1529-465c-83f4-59a68c6e249b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b00e1f8a7f410aec0e0be227d1315a814181f8f825f0103aa0a1889aced27f09\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 37149, \"end_char_idx\": 40870, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "Finally, not having a bank account can be a disproportionate burden on the poor, as overdraft fees can be expensive.\u001b[0m\u001b[32;1m\u001b[1;3mIt's important to provide some resources for those who may be interested in learning more about alternative financial services or how to open a bank account. \n    Action: Knowledge Base\n    Action Input: \"Resources for alternative financial services or opening a bank account\"\u001b[0m\n    \n    Observation:\u001b[33;1m\u001b[1;3m There are a few resources available for alternative financial services or opening a bank account. Prepaid credit cards are becoming more popular and can be found at convenience stores. Capital One offers commercial solutions and a comprehensive suite of financial services tailored to short and long term goals. Airbnb also offers Air Cover for Hosts, which provides $1 million in damage protection, pet damage protection, and income loss protection.\u001b[0m\u001b[32;1m\u001b[1;3mIt's important to note that while prepaid credit cards and alternative financial services can be helpful, they may not offer the same level of protection and benefits as a traditional bank account. It's also important to do research and compare options before making a decision. \n    Final Answer: While it is possible to live without a bank account by using alternative financial services, it may come with potential drawbacks and limitations. It's important to do research and compare options before making a decision, and there are resources available for those who may be interested in opening a bank account or exploring alternative financial services.\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m\n\n\n\n\n\n    \"While it is possible to live without a bank account by using alternative financial services, it may come with potential drawbacks and limitations. It's important to do research and compare options before making a decision, and there are resources available for those who may be interested in opening a bank account or exploring alternative financial services.\"\n\n\n\n\n```python\nmulti_tool_executor.run('Can you tell me some interesting facts about whether zoos are good or bad for animals')\n```\n\n    \n    \n    \u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n    \u001b[32;1m\u001b[1;3mThought: This is a complex topic that requires a balanced perspective\n    Action: Knowledge Base\n    Action Input: \"What are the arguments for and against zoos?\"\u001b[0m\n    \n    Observation:\u001b[33;1m\u001b[1;3m The arguments for zoos include that they have gotten a lot better in the last 30-40 years, they participate in research and conservation projects, and they can help save species from extinction. The arguments against zoos include that they are still businesses, they can be counterproductive in terms of educating the public, and they can have a negative impact on the life span of animals in captivity.\u001b[0m\u001b[32;1m\u001b[1;3mIt's important to consider both sides of the argument before coming to a conclusion\n    Action: Search\n    Action Input: \"What are some examples of successful zoo conservation projects?\"\u001b[0m\n    \n    Observation:\u001b[36;1m\u001b[1;3mThere are dedicated species survival programs which have helped species come out from the brink of extinction, good examples of that being the black-footed ferrets, the red wolves, the Przewalski's wild horse, and the California condors.\u001b[0m\u001b[32;1m\u001b[1;3mWhile there are valid arguments on both sides, it seems that zoos can have a positive impact on conservation efforts for endangered species.\n    Final Answer: Zoos can have both positive and negative effects on animals, but they can play a role in conservation efforts for endangered species. It's important to consider both sides of the argument and do research before forming an opinion.\u001b[0m\n    \n    \u001b[1m> Finished chain.\u001b[0m"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 062e85c4-1529-465c-83f4-59a68c6e249b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb", "title": "How to build a tool-using agent with LangChain", "tokens": 10120, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"062e85c4-1529-465c-83f4-59a68c6e249b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"525158bc025ac66a8380eef18361f30e4fc247905b6ccdcd90aede2dd61cda8d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"eefeccd3-4aee-4798-84b8-8474d04a1dd3\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_build_a_tool-using_agent_with_Langchain.ipynb\", \"title\": \"How to build a tool-using agent with LangChain\", \"tokens\": 10120, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"81c34a5dfdf1061c93400119e42a74b685ee39c86410dd29ffab3eab76d29713\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 40880, \"end_char_idx\": 41470, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "ref_doc_id": "a3c7eeaa-5a63-48db-a7d2-497b55dd4a0e", "chroma:document": "\"Zoos can have both positive and negative effects on animals, but they can play a role in conservation efforts for endangered species. It's important to consider both sides of the argument and do research before forming an opinion.\"\n\n\n\nYou now have a template to deploy conversational agents with tools. If you want to extend this with a Custom Agent to add your own retry behaviour or treatment of input/output variables, then follow [this article](https://python.langchain.com/en/latest/modules/agents/agents/custom_agent.html).\n\nWe look forward to seeing what you build!\n\n\n```python\n\n```"}


