# embeddings_queue

created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 7616622e-2880-49fe-841b-6e71178e48a9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb", "title": "Batch processing with the Batch API", "tokens": 7938, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7616622e-2880-49fe-841b-6e71178e48a9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"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\": \"dd18b174-326d-4229-ad6c-3b96a839456d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"143d1ff00605bdcd7deef3627aa3385ba87f078aaedf31eeaddec44418405200\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"ba657de4-de49-40e7-a995-038e32bf49ce\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"400e705cc2455242999aa2464caa50a1a69029f691d0dda60e2502afa66f17c5\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"9bd14ccb-96aa-4045-81d6-9d40847e8360\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"be19546fc0ff96c8598a033ae3a07a08c5989dcdc1075edfc342e19bcd9ebfa0\", \"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": "dd18b174-326d-4229-ad6c-3b96a839456d", "doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "ref_doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "chroma:document": "Lawn &amp; Garden', 'Outdoor D\u00e9cor', 'Doo.</td>\n      <td>https://m.media-amazon.com/images/I/41RgefVq70.</td>\n      <td>['https://m.media-amazon.com/images/I/41RgefVq.</td>\n      <td>NaN</td>\n      <td>.</td>\n      <td>Green</td>\n      <td>Polyethylene</td>\n      <td>Modern</td>\n      <td>[]</td>\n      <td>[{'Brand': ' MUYETOL '}, {'Size': ' 26.8*26.8 .</td>\n      <td>['PLANT REPOTTING MAT SIZE: 26.8\" x 26.8\", squ.</td>\n      <td>NaN</td>\n      <td>['Brand: MUYETOL', 'Size: 26.8*26.8', 'Item We.</td>\n      <td>b2ede786-3f51-5a45-9a5b-bcf856958cd8</td>\n      <td>2024-02-02 15:15:09</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>B0C1MRB2M8</td>\n      <td>https://www.amazon.com/dp/B0C1MRB2M8</td>\n      <td>Pickleball Doormat, Welcome Doormat Absorbent .</td>\n      <td>VEWETOL</td>\n      <td>$13.99</td>\n      <td>Only 10 left in stock - order soon.</td>\n      <td>['Patio, Lawn &amp; Garden', 'Outdoor D\u00e9cor', 'Doo.</td>\n      <td>https://m.media-amazon.com/images/I/61vz1Igler.</td>\n      <td>['https://m.media-amazon.com/images/I/61vz1Igl.</td>\n      <td>NaN</td>\n      <td>.</td>\n      <td>A5589</td>\n      <td>Rubber</td>\n      <td>Modern</td>\n      <td>[]</td>\n      <td>[{'Brand': ' VEWETOL '}, {'Size': ' 16*24INCH .</td>\n      <td>['Specifications: 16x24 Inch ', \" High-Quality.</td>\n      <td>The decorative doormat features a subtle textu.</td>\n      <td>['Brand: VEWETOL', 'Size: 16*24INCH', 'Materia.</td>\n      <td>8fd9377b-cfa6-5f10-835c-6b8eca2816b5</td>\n      <td>2024-02-02 15:15:10</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>B0CG1N9QRC</td>\n      <td>https://www.amazon.com/dp/B0CG1N9QRC</td>\n      <td>JOIN IRON Foldable TV Trays for Eating Set of .</td>\n      <td>JOIN IRON Store</td>\n      <td>$89.99</td>\n      <td>Usually ships within 5 to 6 weeks</td>\n      <td>['Home &amp; Kitchen', 'Furniture',"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 9bd14ccb-96aa-4045-81d6-9d40847e8360
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb", "title": "Batch processing with the Batch API", "tokens": 7938, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"9bd14ccb-96aa-4045-81d6-9d40847e8360\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"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\": \"dd18b174-326d-4229-ad6c-3b96a839456d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"143d1ff00605bdcd7deef3627aa3385ba87f078aaedf31eeaddec44418405200\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"7616622e-2880-49fe-841b-6e71178e48a9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ca1609fe11f4f0d6412ead3867c8100b3ce7096a62589e38e1b4597b8e35254d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a522c7ae-0099-4f10-8891-d4ae1a883944\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"615a265bfc3235a916b751393dac9a9e41297b986abe183d367e966f55189c0f\", \"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": "dd18b174-326d-4229-ad6c-3b96a839456d", "doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "ref_doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "chroma:document": "Lawn &amp; Garden', 'Outdoor D\u00e9cor', 'Doo.</td>\n      <td>https://m.media-amazon.com/images/I/61vz1Igler.</td>\n      <td>['https://m.media-amazon.com/images/I/61vz1Igl.</td>\n      <td>NaN</td>\n      <td>.</td>\n      <td>A5589</td>\n      <td>Rubber</td>\n      <td>Modern</td>\n      <td>[]</td>\n      <td>[{'Brand': ' VEWETOL '}, {'Size': ' 16*24INCH .</td>\n      <td>['Specifications: 16x24 Inch ', \" High-Quality.</td>\n      <td>The decorative doormat features a subtle textu.</td>\n      <td>['Brand: VEWETOL', 'Size: 16*24INCH', 'Materia.</td>\n      <td>8fd9377b-cfa6-5f10-835c-6b8eca2816b5</td>\n      <td>2024-02-02 15:15:10</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>B0CG1N9QRC</td>\n      <td>https://www.amazon.com/dp/B0CG1N9QRC</td>\n      <td>JOIN IRON Foldable TV Trays for Eating Set of .</td>\n      <td>JOIN IRON Store</td>\n      <td>$89.99</td>\n      <td>Usually ships within 5 to 6 weeks</td>\n      <td>['Home &amp; Kitchen', 'Furniture', 'Game &amp; Recrea.</td>\n      <td>https://m.media-amazon.com/images/I/41p4d4VJnN.</td>\n      <td>['https://m.media-amazon.com/images/I/41p4d4VJ.</td>\n      <td>NaN</td>\n      <td>.</td>\n      <td>Grey Set of 4</td>\n      <td>Iron</td>\n      <td>X Classic Style</td>\n      <td>[]</td>\n      <td>NaN</td>\n      <td>['Includes 4 Folding Tv Tray Tables And one Co.</td>\n      <td>Set of Four Folding Trays With Matching Storag.</td>\n      <td>['Brand: JOIN IRON', 'Shape: Rectangular', 'In.</td>\n      <td>bdc9aa30-9439-50dc-8e89-213ea211d66a</td>\n      <td>2024-02-02 15:15:11</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows \u00d7 25 columns</p>\n</div>\n\n\n\n### Processing step \n\nAgain, we will first prepare our requests with the Chat Completions endpoint, and create the batch file afterwards."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: a522c7ae-0099-4f10-8891-d4ae1a883944
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb", "title": "Batch processing with the Batch API", "tokens": 7938, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a522c7ae-0099-4f10-8891-d4ae1a883944\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"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\": \"dd18b174-326d-4229-ad6c-3b96a839456d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"143d1ff00605bdcd7deef3627aa3385ba87f078aaedf31eeaddec44418405200\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"9bd14ccb-96aa-4045-81d6-9d40847e8360\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a1af3533aca468ea12200188dd3c9658e4c6ccad792d7cdb2bd592edbeeaabb5\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"4c6d6ff8-4240-4b86-843a-20d74fd53ed4\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"030b165c81347300de68349b06097328256cf66a7cbdb15c01d23bca776b36c2\", \"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": "dd18b174-326d-4229-ad6c-3b96a839456d", "doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "ref_doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "chroma:document": "amazon.com/dp/B0CG1N9QRC</td>\n      <td>JOIN IRON Foldable TV Trays for Eating Set of .</td>\n      <td>JOIN IRON Store</td>\n      <td>$89.99</td>\n      <td>Usually ships within 5 to 6 weeks</td>\n      <td>['Home &amp; Kitchen', 'Furniture', 'Game &amp; Recrea.</td>\n      <td>https://m.media-amazon.com/images/I/41p4d4VJnN.</td>\n      <td>['https://m.media-amazon.com/images/I/41p4d4VJ.</td>\n      <td>NaN</td>\n      <td>.</td>\n      <td>Grey Set of 4</td>\n      <td>Iron</td>\n      <td>X Classic Style</td>\n      <td>[]</td>\n      <td>NaN</td>\n      <td>['Includes 4 Folding Tv Tray Tables And one Co.</td>\n      <td>Set of Four Folding Trays With Matching Storag.</td>\n      <td>['Brand: JOIN IRON', 'Shape: Rectangular', 'In.</td>\n      <td>bdc9aa30-9439-50dc-8e89-213ea211d66a</td>\n      <td>2024-02-02 15:15:11</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows \u00d7 25 columns</p>\n</div>\n\n\n\n### Processing step \n\nAgain, we will first prepare our requests with the Chat Completions endpoint, and create the batch file afterwards.\n\n\n```python\ncaption_system_prompt = '''\nYour goal is to generate short, descriptive captions for images of items.\nYou will be provided with an item image and the name of that item and you will output a caption that captures the most important information about the item.\nIf there are multiple items depicted, refer to the name provided to understand which item you should describe.\nYour generated caption should be short (1 sentence), and include only the most important information about the item.\nThe most important information could be: the type of item, the style (if mentioned), the material or color if especially relevant and/or any distinctive features.\nKeep it short and to the point.\n'''\n\ndef get_caption(img_url, title):\n    response = client.chat.completions.create(\n    model=\"gpt-4o-mini\",\n    temperature=0.2,\n    max_tokens=300,\n    messages=[\n        {\n            \"role\": \"system\",\n            \"content\": caption_system_prompt\n        },\n        {\n            \"role\": \"user\",\n            \"content\": [\n                {\n                    \"type\": \"text\",\n                    \"text\": title\n                },\n                # The content type should be \"image_url\" to use gpt-4-turbo's vision capabilities\n                {\n                    \"type\": \"image_url\",\n                    \"image_url\": {\n                        \"url\": img_url\n                    }\n                },\n            ],\n        }\n    ]\n    )\n\n    return response.choices[0].message.content\n```\n\n\n```python\n# Testing on a few images\nfor _, row in df[:5].iterrows():\n    img_url = row['primary_image']\n    caption = get_caption(img_url, row['title'])\n    img = Image(url=img_url)\n    display(img)\n    print(f\"CAPTION: {caption}\\n\\n\")\n```\n\n\n<img src=\"https://m.media-amazon.com/images/I/416WaLx10jL._SS522_.jpg\"/>"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 4c6d6ff8-4240-4b86-843a-20d74fd53ed4
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb", "title": "Batch processing with the Batch API", "tokens": 7938, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4c6d6ff8-4240-4b86-843a-20d74fd53ed4\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"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\": \"dd18b174-326d-4229-ad6c-3b96a839456d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"143d1ff00605bdcd7deef3627aa3385ba87f078aaedf31eeaddec44418405200\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a522c7ae-0099-4f10-8891-d4ae1a883944\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4bd34e0b0aef9de2c62a87d3ebe0194bfbb16f46e20f656886337cb243aa6426\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"dc5e9801-a026-4748-a478-0c349636da0c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"837786bc8cfa394a6cf33ab1f94d8d6ea39824bd18a099d2fefcc6c2db85fa34\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 21366, \"end_char_idx\": 24465, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "ref_doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "chroma:document": "```python\ncaption_system_prompt = '''\nYour goal is to generate short, descriptive captions for images of items.\nYou will be provided with an item image and the name of that item and you will output a caption that captures the most important information about the item.\nIf there are multiple items depicted, refer to the name provided to understand which item you should describe.\nYour generated caption should be short (1 sentence), and include only the most important information about the item.\nThe most important information could be: the type of item, the style (if mentioned), the material or color if especially relevant and/or any distinctive features.\nKeep it short and to the point.\n'''\n\ndef get_caption(img_url, title):\n    response = client.chat.completions.create(\n    model=\"gpt-4o-mini\",\n    temperature=0.2,\n    max_tokens=300,\n    messages=[\n        {\n            \"role\": \"system\",\n            \"content\": caption_system_prompt\n        },\n        {\n            \"role\": \"user\",\n            \"content\": [\n                {\n                    \"type\": \"text\",\n                    \"text\": title\n                },\n                # The content type should be \"image_url\" to use gpt-4-turbo's vision capabilities\n                {\n                    \"type\": \"image_url\",\n                    \"image_url\": {\n                        \"url\": img_url\n                    }\n                },\n            ],\n        }\n    ]\n    )\n\n    return response.choices[0].message.content\n```\n\n\n```python\n# Testing on a few images\nfor _, row in df[:5].iterrows():\n    img_url = row['primary_image']\n    caption = get_caption(img_url, row['title'])\n    img = Image(url=img_url)\n    display(img)\n    print(f\"CAPTION: {caption}\\n\\n\")\n```\n\n\n<img src=\"https://m.media-amazon.com/images/I/416WaLx10jL._SS522_.jpg\"/>\n\n\n    CAPTION: A stylish white free-standing shoe rack featuring multiple layers and eight double hooks, perfect for organizing shoes and accessories in living rooms, bathrooms, or hallways.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/31SejUEWY7L._SS522_.jpg\"/>\n\n\n    CAPTION: Set of 2 black leather dining chairs featuring a sleek design with vertical stitching and sturdy wooden legs.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/41RgefVq70L._SS522_.jpg\"/>\n\n\n    CAPTION: The MUYETOL Plant Repotting Mat is a waterproof, portable, and foldable gardening work mat measuring 26.8\" x 26.8\", designed for easy soil changing and indoor transplanting.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/61vz1IglerL._SS522_.jpg\"/>\n\n\n    CAPTION: Absorbent non-slip doormat featuring the phrase \"It's a good day to play PICKLEBALL\" with paddle graphics, measuring 16x24 inches.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/41p4d4VJnNL._SS522_.jpg\"/>\n\n\n    CAPTION: Set of 4 foldable TV trays in grey, featuring a compact design with a stand for easy storage, perfect for small spaces.\n    \n    \n\n\n### Creating the batch job\n\nAs with the first example, we will create an array of json tasks to generate a `jsonl` file and use it to create the batch job."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: dc5e9801-a026-4748-a478-0c349636da0c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb", "title": "Batch processing with the Batch API", "tokens": 7938, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"dc5e9801-a026-4748-a478-0c349636da0c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"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\": \"dd18b174-326d-4229-ad6c-3b96a839456d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"143d1ff00605bdcd7deef3627aa3385ba87f078aaedf31eeaddec44418405200\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"4c6d6ff8-4240-4b86-843a-20d74fd53ed4\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"00a574d2ee59edfc7ab326a44ccb868eb11ad846f58ca1ba2bd3bea87250806b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"ecf5b3ed-7a98-4a5d-aa3a-879eaaa7b558\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"761b184f443df00c375eb8b7b1974b0018950cc81bc5628cead3e0dfaf5791b8\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 23095, \"end_char_idx\": 26126, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "ref_doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "chroma:document": "<img src=\"https://m.media-amazon.com/images/I/416WaLx10jL._SS522_.jpg\"/>\n\n\n    CAPTION: A stylish white free-standing shoe rack featuring multiple layers and eight double hooks, perfect for organizing shoes and accessories in living rooms, bathrooms, or hallways.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/31SejUEWY7L._SS522_.jpg\"/>\n\n\n    CAPTION: Set of 2 black leather dining chairs featuring a sleek design with vertical stitching and sturdy wooden legs.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/41RgefVq70L._SS522_.jpg\"/>\n\n\n    CAPTION: The MUYETOL Plant Repotting Mat is a waterproof, portable, and foldable gardening work mat measuring 26.8\" x 26.8\", designed for easy soil changing and indoor transplanting.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/61vz1IglerL._SS522_.jpg\"/>\n\n\n    CAPTION: Absorbent non-slip doormat featuring the phrase \"It's a good day to play PICKLEBALL\" with paddle graphics, measuring 16x24 inches.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/41p4d4VJnNL._SS522_.jpg\"/>\n\n\n    CAPTION: Set of 4 foldable TV trays in grey, featuring a compact design with a stand for easy storage, perfect for small spaces.\n    \n    \n\n\n### Creating the batch job\n\nAs with the first example, we will create an array of json tasks to generate a `jsonl` file and use it to create the batch job.\n\n\n```python\n# Creating an array of json tasks\n\ntasks = []\n\nfor index, row in df.iterrows():\n    \n    title = row['title']\n    img_url = row['primary_image']\n    \n    task = {\n        \"custom_id\": f\"task-{index}\",\n        \"method\": \"POST\",\n        \"url\": \"/v1/chat/completions\",\n        \"body\": {\n            # This is what you would have in your Chat Completions API call\n            \"model\": \"gpt-4o-mini\",\n            \"temperature\": 0.2,\n            \"max_tokens\": 300,\n            \"messages\": [\n                {\n                    \"role\": \"system\",\n                    \"content\": caption_system_prompt\n                },\n                {\n                    \"role\": \"user\",\n                    \"content\": [\n                        {\n                            \"type\": \"text\",\n                            \"text\": title\n                        },\n                        {\n                            \"type\": \"image_url\",\n                            \"image_url\": {\n                                \"url\": img_url\n                            }\n                        },\n                    ],\n                }\n            ]            \n        }\n    }\n    \n    tasks.append(task)\n```\n\n\n```python\n# Creating the file\n\nfile_name = \"data/batch_tasks_furniture.jsonl\"\n\nwith open(file_name, 'w') as file:\n    for obj in tasks:\n        file.write(json.dumps(obj) + '\\n')\n```\n\n\n```python\n# Uploading the file \n\nbatch_file = client.files.create(\n  file=open(file_name, \"rb\"),\n  purpose=\"batch\"\n)\n```\n\n\n```python\n# Creating the job\n\nbatch_job = client.batches.create(\n  input_file_id=batch_file.id,\n  endpoint=\"/v1/chat/completions\",\n  completion_window=\"24h\"\n)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: ecf5b3ed-7a98-4a5d-aa3a-879eaaa7b558
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb", "title": "Batch processing with the Batch API", "tokens": 7938, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ecf5b3ed-7a98-4a5d-aa3a-879eaaa7b558\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"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\": \"dd18b174-326d-4229-ad6c-3b96a839456d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"143d1ff00605bdcd7deef3627aa3385ba87f078aaedf31eeaddec44418405200\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"dc5e9801-a026-4748-a478-0c349636da0c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"778956c968dc9640fb2a56e00b92f83208e73c727fdc03c371f7a3c57642f961\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"154bef53-4eb4-4faa-b95c-82a1d61c6bd6\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a100e67df780647c9af24d383f5263c9c1e1b5e5badb10e391815715ba829630\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 24310, \"end_char_idx\": 27662, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "ref_doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "chroma:document": "### Creating the batch job\n\nAs with the first example, we will create an array of json tasks to generate a `jsonl` file and use it to create the batch job.\n\n\n```python\n# Creating an array of json tasks\n\ntasks = []\n\nfor index, row in df.iterrows():\n    \n    title = row['title']\n    img_url = row['primary_image']\n    \n    task = {\n        \"custom_id\": f\"task-{index}\",\n        \"method\": \"POST\",\n        \"url\": \"/v1/chat/completions\",\n        \"body\": {\n            # This is what you would have in your Chat Completions API call\n            \"model\": \"gpt-4o-mini\",\n            \"temperature\": 0.2,\n            \"max_tokens\": 300,\n            \"messages\": [\n                {\n                    \"role\": \"system\",\n                    \"content\": caption_system_prompt\n                },\n                {\n                    \"role\": \"user\",\n                    \"content\": [\n                        {\n                            \"type\": \"text\",\n                            \"text\": title\n                        },\n                        {\n                            \"type\": \"image_url\",\n                            \"image_url\": {\n                                \"url\": img_url\n                            }\n                        },\n                    ],\n                }\n            ]            \n        }\n    }\n    \n    tasks.append(task)\n```\n\n\n```python\n# Creating the file\n\nfile_name = \"data/batch_tasks_furniture.jsonl\"\n\nwith open(file_name, 'w') as file:\n    for obj in tasks:\n        file.write(json.dumps(obj) + '\\n')\n```\n\n\n```python\n# Uploading the file \n\nbatch_file = client.files.create(\n  file=open(file_name, \"rb\"),\n  purpose=\"batch\"\n)\n```\n\n\n```python\n# Creating the job\n\nbatch_job = client.batches.create(\n  input_file_id=batch_file.id,\n  endpoint=\"/v1/chat/completions\",\n  completion_window=\"24h\"\n)\n```\n\n\n```python\nbatch_job = client.batches.retrieve(batch_job.id)\nprint(batch_job)\n```\n\n### Getting results\n\nAs with the first example, we can retrieve results once the batch job is done.\n\nReminder: the results are not in the same order as in the input file.\nMake sure to check the custom_id to match the results against the input requests\n\n\n```python\n# Retrieving result file\n\nresult_file_id = batch_job.output_file_id\nresult = client.files.content(result_file_id).content\n```\n\n\n```python\nresult_file_name = \"data/batch_job_results_furniture.jsonl\"\n\nwith open(result_file_name, 'wb') as file:\n    file.write(result)\n```\n\n\n```python\n#\u00a0Loading data from saved file\n\nresults = []\nwith open(result_file_name, 'r') as file:\n    for line in file:\n        # Parsing the JSON string into a dict and appending to the list of results\n        json_object = json.loads(line.strip())\n        results.append(json_object)\n```\n\n\n```python\n# Reading only the first results\nfor res in results[:5]:\n    task_id = res['custom_id']\n    # Getting index from task id\n    index = task_id.split('-')[-1]\n    result = res['response']['body']['choices'][0]['message']['content']\n    item = df.iloc[int(index)]\n    img_url = item['primary_image']\n    img = Image(url=img_url)\n    display(img)\n    print(f\"CAPTION: {result}\\n\\n\")\n```\n\n\n<img src=\"https://m.media-amazon.com/images/I/31FOa-k+EtL._SS522_.jpg\"/>\n\n\n    CAPTION: Brushed brass pedestal towel rack with a sleek, modern design, featuring multiple bars for hanging towels, measuring 25.75 x 14.44 x 32 inches."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 154bef53-4eb4-4faa-b95c-82a1d61c6bd6
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb", "title": "Batch processing with the Batch API", "tokens": 7938, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"154bef53-4eb4-4faa-b95c-82a1d61c6bd6\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"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\": \"dd18b174-326d-4229-ad6c-3b96a839456d\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"143d1ff00605bdcd7deef3627aa3385ba87f078aaedf31eeaddec44418405200\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"ecf5b3ed-7a98-4a5d-aa3a-879eaaa7b558\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/batch_processing.ipynb\", \"title\": \"Batch processing with the Batch API\", \"tokens\": 7938, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"773ea5f929976523f1ea28cf0829ad39965175ae43e4b49d09bbb889067a42be\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 26129, \"end_char_idx\": 29099, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "ref_doc_id": "dd18b174-326d-4229-ad6c-3b96a839456d", "chroma:document": "```python\nbatch_job = client.batches.retrieve(batch_job.id)\nprint(batch_job)\n```\n\n### Getting results\n\nAs with the first example, we can retrieve results once the batch job is done.\n\nReminder: the results are not in the same order as in the input file.\nMake sure to check the custom_id to match the results against the input requests\n\n\n```python\n# Retrieving result file\n\nresult_file_id = batch_job.output_file_id\nresult = client.files.content(result_file_id).content\n```\n\n\n```python\nresult_file_name = \"data/batch_job_results_furniture.jsonl\"\n\nwith open(result_file_name, 'wb') as file:\n    file.write(result)\n```\n\n\n```python\n#\u00a0Loading data from saved file\n\nresults = []\nwith open(result_file_name, 'r') as file:\n    for line in file:\n        # Parsing the JSON string into a dict and appending to the list of results\n        json_object = json.loads(line.strip())\n        results.append(json_object)\n```\n\n\n```python\n# Reading only the first results\nfor res in results[:5]:\n    task_id = res['custom_id']\n    # Getting index from task id\n    index = task_id.split('-')[-1]\n    result = res['response']['body']['choices'][0]['message']['content']\n    item = df.iloc[int(index)]\n    img_url = item['primary_image']\n    img = Image(url=img_url)\n    display(img)\n    print(f\"CAPTION: {result}\\n\\n\")\n```\n\n\n<img src=\"https://m.media-amazon.com/images/I/31FOa-k+EtL._SS522_.jpg\"/>\n\n\n    CAPTION: Brushed brass pedestal towel rack with a sleek, modern design, featuring multiple bars for hanging towels, measuring 25.75 x 14.44 x 32 inches.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/41z8YktAkGL._SS522_.jpg\"/>\n\n\n    CAPTION: Black round end table featuring a tempered glass top and a metal frame, with a lower shelf for additional storage.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/511N0PuE9EL._SS522_.jpg\"/>\n\n\n    CAPTION: Black collapsible and height-adjustable telescoping stool, portable and designed for makeup artists and hairstylists, shown in various stages of folding for easy transport.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/31dCSKQ14YL._SS522_.jpg\"/>\n\n\n    CAPTION: Ergonomic pink gaming chair featuring breathable fabric, adjustable height, lumbar support, a footrest, and a swivel recliner function.\n    \n    \n\n\n\n<img src=\"https://m.media-amazon.com/images/I/51OPfpn9ovL._SS522_.jpg\"/>\n\n\n    CAPTION: A set of two Glitzhome adjustable bar stools featuring a mid-century modern design with swivel seats, PU leather upholstery, and wooden backrests.\n    \n    \n\n\n## Wrapping up\n\nIn this cookbook, we have seen two examples of how to use the new Batch API, but keep in mind that the Batch API works the same way as the Chat Completions endpoint, supporting the same parameters and most of the recent models (gpt-4o, gpt-4o-mini, gpt-4-turbo, gpt-3.5-turbo...).\n\nBy using this API, you can significantly reduce costs, so we recommend switching every workload that can happen async to a batch job with this new API."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: b90ef9de-5350-4f39-84c1-10daf600c0c8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b90ef9de-5350-4f39-84c1-10daf600c0c8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2452d194-9599-4d9c-92d5-939ec9b5e382\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"c86dc584f102d4902d6a08323d7227955fd5a4ca1e0f7068c7f3bb4511714465\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2543, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "# How to fine-tune chat models\n\nFine-tuning improves the model by training on many more examples than can fit in a prompt, letting you achieve better results on a wide number of tasks. This notebook provides a step-by-step guide for our new GPT-4o mini fine-tuning. We'll perform entity extraction using the [RecipeNLG dataset](https://github.com/Glorf/recipenlg), which provides various recipes and a list of extracted generic ingredients for each. This is a common dataset for named entity recognition (NER) tasks.\n\nNote: **GPT-4o mini fine-tuning is available to developers in our [Tier 4 and 5 usage tiers](https://platform.openai.com/docs/guides/rate-limits/usage-tiers).** You can start fine-tuning GPT-4o mini by visiting your fine-tuning dashboard, clicking \"create\", and selecting \u201cgpt-4o-mini-2024-07-18\u201d from the base model drop-down.\n\nWe will go through the following steps:\n\n1. **Setup:** Loading our dataset and filtering down to one domain to fine-tune on.\n2. **Data preparation:** Preparing your data for fine-tuning by creating training and validation examples, and uploading them to the `Files` endpoint.\n3. **Fine-tuning:** Creating your fine-tuned model.\n4. **Inference:** Using your fine-tuned model for inference on new inputs.\n\nBy the end of this you should be able to train, evaluate and deploy a fine-tuned `gpt-4o-mini-2024-07-18` model.\n\nFor more information on fine-tuning, you can refer to our [documentation guide](https://platform.openai.com/docs/guides/fine-tuning) or [API reference](https://platform.openai.com/docs/api-reference/fine-tuning).\n\n\n## Setup\n\n\n\n```python\n# make sure to use the latest version of the openai python package\n!pip install --upgrade --quiet openai\n```\n\n\n```python\nimport json\nimport openai\nimport os\nimport pandas as pd\nfrom pprint import pprint\n\nclient = openai.OpenAI(\n    api_key=os.environ.get(\"OPENAI_API_KEY\"),\n    organization=\"<org id>\",\n    project=\"<project id>\",\n)\n```\n\nFine-tuning works best when focused on a particular domain. It's important to make sure your dataset is both focused enough for the model to learn, but general enough that unseen examples won't be missed. Having this in mind, we have extracted a subset from the RecipesNLG dataset to only contain documents from [cookbooks.com](https://cookbooks.com/).\n\n\n\n```python\n# Read in the dataset we'll use for this task.\n# This will be the RecipesNLG dataset, which we've cleaned to only contain documents from www.cookbooks.com\nrecipe_df = pd.read_csv(\"data/cookbook_recipes_nlg_10k.csv\")\n\nrecipe_df.head()\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 2452d194-9599-4d9c-92d5-939ec9b5e382
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2452d194-9599-4d9c-92d5-939ec9b5e382\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b90ef9de-5350-4f39-84c1-10daf600c0c8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"91daa5a3fa0c5171155a487f411779829464e62a21cce4200449ac9f47210e82\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c08aee88-360d-402e-9789-800feaa7ebee\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5b4f1097917b2acb5c1a0ed444aec0aff4ab79093f31dc26597914d91042ff98\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1580, \"end_char_idx\": 3945, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "## Setup\n\n\n\n```python\n# make sure to use the latest version of the openai python package\n!pip install --upgrade --quiet openai\n```\n\n\n```python\nimport json\nimport openai\nimport os\nimport pandas as pd\nfrom pprint import pprint\n\nclient = openai.OpenAI(\n    api_key=os.environ.get(\"OPENAI_API_KEY\"),\n    organization=\"<org id>\",\n    project=\"<project id>\",\n)\n```\n\nFine-tuning works best when focused on a particular domain. It's important to make sure your dataset is both focused enough for the model to learn, but general enough that unseen examples won't be missed. Having this in mind, we have extracted a subset from the RecipesNLG dataset to only contain documents from [cookbooks.com](https://cookbooks.com/).\n\n\n\n```python\n# Read in the dataset we'll use for this task.\n# This will be the RecipesNLG dataset, which we've cleaned to only contain documents from www.cookbooks.com\nrecipe_df = pd.read_csv(\"data/cookbook_recipes_nlg_10k.csv\")\n\nrecipe_df.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>title</th>\n      <th>ingredients</th>\n      <th>directions</th>\n      <th>link</th>\n      <th>source</th>\n      <th>NER</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>No-Bake Nut Cookies</td>\n      <td>[\"1 c. firmly packed brown sugar\", \"1/2 c. eva...</td>\n      <td>[\"In a heavy 2-quart saucepan, mix brown sugar...</td>\n      <td>www.cookbooks.com/Recipe-Details.aspx?id=44874</td>\n      <td>www.cookbooks.com</td>\n      <td>[\"brown sugar\", \"milk\", \"vanilla\", \"nuts\", \"bu...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Jewell Ball'S Chicken</td>\n      <td>[\"1 small jar chipped beef, cut up\", \"4 boned ...</td>\n      <td>[\"Place chipped beef on bottom of baking dish....</td>\n      <td>www.cookbooks.com/Recipe-Details.aspx?id=699419</td>\n      <td>www.cookbooks.com</td>\n      <td>[\"beef\", \"chicken breasts\", \"cream of mushroom...</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>Creamy Corn</td>\n      <td>[\"2 (16 oz.) pkg. frozen corn\", \"1 (8 oz.) pkg...</td>\n      <td>[\"In a slow cooker, combine all ingredients."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c08aee88-360d-402e-9789-800feaa7ebee
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c08aee88-360d-402e-9789-800feaa7ebee\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2452d194-9599-4d9c-92d5-939ec9b5e382\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0ef395b625150d129b410bf4e24ce35e3faaa49c578dbd86c48a379267f5be56\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"324e8a03-0554-4208-bf2f-c73aeff6507f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"c26544e0cd9487c7a5bb348b6b38075ee50a7452b7f7d59f430aaf4ae091db57\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3849, \"end_char_idx\": 6484, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "pkg. frozen corn\", \"1 (8 oz.) pkg...</td>\n      <td>[\"In a slow cooker, combine all ingredients. C...</td>\n      <td>www.cookbooks.com/Recipe-Details.aspx?id=10570</td>\n      <td>www.cookbooks.com</td>\n      <td>[\"frozen corn\", \"cream cheese\", \"butter\", \"gar...</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>Chicken Funny</td>\n      <td>[\"1 large whole chicken\", \"2 (10 1/2 oz.) cans...</td>\n      <td>[\"Boil and debone chicken.\", \"Put bite size pi...</td>\n      <td>www.cookbooks.com/Recipe-Details.aspx?id=897570</td>\n      <td>www.cookbooks.com</td>\n      <td>[\"chicken\", \"chicken gravy\", \"cream of mushroo...</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>Reeses Cups(Candy)</td>\n      <td>[\"1 c. peanut butter\", \"3/4 c. graham cracker ...</td>\n      <td>[\"Combine first four ingredients and press in ...</td>\n      <td>www.cookbooks.com/Recipe-Details.aspx?id=659239</td>\n      <td>www.cookbooks.com</td>\n      <td>[\"peanut butter\", \"graham cracker crumbs\", \"bu...</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\n## Data preparation\n\nWe'll begin by preparing our data. When fine-tuning with the `ChatCompletion` format, each training example is a simple list of `messages`. For example, an entry could look like:\n\n```\n[{'role': 'system',\n  'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'},\n\n {'role': 'user',\n  'content': 'Title: No-Bake Nut Cookies\\n\\nIngredients: [\"1 c. firmly packed brown sugar\", \"1/2 c. evaporated milk\", \"1/2 tsp. vanilla\", \"1/2 c. broken nuts (pecans)\", \"2 Tbsp. butter or margarine\", \"3 1/2 c. bite size shredded rice biscuits\"]\\n\\nGeneric ingredients: '},\n\n {'role': 'assistant',\n  'content': '[\"brown sugar\", \"milk\", \"vanilla\", \"nuts\", \"butter\", \"bite size shredded rice biscuits\"]'}]\n```\n\nDuring the training process this conversation will be split, with the final entry being the `completion` that the model will produce, and the remainder of the `messages` acting as the prompt. Consider this when building your training examples - if your model will act on multi-turn conversations, then please provide representative examples so it doesn't perform poorly when the conversation starts to expand.\n\nPlease note that currently there is a 4096 token limit for each training example. Anything longer than this will be truncated at 4096 tokens.\n\n\n\n```python\nsystem_message = \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"\n\n\ndef create_user_message(row):\n    return f\"Title: {row['title']}\\n\\nIngredients: {row['ingredients']}\\n\\nGeneric ingredients: \""}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 324e8a03-0554-4208-bf2f-c73aeff6507f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"324e8a03-0554-4208-bf2f-c73aeff6507f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c08aee88-360d-402e-9789-800feaa7ebee\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"366e6add21fbcdf4c037a2db0e18db1af4ce9b1d35126c7e971841dd55cd2a8f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"699f50ef-be76-4088-9a18-36ff9ffeba1f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b551c0abfdfe8eea9f7758ed3a21185e68cabd23e0a597a482293d5b9e77cdbf\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4873, \"end_char_idx\": 8126, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "## Data preparation\n\nWe'll begin by preparing our data. When fine-tuning with the `ChatCompletion` format, each training example is a simple list of `messages`. For example, an entry could look like:\n\n```\n[{'role': 'system',\n  'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'},\n\n {'role': 'user',\n  'content': 'Title: No-Bake Nut Cookies\\n\\nIngredients: [\"1 c. firmly packed brown sugar\", \"1/2 c. evaporated milk\", \"1/2 tsp. vanilla\", \"1/2 c. broken nuts (pecans)\", \"2 Tbsp. butter or margarine\", \"3 1/2 c. bite size shredded rice biscuits\"]\\n\\nGeneric ingredients: '},\n\n {'role': 'assistant',\n  'content': '[\"brown sugar\", \"milk\", \"vanilla\", \"nuts\", \"butter\", \"bite size shredded rice biscuits\"]'}]\n```\n\nDuring the training process this conversation will be split, with the final entry being the `completion` that the model will produce, and the remainder of the `messages` acting as the prompt. Consider this when building your training examples - if your model will act on multi-turn conversations, then please provide representative examples so it doesn't perform poorly when the conversation starts to expand.\n\nPlease note that currently there is a 4096 token limit for each training example. Anything longer than this will be truncated at 4096 tokens.\n\n\n\n```python\nsystem_message = \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"\n\n\ndef create_user_message(row):\n    return f\"Title: {row['title']}\\n\\nIngredients: {row['ingredients']}\\n\\nGeneric ingredients: \"\n\n\ndef prepare_example_conversation(row):\n    return {\n        \"messages\": [\n            {\"role\": \"system\", \"content\": system_message},\n            {\"role\": \"user\", \"content\": create_user_message(row)},\n            {\"role\": \"assistant\", \"content\": row[\"NER\"]},\n        ]\n    }\n\n\npprint(prepare_example_conversation(recipe_df.iloc[0]))\n```\n\n    {'messages': [{'content': 'You are a helpful recipe assistant. You are to '\n                              'extract the generic ingredients from each of the '\n                              'recipes provided.',\n                   'role': 'system'},\n                  {'content': 'Title: No-Bake Nut Cookies\\n'\n                              '\\n'\n                              'Ingredients: [\"1 c. firmly packed brown sugar\", '\n                              '\"1/2 c. evaporated milk\", \"1/2 tsp. vanilla\", \"1/2 '\n                              'c. broken nuts (pecans)\", \"2 Tbsp. butter or '\n                              'margarine\", \"3 1/2 c. bite size shredded rice '\n                              'biscuits\"]\\n'\n                              '\\n'\n                              'Generic ingredients: ',\n                   'role': 'user'},\n                  {'content': '[\"brown sugar\", \"milk\", \"vanilla\", \"nuts\", '\n                              '\"butter\", \"bite size shredded rice biscuits\"]',\n                   'role': 'assistant'}]}\n\n\nLet's now do this for a subset of the dataset to use as our training data. You can begin with even 30-50 well-pruned examples. You should see performance continue to scale linearly as you increase the size of the training set, but your jobs will also take longer."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 699f50ef-be76-4088-9a18-36ff9ffeba1f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"699f50ef-be76-4088-9a18-36ff9ffeba1f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"324e8a03-0554-4208-bf2f-c73aeff6507f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"588683e3ea9c46ff7a2e090526512010be2675f0deb29d5345080d0704b52b6f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"0a86525c-6b9c-4f77-a9d6-df655e6dbe76\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"7a946e6404cb2b1151ac8dfb76b3aaa9b42894ff2c51842a89da0767d4960775\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6357, \"end_char_idx\": 9193, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "def create_user_message(row):\n    return f\"Title: {row['title']}\\n\\nIngredients: {row['ingredients']}\\n\\nGeneric ingredients: \"\n\n\ndef prepare_example_conversation(row):\n    return {\n        \"messages\": [\n            {\"role\": \"system\", \"content\": system_message},\n            {\"role\": \"user\", \"content\": create_user_message(row)},\n            {\"role\": \"assistant\", \"content\": row[\"NER\"]},\n        ]\n    }\n\n\npprint(prepare_example_conversation(recipe_df.iloc[0]))\n```\n\n    {'messages': [{'content': 'You are a helpful recipe assistant. You are to '\n                              'extract the generic ingredients from each of the '\n                              'recipes provided.',\n                   'role': 'system'},\n                  {'content': 'Title: No-Bake Nut Cookies\\n'\n                              '\\n'\n                              'Ingredients: [\"1 c. firmly packed brown sugar\", '\n                              '\"1/2 c. evaporated milk\", \"1/2 tsp. vanilla\", \"1/2 '\n                              'c. broken nuts (pecans)\", \"2 Tbsp. butter or '\n                              'margarine\", \"3 1/2 c. bite size shredded rice '\n                              'biscuits\"]\\n'\n                              '\\n'\n                              'Generic ingredients: ',\n                   'role': 'user'},\n                  {'content': '[\"brown sugar\", \"milk\", \"vanilla\", \"nuts\", '\n                              '\"butter\", \"bite size shredded rice biscuits\"]',\n                   'role': 'assistant'}]}\n\n\nLet's now do this for a subset of the dataset to use as our training data. You can begin with even 30-50 well-pruned examples. You should see performance continue to scale linearly as you increase the size of the training set, but your jobs will also take longer.\n\n\n\n```python\n# use the first 100 rows of the dataset for training\ntraining_df = recipe_df.loc[0:100]\n\n# apply the prepare_example_conversation function to each row of the training_df\ntraining_data = training_df.apply(prepare_example_conversation, axis=1).tolist()\n\nfor example in training_data[:5]:\n    print(example)\n```\n\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: No-Bake Nut Cookies\\n\\nIngredients: [\"1 c. firmly packed brown sugar\", \"1/2 c. evaporated milk\", \"1/2 tsp. vanilla\", \"1/2 c. broken nuts (pecans)\", \"2 Tbsp. butter or margarine\", \"3 1/2 c. bite size shredded rice biscuits\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"brown sugar\", \"milk\", \"vanilla\", \"nuts\", \"butter\", \"bite size shredded rice biscuits\"]'}]}\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0a86525c-6b9c-4f77-a9d6-df655e6dbe76
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0a86525c-6b9c-4f77-a9d6-df655e6dbe76\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"699f50ef-be76-4088-9a18-36ff9ffeba1f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1e7d76a3571d814b8bdcfe48053ae119e9d5f3f7f3d8bddca0cc5b14037440f0\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"36b5a8e3-8014-41bc-9204-fb66f1f571db\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a462f0eb5e784154e2b3d3b340a7d1170956ee99421fa0b7e530f49021b1dad0\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7863, \"end_char_idx\": 10436, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "Let's now do this for a subset of the dataset to use as our training data. You can begin with even 30-50 well-pruned examples. You should see performance continue to scale linearly as you increase the size of the training set, but your jobs will also take longer.\n\n\n\n```python\n# use the first 100 rows of the dataset for training\ntraining_df = recipe_df.loc[0:100]\n\n# apply the prepare_example_conversation function to each row of the training_df\ntraining_data = training_df.apply(prepare_example_conversation, axis=1).tolist()\n\nfor example in training_data[:5]:\n    print(example)\n```\n\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: No-Bake Nut Cookies\\n\\nIngredients: [\"1 c. firmly packed brown sugar\", \"1/2 c. evaporated milk\", \"1/2 tsp. vanilla\", \"1/2 c. broken nuts (pecans)\", \"2 Tbsp. butter or margarine\", \"3 1/2 c. bite size shredded rice biscuits\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"brown sugar\", \"milk\", \"vanilla\", \"nuts\", \"butter\", \"bite size shredded rice biscuits\"]'}]}\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: Jewell Ball\\'S Chicken\\n\\nIngredients: [\"1 small jar chipped beef, cut up\", \"4 boned chicken breasts\", \"1 can cream of mushroom soup\", \"1 carton sour cream\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"beef\", \"chicken breasts\", \"cream of mushroom soup\", \"sour cream\"]'}]}\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: Creamy Corn\\n\\nIngredients: [\"2 (16 oz.) pkg. frozen corn\", \"1 (8 oz.) pkg. cream cheese, cubed\", \"1/3 c. butter, cubed\", \"1/2 tsp. garlic powder\", \"1/2 tsp. salt\", \"1/4 tsp. pepper\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"frozen corn\", \"cream cheese\", \"butter\", \"garlic powder\", \"salt\", \"pepper\"]'}]}\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: Chicken Funny\\n\\nIngredients: [\"1 large whole chicken\", \"2 (10 1/2 oz.) cans chicken gravy\", \"1 (10 1/2 oz.) can cream of mushroom soup\", \"1 (6 oz.) box Stove Top stuffing\", \"4 oz."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 36b5a8e3-8014-41bc-9204-fb66f1f571db
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"36b5a8e3-8014-41bc-9204-fb66f1f571db\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0a86525c-6b9c-4f77-a9d6-df655e6dbe76\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6e7b0ea03c990eabd302e8bcc87066ef7d3672a4e8236619bb5c2f1d1937abd5\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"00dba830-7c92-4e94-a0f3-a1e09f7e1b2b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9208ea71be36cfec36d584e857f34148846be494cd61eb2b4ffce56ebfad8b80\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9116, \"end_char_idx\": 11767, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: Jewell Ball\\'S Chicken\\n\\nIngredients: [\"1 small jar chipped beef, cut up\", \"4 boned chicken breasts\", \"1 can cream of mushroom soup\", \"1 carton sour cream\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"beef\", \"chicken breasts\", \"cream of mushroom soup\", \"sour cream\"]'}]}\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: Creamy Corn\\n\\nIngredients: [\"2 (16 oz.) pkg. frozen corn\", \"1 (8 oz.) pkg. cream cheese, cubed\", \"1/3 c. butter, cubed\", \"1/2 tsp. garlic powder\", \"1/2 tsp. salt\", \"1/4 tsp. pepper\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"frozen corn\", \"cream cheese\", \"butter\", \"garlic powder\", \"salt\", \"pepper\"]'}]}\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: Chicken Funny\\n\\nIngredients: [\"1 large whole chicken\", \"2 (10 1/2 oz.) cans chicken gravy\", \"1 (10 1/2 oz.) can cream of mushroom soup\", \"1 (6 oz.) box Stove Top stuffing\", \"4 oz. shredded cheese\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"chicken\", \"chicken gravy\", \"cream of mushroom soup\", \"shredded cheese\"]'}]}\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: Reeses Cups(Candy)  \\n\\nIngredients: [\"1 c. peanut butter\", \"3/4 c. graham cracker crumbs\", \"1 c. melted butter\", \"1 lb. (3 1/2 c.) powdered sugar\", \"1 large pkg. chocolate chips\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"peanut butter\", \"graham cracker crumbs\", \"butter\", \"powdered sugar\", \"chocolate chips\"]'}]}\n\n\nIn addition to training data, we can also **optionally** provide validation data, which will be used to make sure that the model does not overfit your training set.\n\n\n\n```python\nvalidation_df = recipe_df.loc[101:200]\nvalidation_data = validation_df.apply(\n    prepare_example_conversation, axis=1).tolist()\n```\n\nWe then need to save our data as `.jsonl` files, with each line being one training example conversation.\n\n\n\n```python\ndef write_jsonl(data_list: list, filename: str) -> None:\n    with open(filename, \"w\") as out:\n        for ddict in data_list:\n            jout = json.dumps(ddict) + \"\\n\"\n            out.write(jout)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 00dba830-7c92-4e94-a0f3-a1e09f7e1b2b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"00dba830-7c92-4e94-a0f3-a1e09f7e1b2b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"36b5a8e3-8014-41bc-9204-fb66f1f571db\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8a4928c1c9587869a375971ef4e511218427a7ac43428cfe38aeb8bb1c422a81\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"0b73935f-4bb5-4854-b8a8-17433c7dde12\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"54b4be081534789424611182cb1ea01f2684e6c1a267afafc2958927bc25b0f5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10365, \"end_char_idx\": 12954, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "can cream of mushroom soup\", \"1 (6 oz.) box Stove Top stuffing\", \"4 oz. shredded cheese\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"chicken\", \"chicken gravy\", \"cream of mushroom soup\", \"shredded cheese\"]'}]}\n    {'messages': [{'role': 'system', 'content': 'You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.'}, {'role': 'user', 'content': 'Title: Reeses Cups(Candy)  \\n\\nIngredients: [\"1 c. peanut butter\", \"3/4 c. graham cracker crumbs\", \"1 c. melted butter\", \"1 lb. (3 1/2 c.) powdered sugar\", \"1 large pkg. chocolate chips\"]\\n\\nGeneric ingredients: '}, {'role': 'assistant', 'content': '[\"peanut butter\", \"graham cracker crumbs\", \"butter\", \"powdered sugar\", \"chocolate chips\"]'}]}\n\n\nIn addition to training data, we can also **optionally** provide validation data, which will be used to make sure that the model does not overfit your training set.\n\n\n\n```python\nvalidation_df = recipe_df.loc[101:200]\nvalidation_data = validation_df.apply(\n    prepare_example_conversation, axis=1).tolist()\n```\n\nWe then need to save our data as `.jsonl` files, with each line being one training example conversation.\n\n\n\n```python\ndef write_jsonl(data_list: list, filename: str) -> None:\n    with open(filename, \"w\") as out:\n        for ddict in data_list:\n            jout = json.dumps(ddict) + \"\\n\"\n            out.write(jout)\n```\n\n\n```python\ntraining_file_name = \"tmp_recipe_finetune_training.jsonl\"\nwrite_jsonl(training_data, training_file_name)\n\nvalidation_file_name = \"tmp_recipe_finetune_validation.jsonl\"\nwrite_jsonl(validation_data, validation_file_name)\n```\n\nThis is what the first 5 lines of our training `.jsonl` file look like:\n\n\n\n```python\n# print the first 5 lines of the training file\n!head -n 5 tmp_recipe_finetune_training.jsonl\n```\n\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: No-Bake Nut Cookies\\n\\nIngredients: [\\\"1 c. firmly packed brown sugar\\\", \\\"1/2 c. evaporated milk\\\", \\\"1/2 tsp. vanilla\\\", \\\"1/2 c. broken nuts (pecans)\\\", \\\"2 Tbsp. butter or margarine\\\", \\\"3 1/2 c. bite size shredded rice biscuits\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"brown sugar\\\", \\\"milk\\\", \\\"vanilla\\\", \\\"nuts\\\", \\\"butter\\\", \\\"bite size shredded rice biscuits\\\"]\"}]}\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0b73935f-4bb5-4854-b8a8-17433c7dde12
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0b73935f-4bb5-4854-b8a8-17433c7dde12\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"00dba830-7c92-4e94-a0f3-a1e09f7e1b2b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6657808e1355f20f511c4307a490687b49bb763a8317c50d8a89f733d25ae628\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"51fdc6a3-e477-4dcf-81b4-15200f5db935\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5e81877bc99425c24d8448def062cc8df67e144f7fe799385adcb26bbba6cd45\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11556, \"end_char_idx\": 14245, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "```python\ndef write_jsonl(data_list: list, filename: str) -> None:\n    with open(filename, \"w\") as out:\n        for ddict in data_list:\n            jout = json.dumps(ddict) + \"\\n\"\n            out.write(jout)\n```\n\n\n```python\ntraining_file_name = \"tmp_recipe_finetune_training.jsonl\"\nwrite_jsonl(training_data, training_file_name)\n\nvalidation_file_name = \"tmp_recipe_finetune_validation.jsonl\"\nwrite_jsonl(validation_data, validation_file_name)\n```\n\nThis is what the first 5 lines of our training `.jsonl` file look like:\n\n\n\n```python\n# print the first 5 lines of the training file\n!head -n 5 tmp_recipe_finetune_training.jsonl\n```\n\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: No-Bake Nut Cookies\\n\\nIngredients: [\\\"1 c. firmly packed brown sugar\\\", \\\"1/2 c. evaporated milk\\\", \\\"1/2 tsp. vanilla\\\", \\\"1/2 c. broken nuts (pecans)\\\", \\\"2 Tbsp. butter or margarine\\\", \\\"3 1/2 c. bite size shredded rice biscuits\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"brown sugar\\\", \\\"milk\\\", \\\"vanilla\\\", \\\"nuts\\\", \\\"butter\\\", \\\"bite size shredded rice biscuits\\\"]\"}]}\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Jewell Ball'S Chicken\\n\\nIngredients: [\\\"1 small jar chipped beef, cut up\\\", \\\"4 boned chicken breasts\\\", \\\"1 can cream of mushroom soup\\\", \\\"1 carton sour cream\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"beef\\\", \\\"chicken breasts\\\", \\\"cream of mushroom soup\\\", \\\"sour cream\\\"]\"}]}\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Creamy Corn\\n\\nIngredients: [\\\"2 (16 oz.) pkg. frozen corn\\\", \\\"1 (8 oz.) pkg. cream cheese, cubed\\\", \\\"1/3 c. butter, cubed\\\", \\\"1/2 tsp. garlic powder\\\", \\\"1/2 tsp. salt\\\", \\\"1/4 tsp. pepper\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"frozen corn\\\", \\\"cream cheese\\\", \\\"butter\\\", \\\"garlic powder\\\", \\\"salt\\\", \\\"pepper\\\"]\"}]}\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Chicken Funny\\n\\nIngredients: [\\\"1 large whole chicken\\\", \\\"2 (10 1/2 oz.) cans chicken gravy\\\", \\\"1 (10 1/2 oz.) can cream of mushroom soup\\\", \\\"1 (6 oz.) box Stove Top stuffing\\\", \\\"4 oz."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 51fdc6a3-e477-4dcf-81b4-15200f5db935
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"51fdc6a3-e477-4dcf-81b4-15200f5db935\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0b73935f-4bb5-4854-b8a8-17433c7dde12\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"09c8fa16ed78eb6476af520999e2837cff73b6b9f81966f44ab3a84684861aab\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"54b221b5-2d94-4a27-bada-393243c1e90f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"73b9730ffe4fcc04e99a7ba4ab6a12301b5274678c55a5abd3c426f94afeeab0\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 12877, \"end_char_idx\": 15283, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Jewell Ball'S Chicken\\n\\nIngredients: [\\\"1 small jar chipped beef, cut up\\\", \\\"4 boned chicken breasts\\\", \\\"1 can cream of mushroom soup\\\", \\\"1 carton sour cream\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"beef\\\", \\\"chicken breasts\\\", \\\"cream of mushroom soup\\\", \\\"sour cream\\\"]\"}]}\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Creamy Corn\\n\\nIngredients: [\\\"2 (16 oz.) pkg. frozen corn\\\", \\\"1 (8 oz.) pkg. cream cheese, cubed\\\", \\\"1/3 c. butter, cubed\\\", \\\"1/2 tsp. garlic powder\\\", \\\"1/2 tsp. salt\\\", \\\"1/4 tsp. pepper\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"frozen corn\\\", \\\"cream cheese\\\", \\\"butter\\\", \\\"garlic powder\\\", \\\"salt\\\", \\\"pepper\\\"]\"}]}\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Chicken Funny\\n\\nIngredients: [\\\"1 large whole chicken\\\", \\\"2 (10 1/2 oz.) cans chicken gravy\\\", \\\"1 (10 1/2 oz.) can cream of mushroom soup\\\", \\\"1 (6 oz.) box Stove Top stuffing\\\", \\\"4 oz. shredded cheese\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"chicken\\\", \\\"chicken gravy\\\", \\\"cream of mushroom soup\\\", \\\"shredded cheese\\\"]\"}]}\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Reeses Cups(Candy)  \\n\\nIngredients: [\\\"1 c. peanut butter\\\", \\\"3/4 c. graham cracker crumbs\\\", \\\"1 c. melted butter\\\", \\\"1 lb. (3 1/2 c.) powdered sugar\\\", \\\"1 large pkg. chocolate chips\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"peanut butter\\\", \\\"graham cracker crumbs\\\", \\\"butter\\\", \\\"powdered sugar\\\", \\\"chocolate chips\\\"]\"}]}\n\n\n### Upload files\n\nYou can now upload the files to our `Files` endpoint to be used by the fine-tuned model.\n\n\n\n```python\ndef upload_file(file_name: str, purpose: str) -> str:\n    with open(file_name, \"rb\") as file_fd:\n        response = client.files.create(file=file_fd, purpose=purpose)\n    return response.id"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 54b221b5-2d94-4a27-bada-393243c1e90f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"54b221b5-2d94-4a27-bada-393243c1e90f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"51fdc6a3-e477-4dcf-81b4-15200f5db935\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a14b6272534697a6d79d247c77f68d54cf22b2dbd8ddcfb55cc5acb0a29fc7f7\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"bc6c945b-925e-454e-94ee-c014adc11071\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"83636768a79fdbf7af00fb74dcc574471ca43ff47663abe84c8e710dd0a97004\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 13939, \"end_char_idx\": 16358, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Chicken Funny\\n\\nIngredients: [\\\"1 large whole chicken\\\", \\\"2 (10 1/2 oz.) cans chicken gravy\\\", \\\"1 (10 1/2 oz.) can cream of mushroom soup\\\", \\\"1 (6 oz.) box Stove Top stuffing\\\", \\\"4 oz. shredded cheese\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"chicken\\\", \\\"chicken gravy\\\", \\\"cream of mushroom soup\\\", \\\"shredded cheese\\\"]\"}]}\n    {\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful recipe assistant. You are to extract the generic ingredients from each of the recipes provided.\"}, {\"role\": \"user\", \"content\": \"Title: Reeses Cups(Candy)  \\n\\nIngredients: [\\\"1 c. peanut butter\\\", \\\"3/4 c. graham cracker crumbs\\\", \\\"1 c. melted butter\\\", \\\"1 lb. (3 1/2 c.) powdered sugar\\\", \\\"1 large pkg. chocolate chips\\\"]\\n\\nGeneric ingredients: \"}, {\"role\": \"assistant\", \"content\": \"[\\\"peanut butter\\\", \\\"graham cracker crumbs\\\", \\\"butter\\\", \\\"powdered sugar\\\", \\\"chocolate chips\\\"]\"}]}\n\n\n### Upload files\n\nYou can now upload the files to our `Files` endpoint to be used by the fine-tuned model.\n\n\n\n```python\ndef upload_file(file_name: str, purpose: str) -> str:\n    with open(file_name, \"rb\") as file_fd:\n        response = client.files.create(file=file_fd, purpose=purpose)\n    return response.id\n\n\ntraining_file_id = upload_file(training_file_name, \"fine-tune\")\nvalidation_file_id = upload_file(validation_file_name, \"fine-tune\")\n\nprint(\"Training file ID:\", training_file_id)\nprint(\"Validation file ID:\", validation_file_id)\n```\n\n    Training file ID: file-3wfAfDoYcGrSpaE17qK0vXT0\n    Validation file ID: file-HhFhnyGJhazYdPcd3wrtvIoX\n\n\n## Fine-tuning\n\nNow we can create our fine-tuning job with the generated files and an optional suffix to identify the model. The response will contain an `id` which you can use to retrieve updates on the job.\n\nNote: The files have to first be processed by our system, so you might get a `File not ready` error. In that case, simply retry a few minutes later.\n\n\n\n```python\nMODEL = \"gpt-4o-mini-2024-07-18\"\n\nresponse = client.fine_tuning.jobs.create(\n    training_file=training_file_id,\n    validation_file=validation_file_id,\n    model=MODEL,\n    suffix=\"recipe-ner\",\n)\n\njob_id = response.id\n\nprint(\"Job ID:\", response.id)\nprint(\"Status:\", response.status)\n```\n\n    Job ID: ftjob-UiaiLwGdGBfdLQDBAoQheufN\n    Status: validating_files"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: bc6c945b-925e-454e-94ee-c014adc11071
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"bc6c945b-925e-454e-94ee-c014adc11071\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"54b221b5-2d94-4a27-bada-393243c1e90f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"77e51691393497db8802f5e92f6b6584315dfa2dfb93e1ec5612c440a5bce943\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"30c3d1ff-69de-4b8a-804a-de2c4e7eb19b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"0e59a71316639288d38c7447232beab1bab2ac348cf7c50aaf8d52a82c592347\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14974, \"end_char_idx\": 17242, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "### Upload files\n\nYou can now upload the files to our `Files` endpoint to be used by the fine-tuned model.\n\n\n\n```python\ndef upload_file(file_name: str, purpose: str) -> str:\n    with open(file_name, \"rb\") as file_fd:\n        response = client.files.create(file=file_fd, purpose=purpose)\n    return response.id\n\n\ntraining_file_id = upload_file(training_file_name, \"fine-tune\")\nvalidation_file_id = upload_file(validation_file_name, \"fine-tune\")\n\nprint(\"Training file ID:\", training_file_id)\nprint(\"Validation file ID:\", validation_file_id)\n```\n\n    Training file ID: file-3wfAfDoYcGrSpaE17qK0vXT0\n    Validation file ID: file-HhFhnyGJhazYdPcd3wrtvIoX\n\n\n## Fine-tuning\n\nNow we can create our fine-tuning job with the generated files and an optional suffix to identify the model. The response will contain an `id` which you can use to retrieve updates on the job.\n\nNote: The files have to first be processed by our system, so you might get a `File not ready` error. In that case, simply retry a few minutes later.\n\n\n\n```python\nMODEL = \"gpt-4o-mini-2024-07-18\"\n\nresponse = client.fine_tuning.jobs.create(\n    training_file=training_file_id,\n    validation_file=validation_file_id,\n    model=MODEL,\n    suffix=\"recipe-ner\",\n)\n\njob_id = response.id\n\nprint(\"Job ID:\", response.id)\nprint(\"Status:\", response.status)\n```\n\n    Job ID: ftjob-UiaiLwGdGBfdLQDBAoQheufN\n    Status: validating_files\n\n\n#### Check job status\n\nYou can make a `GET` request to the `https://api.openai.com/v1/alpha/fine-tunes` endpoint to list your alpha fine-tune jobs. In this instance you'll want to check that the ID you got from the previous step ends up as `status: succeeded`.\n\nOnce it is completed, you can use the `result_files` to sample the results from the validation set (if you uploaded one), and use the ID from the `fine_tuned_model` parameter to invoke your trained model.\n\n\n\n```python\nresponse = client.fine_tuning.jobs.retrieve(job_id)\n\nprint(\"Job ID:\", response.id)\nprint(\"Status:\", response.status)\nprint(\"Trained Tokens:\", response.trained_tokens)\n```\n\n    Job ID: ftjob-UiaiLwGdGBfdLQDBAoQheufN\n    Status: running\n    Trained Tokens: None\n\n\nWe can track the progress of the fine-tune with the events endpoint. You can rerun the cell below a few times until the fine-tune is ready."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 30c3d1ff-69de-4b8a-804a-de2c4e7eb19b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"30c3d1ff-69de-4b8a-804a-de2c4e7eb19b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"bc6c945b-925e-454e-94ee-c014adc11071\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0044610978303c95aaca7eaf4ae19cebedb4393f9e6fc5645ed29f27cf0e0cfd\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"4c47b7b2-16b9-4b05-9976-af89fc1f72ab\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b6c6e19d0619cd01641f9562ea00ddceab7ae8d2adeb54e0c6e0a274918340dc\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 15988, \"end_char_idx\": 18444, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "```python\nMODEL = \"gpt-4o-mini-2024-07-18\"\n\nresponse = client.fine_tuning.jobs.create(\n    training_file=training_file_id,\n    validation_file=validation_file_id,\n    model=MODEL,\n    suffix=\"recipe-ner\",\n)\n\njob_id = response.id\n\nprint(\"Job ID:\", response.id)\nprint(\"Status:\", response.status)\n```\n\n    Job ID: ftjob-UiaiLwGdGBfdLQDBAoQheufN\n    Status: validating_files\n\n\n#### Check job status\n\nYou can make a `GET` request to the `https://api.openai.com/v1/alpha/fine-tunes` endpoint to list your alpha fine-tune jobs. In this instance you'll want to check that the ID you got from the previous step ends up as `status: succeeded`.\n\nOnce it is completed, you can use the `result_files` to sample the results from the validation set (if you uploaded one), and use the ID from the `fine_tuned_model` parameter to invoke your trained model.\n\n\n\n```python\nresponse = client.fine_tuning.jobs.retrieve(job_id)\n\nprint(\"Job ID:\", response.id)\nprint(\"Status:\", response.status)\nprint(\"Trained Tokens:\", response.trained_tokens)\n```\n\n    Job ID: ftjob-UiaiLwGdGBfdLQDBAoQheufN\n    Status: running\n    Trained Tokens: None\n\n\nWe can track the progress of the fine-tune with the events endpoint. You can rerun the cell below a few times until the fine-tune is ready.\n\n\n\n```python\nresponse = client.fine_tuning.jobs.list_events(job_id)\n\nevents = response.data\nevents.reverse()\n\nfor event in events:\n    print(event.message)\n```\n\n    Step 288/303: training loss=0.00\n    Step 289/303: training loss=0.01\n    Step 290/303: training loss=0.00, validation loss=0.31\n    Step 291/303: training loss=0.00\n    Step 292/303: training loss=0.00\n    Step 293/303: training loss=0.00\n    Step 294/303: training loss=0.00\n    Step 295/303: training loss=0.00\n    Step 296/303: training loss=0.00\n    Step 297/303: training loss=0.00\n    Step 298/303: training loss=0.01\n    Step 299/303: training loss=0.00\n    Step 300/303: training loss=0.00, validation loss=0.04\n    Step 301/303: training loss=0.16\n    Step 302/303: training loss=0.00\n    Step 303/303: training loss=0.00, full validation loss=0.33\n    Checkpoint created at step 101 with Snapshot ID: ft:gpt-4o-mini-2024-07-18:openai-gtm:recipe-ner:9o1eNlSa:ckpt-step-101\n    Checkpoint created at step 202 with Snapshot ID: ft:gpt-4o-mini-2024-07-18:openai-gtm:recipe-ner:9o1eNFnj:ckpt-step-202\n    New fine-tuned model created: ft:gpt-4o-mini-2024-07-18:openai-gtm:recipe-ner:9o1eNNKO\n    The job has successfully completed"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 4c47b7b2-16b9-4b05-9976-af89fc1f72ab
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb", "title": "How to fine-tune chat models", "tokens": 5550, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4c47b7b2-16b9-4b05-9976-af89fc1f72ab\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"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\": \"dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ab5424c1e34d9cad6deae7e35f5475d8dddeffb23386433668a5e5e5e3c8509\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"30c3d1ff-69de-4b8a-804a-de2c4e7eb19b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb\", \"title\": \"How to fine-tune chat models\", \"tokens\": 5550, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"03d25c21569a3f888dcdf70da8e0f4a9bcc77cc09a7bd905bcfb9458ffa524b3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 18447, \"end_char_idx\": 20499, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "ref_doc_id": "dc3e3826-fe04-4e3b-b2a1-e8cf35af25b7", "chroma:document": "Now that it's done, we can get a fine-tuned model ID from the job:\n\n\n\n```python\nresponse = client.fine_tuning.jobs.retrieve(job_id)\nfine_tuned_model_id = response.fine_tuned_model\n\nif fine_tuned_model_id is None:\n    raise RuntimeError(\n        \"Fine-tuned model ID not found. Your job has likely not been completed yet.\"\n    )\n\nprint(\"Fine-tuned model ID:\", fine_tuned_model_id)\n```\n\n    Fine-tuned model ID: ft:gpt-4o-mini-2024-07-18:openai-gtm:recipe-ner:9o1eNNKO\n\n\n## Inference\n\n\nThe last step is to use your fine-tuned model for inference. Similar to the classic `FineTuning`, you simply call `ChatCompletions` with your new fine-tuned model name filling the `model` parameter.\n\n\n\n```python\ntest_df = recipe_df.loc[201:300]\ntest_row = test_df.iloc[0]\ntest_messages = []\ntest_messages.append({\"role\": \"system\", \"content\": system_message})\nuser_message = create_user_message(test_row)\ntest_messages.append({\"role\": \"user\", \"content\": user_message})\n\npprint(test_messages)\n```\n\n    [{'content': 'You are a helpful recipe assistant. You are to extract the '\n                 'generic ingredients from each of the recipes provided.',\n      'role': 'system'},\n     {'content': 'Title: Beef Brisket\\n'\n                 '\\n'\n                 'Ingredients: [\"4 lb. beef brisket\", \"1 c. catsup\", \"1 c. water\", '\n                 '\"1/2 onion, minced\", \"2 Tbsp. cider vinegar\", \"1 Tbsp. prepared '\n                 'horseradish\", \"1 Tbsp. prepared mustard\", \"1 tsp. salt\", \"1/2 '\n                 'tsp. pepper\"]\\n'\n                 '\\n'\n                 'Generic ingredients: ',\n      'role': 'user'}]\n\n\n\n```python\nresponse = client.chat.completions.create(\n    model=fine_tuned_model_id, messages=test_messages, temperature=0, max_tokens=500\n)\nprint(response.choices[0].message.content)\n```\n\n    [\"beef brisket\", \"catsup\", \"water\", \"onion\", \"cider vinegar\", \"horseradish\", \"mustard\", \"salt\", \"pepper\"]\n\n\n## Conclusion\n\nCongratulations, you are now ready to fine-tune your own models using the `ChatCompletion` format! We look forward to seeing what you build"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: ce529ee7-0e87-4001-badd-846442e53fa7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Classification_using_embeddings.ipynb", "title": "split data into train and test", "tokens": 708, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ce529ee7-0e87-4001-badd-846442e53fa7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Classification_using_embeddings.ipynb\", \"title\": \"split data into train and test\", \"tokens\": 708, \"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\": \"5401f931-18e8-4837-8a1c-cd138c055331\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Classification_using_embeddings.ipynb\", \"title\": \"split data into train and test\", \"tokens\": 708, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f25f7cd013b2d972d6996d5b5fab50fa34cc88e9502d5962812e89a9e5ca59a3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2947, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5401f931-18e8-4837-8a1c-cd138c055331", "doc_id": "5401f931-18e8-4837-8a1c-cd138c055331", "ref_doc_id": "5401f931-18e8-4837-8a1c-cd138c055331", "chroma:document": "## Classification using embeddings\n\nThere are many ways to classify text. This notebook shares an example of text classification using embeddings. For many text classification tasks, we've seen fine-tuned models do better than embeddings. See an example of fine-tuned models for classification in [Fine-tuned_classification.ipynb](Fine-tuned_classification.ipynb). We also recommend having more examples than embedding dimensions, which we don't quite achieve here.\n\nIn this text classification task, we predict the score of a food review (1 to 5) based on the embedding of the review's text. We split the dataset into a training and a testing set for all 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\n\n\n```python\nimport pandas as pd\nimport numpy as np\nfrom ast import literal_eval\n\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import classification_report, accuracy_score\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)  # convert string to array\n\n# split data into train and test\nX_train, X_test, y_train, y_test = train_test_split(\n    list(df.embedding.values), df.Score, test_size=0.2, random_state=42\n)\n\n# train random forest classifier\nclf = RandomForestClassifier(n_estimators=100)\nclf.fit(X_train, y_train)\npreds = clf.predict(X_test)\nprobas = clf.predict_proba(X_test)\n\nreport = classification_report(y_test, preds)\nprint(report)\n\n```\n\n                  precision    recall  f1-score   support\n    \n               1       0.90      0.45      0.60        20\n               2       1.00      0.38      0.55         8\n               3       1.00      0.18      0.31        11\n               4       0.88      0.26      0.40        27\n               5       0.76      1.00      0.86       134\n    \n        accuracy                           0.78       200\n       macro avg       0.91      0.45      0.54       200\n    weighted avg       0.81      0.78      0.73       200\n    \n\n\nWe can see that the model has learnt to distinguish between the categories decently. 5-star reviews show the best performance overall, and this is not too surprising, since they are the most common in the dataset.\n\n\n```python\nfrom utils.embeddings_utils import plot_multiclass_precision_recall\n\nplot_multiclass_precision_recall(probas, y_test, [1, 2, 3, 4, 5], clf)\n```\n\n    RandomForestClassifier() - Average precision score over all classes: 0.90\n\n\n\n    \n![png](output_3_1.png)\n    \n\n\nUnsurprisingly 5-star and 1-star reviews seem to be easier to predict. Perhaps with more data, the nuances between 2-4 stars could be better predicted, but there's also probably more subjectivity in how people use the inbetween scores."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: ab2a6943-e226-452f-a79f-3e5fa42fa4d4
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ab2a6943-e226-452f-a79f-3e5fa42fa4d4\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"89686bb2-712f-4df7-b94f-6102d82e33dc\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a012f786d7175571e429554d3ac6c488b913dc2f7366b9201ab4cb2f7cd0c9d1\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 1143, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "# Using Tool Required for Customer Service\n\nThe `ChatCompletion` endpoint now includes the ability to specify whether a tool **must** be called every time, by adding `tool_choice='required'` as a parameter. \n\nThis adds an element of determinism to how you build your wrapping application, as you can count on a tool being provided with every call. We'll demonstrate here how this can be useful for a contained flow like customer service, where having the ability to define specific exit points gives more control.\n\nThe notebook concludes with a multi-turn evaluation, where we spin up a customer GPT to imitate our customer and test the LLM customer service agent we've set up.\n\n\n```python\nimport json\nfrom openai import OpenAI\nimport os\n\nclient = OpenAI()\nGPT_MODEL = 'gpt-4-turbo'\n```\n\n## Config definition\n\nWe will define `tools` and `instructions` which our LLM customer service agent will use. It will source the right instructions for the problem the customer is facing, and use those to answer the customer's query.\n\nAs this is a demo example, we'll ask the model to make up values where it doesn't have external systems to source info."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 89686bb2-712f-4df7-b94f-6102d82e33dc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"89686bb2-712f-4df7-b94f-6102d82e33dc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"ab2a6943-e226-452f-a79f-3e5fa42fa4d4\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"092d78e00d12a2be3af476a25c30511623ea6b902f52544ef2981e71872ad3ec\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e3996f71-9ed1-4f34-a1d3-f2b2dd76aa0d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"df15be066edc4d9b5322771a0d5b997b53ec1470fdb4b41ad89768474d0a3556\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3912, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "# Using Tool Required for Customer Service\n\nThe `ChatCompletion` endpoint now includes the ability to specify whether a tool **must** be called every time, by adding `tool_choice='required'` as a parameter. \n\nThis adds an element of determinism to how you build your wrapping application, as you can count on a tool being provided with every call. We'll demonstrate here how this can be useful for a contained flow like customer service, where having the ability to define specific exit points gives more control.\n\nThe notebook concludes with a multi-turn evaluation, where we spin up a customer GPT to imitate our customer and test the LLM customer service agent we've set up.\n\n\n```python\nimport json\nfrom openai import OpenAI\nimport os\n\nclient = OpenAI()\nGPT_MODEL = 'gpt-4-turbo'\n```\n\n## Config definition\n\nWe will define `tools` and `instructions` which our LLM customer service agent will use. It will source the right instructions for the problem the customer is facing, and use those to answer the customer's query.\n\nAs this is a demo example, we'll ask the model to make up values where it doesn't have external systems to source info.\n\n\n```python\n# The tools our customer service LLM will use to communicate\ntools = [\n{\n  \"type\": \"function\",\n  \"function\": {\n    \"name\": \"speak_to_user\",\n    \"description\": \"Use this to speak to the user to give them information and to ask for anything required for their case.\",\n    \"parameters\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"message\": {\n          \"type\": \"string\",\n          \"description\": \"Text of message to send to user. Can cover multiple topics.\"\n        }\n      },\n      \"required\": [\"message\"]\n    }\n  }\n},\n{\n  \"type\": \"function\",\n  \"function\": {\n    \"name\": \"get_instructions\",\n    \"description\": \"Used to get instructions to deal with the user's problem.\",\n    \"parameters\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"problem\": {\n          \"type\": \"string\",\n          \"enum\": [\"fraud\",\"refund\",\"information\"],\n          \"description\": \"\"\"The type of problem the customer has. Can be one of:\n          - fraud: Required to report and resolve fraud.\n          - refund: Required to submit a refund request.\n          - information: Used for any other informational queries.\"\"\"\n        }\n      },\n      \"required\": [\n        \"problem\"\n      ]\n    }\n  }\n}\n]\n\n# Example instructions that the customer service assistant can consult for relevant customer problems\nINSTRUCTIONS = [ {\"type\": \"fraud\",\n                  \"instructions\": \"\"\"\u2022 Ask the customer to describe the fraudulent activity, including the the date and items involved in the suspected fraud.\n\u2022 Offer the customer a refund.\n\u2022 Report the fraud to the security team for further investigation.\n\u2022 Thank the customer for contacting support and invite them to reach out with any future queries.\"\"\"},\n                {\"type\": \"refund\",\n                 \"instructions\": \"\"\"\u2022 Confirm the customer's purchase details and verify the transaction in the system.\n\u2022 Check the company's refund policy to ensure the request meets the criteria.\n\u2022 Ask the customer to provide a reason for the refund.\n\u2022 Submit the refund request to the accounting department.\n\u2022 Inform the customer of the expected time frame for the refund processing.\n\u2022 Thank the customer for contacting support and invite them to reach out with any future queries.\"\"\"},\n                {\"type\": \"information\",\n                 \"instructions\": \"\"\"\u2022 Greet the customer and ask how you can assist them today.\n\u2022 Listen carefully to the customer's query and clarify if necessary.\n\u2022 Provide accurate and clear information based on the customer's questions.\n\u2022 Offer to assist with any additional questions or provide further details if needed.\n\u2022 Ensure the customer is satisfied with the information provided.\n\u2022 Thank the customer for contacting support and invite them to reach out with any future queries.\"\"\" }]\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: e3996f71-9ed1-4f34-a1d3-f2b2dd76aa0d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e3996f71-9ed1-4f34-a1d3-f2b2dd76aa0d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"89686bb2-712f-4df7-b94f-6102d82e33dc\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a8487aa8738f5cfcb800409ca5dc1c25f724019114093e2e4c051cf5da9d45d0\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"27e2138d-c284-4672-9afd-c1261160e3fa\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"23cf9c7df1e679e8bab065da1adc06295ad8046465a29c0fd0aba67bf26c550b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3915, \"end_char_idx\": 8198, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "```python\nassistant_system_prompt = \"\"\"You are a customer service assistant. Your role is to answer user questions politely and competently.\nYou should follow these instructions to solve the case:\n- Understand their problem and get the relevant instructions.\n- Follow the instructions to solve the customer's problem. Get their confirmation before performing a permanent operation like a refund or similar.\n- Help them with any other problems or close the case.\n\nOnly call a tool once in a single message.\nIf you need to fetch a piece of information from a system or document that you don't have access to, give a clear, confident answer with some dummy values.\"\"\"\n\ndef submit_user_message(user_query,conversation_messages=[]):\n    \"\"\"Message handling function which loops through tool calls until it reaches one that requires a response.\n    Once it receives respond=True it returns the conversation_messages to the user.\"\"\"\n\n    # Initiate a respond object. This will be set to True by our functions when a response is required\n    respond = False\n    \n    user_message = {\"role\":\"user\",\"content\": user_query}\n    conversation_messages.append(user_message)\n\n    print(f\"User: {user_query}\")\n\n    while respond is False:\n\n        # Build a transient messages object to add the conversation messages to\n        messages = [\n            {\n                \"role\": \"system\",\n                \"content\": assistant_system_prompt\n            }\n        ]\n\n        # Add the conversation messages to our messages call to the API\n        [messages.append(x) for x in conversation_messages]\n\n        # Make the ChatCompletion call with tool_choice='required' so we can guarantee tools will be used\n        response = client.chat.completions.create(model=GPT_MODEL\n                                                  ,messages=messages\n                                                  ,temperature=0\n                                                  ,tools=tools\n                                                  ,tool_choice='required'\n                                                 )\n\n        conversation_messages.append(response.choices[0].message)\n\n        # Execute the function and get an updated conversation_messages object back\n        # If it doesn't require a response, it will ask the assistant again. \n        # If not the results are returned to the user.\n        respond, conversation_messages = execute_function(response.choices[0].message,conversation_messages)\n    \n    return conversation_messages\n\ndef execute_function(function_calls,messages):\n    \"\"\"Wrapper function to execute the tool calls\"\"\"\n\n    for function_call in function_calls.tool_calls:\n    \n        function_id = function_call.id\n        function_name = function_call.function.name\n        print(f\"Calling function {function_name}\")\n        function_arguments = json.loads(function_call.function.arguments)\n    \n        if function_name == 'get_instructions':\n\n            respond = False\n    \n            instruction_name = function_arguments['problem']\n            instructions = INSTRUCTIONS['type' == instruction_name]\n    \n            messages.append(\n                                {\n                                    \"tool_call_id\": function_id,\n                                    \"role\": \"tool\",\n                                    \"name\": function_name,\n                                    \"content\": instructions['instructions'],\n                                }\n                            )\n    \n        elif function_name != 'get_instructions':\n\n            respond = True\n    \n            messages.append(\n                                {\n                                    \"tool_call_id\": function_id,\n                                    \"role\": \"tool\",\n                                    \"name\": function_name,\n                                    \"content\": function_arguments['message'],\n                                }\n                            )\n    \n            print(f\"Assistant: {function_arguments['message']}\")\n    \n    return (respond, messages)\n    \n```\n\n## Example\n\nTo test this we will run an example for a customer who has experienced fraud, and see how the model handles it.\n\nPlay the role of the user and provide plausible next steps to keep the conversation going."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 27e2138d-c284-4672-9afd-c1261160e3fa
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"27e2138d-c284-4672-9afd-c1261160e3fa\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"e3996f71-9ed1-4f34-a1d3-f2b2dd76aa0d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0891b353cc1f2fd369111df7c9efbae2ad555144c2b581de1253511e25b2a3eb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"3dd427d0-8501-45a7-bca4-f6d5e84ec5a2\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1e7b7aaf3b01987d1487cf2b52da79ab714942b8654a6d592f87671379808c5b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8201, \"end_char_idx\": 11338, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "```python\nmessages = submit_user_message(\"Hi, I have had an item stolen that was supposed to be delivered to me yesterday.\")\n```\n\n    User: Hi, I have had an item stolen that was supposed to be delivered to me yesterday.\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: I'm sorry to hear about the stolen item. Could you please provide me with more details about the fraudulent activity, including the date and the items involved? This information will help us to investigate the issue further and proceed with the necessary actions, including offering you a refund.\n\n\n\n```python\nmessages = submit_user_message(\"For sure, it was a shirt, it was supposed to be delivered yesterday but it never arrived.\",messages)\n```\n\n    User: For sure, it was a shirt, it was supposed to be delivered yesterday but it never arrived.\n    Calling function speak_to_user\n    Assistant: Thank you for providing the details. I will now proceed to report this incident to our security team for further investigation and arrange a refund for the stolen shirt. Please confirm if you would like me to go ahead with the refund.\n    Calling function speak_to_user\n    Assistant: Thank you for contacting us about this issue. Please don't hesitate to reach out if you have any more questions or need further assistance in the future.\n\n\n\n```python\nmessages = submit_user_message(\"Yes I would like to proceed with the refund.\",messages)\n```\n\n    User: Yes I would like to proceed with the refund.\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: Thank you for confirming. I have processed the refund for the stolen shirt. The amount should be reflected in your account within 5-7 business days. If you have any more questions or need further assistance, please feel free to contact us.\n\n\n\n```python\nmessages = submit_user_message(\"Thanks very much.\",messages)\n```\n\n    User: Thanks very much.\n    Calling function speak_to_user\n    Assistant: You're welcome! If you need any more help in the future, don't hesitate to reach out. Have a great day!\n\n\n## Evaluation\n\nNow we'll do a simple evaluation where a GPT will pretend to be our customer. The two will go back and forth until a resolution is reached.\n\nWe'll reuse the functions above, adding an `execute_conversation` function where the customer GPT will continue answering.\n\n\n```python\ncustomer_system_prompt = \"\"\"You are a user calling in to customer service.\nYou will talk to the agent until you have a resolution to your query.\nYour query is {query}.\nYou will be presented with a conversation - provide answers for any assistant questions you receive. \nHere is the conversation - you are the \"user\" and you are speaking with the \"assistant\":\n{chat_history}\n\nIf you don't know the details, respond with dummy values.\nOnce your query is resolved, respond with \"DONE\" \"\"\"\n\n# Initiate a bank of questions run through\nquestions = ['I want to get a refund for the suit I ordered last Friday.',\n            'Can you tell me what your policy is for returning damaged goods?',\n            'Please tell me what your complaint policy is']\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 3dd427d0-8501-45a7-bca4-f6d5e84ec5a2
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3dd427d0-8501-45a7-bca4-f6d5e84ec5a2\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"27e2138d-c284-4672-9afd-c1261160e3fa\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"04e1d6042d4676d45a4dba632d37773a2c21bc75a36f19fbdd770bf9b2bfb3a3\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"8244939c-7290-4d28-b386-2e7b2eb02f9f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"fcc9e78b1db92e14c424f56c897c2ef3475f2fa24fa91a410c55e3c4babc4894\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9550, \"end_char_idx\": 13207, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "```python\nmessages = submit_user_message(\"Yes I would like to proceed with the refund.\",messages)\n```\n\n    User: Yes I would like to proceed with the refund.\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: Thank you for confirming. I have processed the refund for the stolen shirt. The amount should be reflected in your account within 5-7 business days. If you have any more questions or need further assistance, please feel free to contact us.\n\n\n\n```python\nmessages = submit_user_message(\"Thanks very much.\",messages)\n```\n\n    User: Thanks very much.\n    Calling function speak_to_user\n    Assistant: You're welcome! If you need any more help in the future, don't hesitate to reach out. Have a great day!\n\n\n## Evaluation\n\nNow we'll do a simple evaluation where a GPT will pretend to be our customer. The two will go back and forth until a resolution is reached.\n\nWe'll reuse the functions above, adding an `execute_conversation` function where the customer GPT will continue answering.\n\n\n```python\ncustomer_system_prompt = \"\"\"You are a user calling in to customer service.\nYou will talk to the agent until you have a resolution to your query.\nYour query is {query}.\nYou will be presented with a conversation - provide answers for any assistant questions you receive. \nHere is the conversation - you are the \"user\" and you are speaking with the \"assistant\":\n{chat_history}\n\nIf you don't know the details, respond with dummy values.\nOnce your query is resolved, respond with \"DONE\" \"\"\"\n\n# Initiate a bank of questions run through\nquestions = ['I want to get a refund for the suit I ordered last Friday.',\n            'Can you tell me what your policy is for returning damaged goods?',\n            'Please tell me what your complaint policy is']\n```\n\n\n```python\ndef execute_conversation(objective):\n\n    conversation_messages = []\n\n    done = False\n\n    user_query = objective\n\n    while done is False:\n\n        conversation_messages = submit_user_message(user_query,conversation_messages)\n\n        messages_string = ''\n        for x in conversation_messages:\n            if isinstance(x,dict):\n                if x['role'] == 'user':\n                    messages_string += 'User: ' + x['content'] + '\\n'\n                elif x['role'] == 'tool':\n                    if x['name'] == 'speak_to_user':\n                        messages_string += 'Assistant: ' + x['content'] + '\\n'\n            else:\n                continue\n\n        messages = [\n            {\n            \"role\": \"system\",\n            \"content\": customer_system_prompt.format(query=objective,chat_history=messages_string)\n            },\n            {\n            \"role\": \"user\",\n            \"content\": \"Continue the chat to solve your query. Remember, you are in the user in this exchange. Do not provide User: or Assistant: in your response\"\n            }\n        ]\n\n        user_response = client.chat.completions.create(model=GPT_MODEL,messages=messages,temperature=0.5)\n\n        conversation_messages.append({\n            \"role\": \"user\",\n            \"content\": user_response.choices[0].message.content\n            })\n\n        if 'DONE' in user_response.choices[0].message.content:\n            done = True\n            print(\"Achieved objective, closing conversation\\n\\n\")\n\n        else:\n            user_query = user_response.choices[0].message.content\n```\n\n\n```python\nfor x in questions:\n\n    execute_conversation(x)\n```\n\n    User: I want to get a refund for the suit I ordered last Friday.\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: I understand you'd like a refund for the suit you ordered last Friday."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 8244939c-7290-4d28-b386-2e7b2eb02f9f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"8244939c-7290-4d28-b386-2e7b2eb02f9f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"3dd427d0-8501-45a7-bca4-f6d5e84ec5a2\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b4dfeeecd0222d2b1f4e9f5f59d0045dc0c1696790307b812df6c1a9b11c3d20\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"bd4d7ba3-0607-4a9f-9719-d08fafc60856\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"ea7fa1c7850943888862015156f00198482cfdfd65aa04044f86bb54687efad8\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11341, \"end_char_idx\": 14997, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "```python\ndef execute_conversation(objective):\n\n    conversation_messages = []\n\n    done = False\n\n    user_query = objective\n\n    while done is False:\n\n        conversation_messages = submit_user_message(user_query,conversation_messages)\n\n        messages_string = ''\n        for x in conversation_messages:\n            if isinstance(x,dict):\n                if x['role'] == 'user':\n                    messages_string += 'User: ' + x['content'] + '\\n'\n                elif x['role'] == 'tool':\n                    if x['name'] == 'speak_to_user':\n                        messages_string += 'Assistant: ' + x['content'] + '\\n'\n            else:\n                continue\n\n        messages = [\n            {\n            \"role\": \"system\",\n            \"content\": customer_system_prompt.format(query=objective,chat_history=messages_string)\n            },\n            {\n            \"role\": \"user\",\n            \"content\": \"Continue the chat to solve your query. Remember, you are in the user in this exchange. Do not provide User: or Assistant: in your response\"\n            }\n        ]\n\n        user_response = client.chat.completions.create(model=GPT_MODEL,messages=messages,temperature=0.5)\n\n        conversation_messages.append({\n            \"role\": \"user\",\n            \"content\": user_response.choices[0].message.content\n            })\n\n        if 'DONE' in user_response.choices[0].message.content:\n            done = True\n            print(\"Achieved objective, closing conversation\\n\\n\")\n\n        else:\n            user_query = user_response.choices[0].message.content\n```\n\n\n```python\nfor x in questions:\n\n    execute_conversation(x)\n```\n\n    User: I want to get a refund for the suit I ordered last Friday.\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: I understand you'd like a refund for the suit you ordered last Friday. Could you please provide more details about the issue with the suit? This will help us process your refund request accurately.\n    User: The suit I received is not the color I ordered. I ordered a navy blue suit, but the one I received is black.\n    Calling function speak_to_user\n    Assistant: Thank you for providing the details. I will proceed with the refund for the navy blue suit that was incorrectly sent as black. Please confirm if you would like me to go ahead with the refund.\n    User: Yes, please go ahead with the refund.\n    Calling function speak_to_user\n    Assistant: The refund for the incorrectly colored suit has been processed. You should see the amount credited back to your original payment method within 5-7 business days. Thank you for contacting us, and if you have any more questions or need further assistance, please feel free to reach out.\n    Achieved objective, closing conversation\n    \n    \n    User: Can you tell me what your policy is for returning damaged goods?\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: It seems there was a misunderstanding in my previous request. I'm looking for information on our policy for returning damaged goods. Could you please provide me with the details on how to handle returns for damaged items?\n    User: Yes, I'd appreciate that. Could you please tell me the steps I need to follow to return a damaged item?\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: I apologize for the confusion earlier. Here's the correct information regarding our policy for returning damaged goods:\n    \n    1. Please provide a description of the damage and the item involved.\n    2. Include the date of purchase and your order number if available.\n    3."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: bd4d7ba3-0607-4a9f-9719-d08fafc60856
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"bd4d7ba3-0607-4a9f-9719-d08fafc60856\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"8244939c-7290-4d28-b386-2e7b2eb02f9f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6bc656da392fdaf8562a67eb147ef4e25474f036daca05b8c65e5df4d7e9125c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d048e537-0315-439f-aaab-cc4369283888\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"77a8ad006666af5a70ebb37d4db72df52db78556f9dbc41242793d730a1f18de\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 13208, \"end_char_idx\": 16842, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "Could you please provide more details about the issue with the suit? This will help us process your refund request accurately.\n    User: The suit I received is not the color I ordered. I ordered a navy blue suit, but the one I received is black.\n    Calling function speak_to_user\n    Assistant: Thank you for providing the details. I will proceed with the refund for the navy blue suit that was incorrectly sent as black. Please confirm if you would like me to go ahead with the refund.\n    User: Yes, please go ahead with the refund.\n    Calling function speak_to_user\n    Assistant: The refund for the incorrectly colored suit has been processed. You should see the amount credited back to your original payment method within 5-7 business days. Thank you for contacting us, and if you have any more questions or need further assistance, please feel free to reach out.\n    Achieved objective, closing conversation\n    \n    \n    User: Can you tell me what your policy is for returning damaged goods?\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: It seems there was a misunderstanding in my previous request. I'm looking for information on our policy for returning damaged goods. Could you please provide me with the details on how to handle returns for damaged items?\n    User: Yes, I'd appreciate that. Could you please tell me the steps I need to follow to return a damaged item?\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: I apologize for the confusion earlier. Here's the correct information regarding our policy for returning damaged goods:\n    \n    1. Please provide a description of the damage and the item involved.\n    2. Include the date of purchase and your order number if available.\n    3. You can choose to return the item by mail or in person at one of our stores. Please let us know which method you prefer, and we will provide the necessary details for the return process.\n    4. Once we receive the item, we will inspect it and process a refund or exchange based on your preference and our return policy guidelines.\n    \n    Please let me know if you need further assistance with this process or if there's anything else I can help you with!\n    User: I would like to return the item by mail. Could you please provide me with the details on how to do that?\n    Calling function speak_to_user\n    Assistant: Certainly! To return the damaged item by mail, please follow these steps:\n    \n    1. Pack the item securely in its original packaging, if possible.\n    2. Include all original materials such as manuals, accessories, and receipts.\n    3. Address the package to our returns department at the following address:\n       [Your Company's Return Address]\n    4. Use a trackable shipping service and keep the tracking number for your records.\n    5. Once we receive and inspect the item, we will process your refund or exchange as per your request.\n    \n    Please let me know if you need a prepaid shipping label or any other assistance with your return!\n    User: Yes, please, I would need a prepaid shipping label.\n    Calling function speak_to_user\n    Assistant: I will arrange for a prepaid shipping label to be sent to your email address. Please ensure that the email address we have on file is correct. You should receive the label shortly, which you can print and attach to your return package.\n    \n    Once you've shipped the item, please provide us with the tracking number so we can monitor the return's progress. If there's anything else you need help with, feel free to ask!\n    User: That sounds great, thank you!"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: d048e537-0315-439f-aaab-cc4369283888
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d048e537-0315-439f-aaab-cc4369283888\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"bd4d7ba3-0607-4a9f-9719-d08fafc60856\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ef6dde0e11f8c9ab05bc0e8d48cd4db905e2861ce32ce1e8cf343fed8124fc22\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"86d669df-a020-4681-a297-6e55bc71af88\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a702238baed74aae3ee6020a2199b841723aff01893a1f7ccc6a150d1664a079\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14998, \"end_char_idx\": 18570, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "You can choose to return the item by mail or in person at one of our stores. Please let us know which method you prefer, and we will provide the necessary details for the return process.\n    4. Once we receive the item, we will inspect it and process a refund or exchange based on your preference and our return policy guidelines.\n    \n    Please let me know if you need further assistance with this process or if there's anything else I can help you with!\n    User: I would like to return the item by mail. Could you please provide me with the details on how to do that?\n    Calling function speak_to_user\n    Assistant: Certainly! To return the damaged item by mail, please follow these steps:\n    \n    1. Pack the item securely in its original packaging, if possible.\n    2. Include all original materials such as manuals, accessories, and receipts.\n    3. Address the package to our returns department at the following address:\n       [Your Company's Return Address]\n    4. Use a trackable shipping service and keep the tracking number for your records.\n    5. Once we receive and inspect the item, we will process your refund or exchange as per your request.\n    \n    Please let me know if you need a prepaid shipping label or any other assistance with your return!\n    User: Yes, please, I would need a prepaid shipping label.\n    Calling function speak_to_user\n    Assistant: I will arrange for a prepaid shipping label to be sent to your email address. Please ensure that the email address we have on file is correct. You should receive the label shortly, which you can print and attach to your return package.\n    \n    Once you've shipped the item, please provide us with the tracking number so we can monitor the return's progress. If there's anything else you need help with, feel free to ask!\n    User: That sounds great, thank you! My email address is correct on file. I'll look out for the prepaid shipping label and send the package back as soon as I receive it.\n    Calling function speak_to_user\n    Assistant: You're welcome! I'm glad I could assist you. Once you receive the prepaid shipping label, please proceed with the return as discussed. If you have any more questions or need further assistance in the future, don't hesitate to reach out. Have a great day!\n    Achieved objective, closing conversation\n    \n    \n    User: Please tell me what your complaint policy is\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: It seems there was a misunderstanding. I will provide you with information about our complaint policy. Please give me a moment to gather the correct details for you.\n    User: Sure, I'll wait. Thank you.\n    Calling function speak_to_user\n    Assistant: Our complaint policy is designed to ensure that any issues you encounter are addressed promptly and fairly. Here\u2019s a brief overview:\n    \n    1. **Submission**: You can submit your complaint through our website, by email, or by calling our customer service hotline.\n    2. **Acknowledgment**: We will acknowledge receipt of your complaint within 24 hours.\n    3. **Investigation**: We will investigate your complaint thoroughly. This process typically takes 3-5 business days.\n    4. **Resolution**: After the investigation, we will contact you with the outcome and any steps we will take to resolve the issue.\n    5. **Follow-up**: If you are not satisfied with the resolution, you can request a review of the decision.\n    \n    Please let me know if you need more detailed information or if there's anything else I can assist you with!"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 86d669df-a020-4681-a297-6e55bc71af88
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb", "title": "Using Tool Required for Customer Service", "tokens": 3814, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"86d669df-a020-4681-a297-6e55bc71af88\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"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\": \"63810a79-ff1f-44ad-b1c8-4e67d244c976\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c24edc3ba0f4627e0a356055aecd989311421ef871953d9b3ade6a19889df5a8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d048e537-0315-439f-aaab-cc4369283888\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Using_tool_required_for_customer_service.ipynb\", \"title\": \"Using Tool Required for Customer Service\", \"tokens\": 3814, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4c9187f2010da335b341cb1876043a49c166bb2a6fc0c57dd96c4ccfbf529b01\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 16740, \"end_char_idx\": 19201, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "ref_doc_id": "63810a79-ff1f-44ad-b1c8-4e67d244c976", "chroma:document": "If there's anything else you need help with, feel free to ask!\n    User: That sounds great, thank you! My email address is correct on file. I'll look out for the prepaid shipping label and send the package back as soon as I receive it.\n    Calling function speak_to_user\n    Assistant: You're welcome! I'm glad I could assist you. Once you receive the prepaid shipping label, please proceed with the return as discussed. If you have any more questions or need further assistance in the future, don't hesitate to reach out. Have a great day!\n    Achieved objective, closing conversation\n    \n    \n    User: Please tell me what your complaint policy is\n    Calling function get_instructions\n    Calling function speak_to_user\n    Assistant: It seems there was a misunderstanding. I will provide you with information about our complaint policy. Please give me a moment to gather the correct details for you.\n    User: Sure, I'll wait. Thank you.\n    Calling function speak_to_user\n    Assistant: Our complaint policy is designed to ensure that any issues you encounter are addressed promptly and fairly. Here\u2019s a brief overview:\n    \n    1. **Submission**: You can submit your complaint through our website, by email, or by calling our customer service hotline.\n    2. **Acknowledgment**: We will acknowledge receipt of your complaint within 24 hours.\n    3. **Investigation**: We will investigate your complaint thoroughly. This process typically takes 3-5 business days.\n    4. **Resolution**: After the investigation, we will contact you with the outcome and any steps we will take to resolve the issue.\n    5. **Follow-up**: If you are not satisfied with the resolution, you can request a review of the decision.\n    \n    Please let me know if you need more detailed information or if there's anything else I can assist you with!\n    User: That covers everything I needed to know, thank you!\n    Calling function speak_to_user\n    Assistant: You're welcome! I'm glad I could help. If you have any more questions in the future or need further assistance, feel free to reach out. Have a great day!\n    Achieved objective, closing conversation\n    \n    \n\n\n## Conclusion\n\nYou can now control your LLM's behaviour explicitly by making tool use mandatory, as well as spin up GPT testers to challenge your LLM and to act as automated test cases.\n\nWe hope this has given you an appreciation for a great use case for tool use, and look forward to seeing what you build!"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 98388a88-4f87-4e45-b4a6-90f6cbf0d9ed
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"98388a88-4f87-4e45-b4a6-90f6cbf0d9ed\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"cdbef906-2ead-4163-a02f-34c0d3213a67\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4b067052d386a0317f3945fbd2903e8a701548261f091d41579e2840cca189bc\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2766, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "# How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\n\nWelcome to the Clothing Matchmaker App Jupyter Notebook! This project demonstrates the power of the GPT-4o mini model in analyzing images of clothing items and extracting key features such as color, style, and type. The core of our app relies on this advanced image analysis model developed by OpenAI, which enables us to accurately identify the characteristics of the input clothing item.\n\nGPT-4o mini is a small model that combines natural language processing with image recognition, allowing it to understand and generate responses based on both text and visual inputs with low latency.\n\nBuilding on the capabilities of the GPT-4o mini model, we employ a custom matching algorithm and the RAG technique to search our knowledge base for items that complement the identified features. This algorithm takes into account factors like color compatibility and style coherence to provide users with suitable recommendations. Through this notebook, we aim to showcase the practical application of these technologies in creating a clothing recommendation system.\n\nUsing the combination of GPT-4o mini + RAG (Retrieval-Augmented Generation) offers several advantages:\n\n1. **Contextual Understanding**: GPT-4o mini can analyze input images and understand the context, such as the objects, scenes, and activities depicted. This allows for more accurate and relevant suggestions or information across various domains, whether it's interior design, cooking, or education.\n2. **Rich Knowledge Base**: RAG combines the generative capabilities of GPT-4 with a retrieval component that accesses a large corpus of information across different fields. This means the system can provide suggestions or insights based on a wide range of knowledge, from historical facts to scientific concepts.\n3. **Customization**: The approach allows for easy customization to cater to specific user needs or preferences in various applications. Whether it's tailoring suggestions to a user's taste in art or providing educational content based on a student's learning level, the system can be adapted to deliver personalized experiences.\n\nOverall, the GPT-4o mini + RAG approach offers a fast, powerful, and flexible solution for various fashion-related applications, leveraging the strengths of both generative and retrieval-based AI techniques.\n\n\n### Environment Setup\n\nFirst we will install the necessary dependencies, then import the libraries and write some utility functions that we will use later on. \n\n\n```python\n%pip install openai --quiet\n%pip install tenacity --quiet\n%pip install tqdm --quiet\n%pip install numpy --quiet\n%pip install typing --quiet\n%pip install tiktoken --quiet\n%pip install concurrent --quiet\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: cdbef906-2ead-4163-a02f-34c0d3213a67
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"cdbef906-2ead-4163-a02f-34c0d3213a67\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"98388a88-4f87-4e45-b4a6-90f6cbf0d9ed\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2d171c9e00f0df8a4626d2c278bfd49583a803c2b89c6f5ad582a950a5b0d1ac\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"adbe2496-a6bb-4e01-b452-5dfff69bf1d3\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6b66e0159e73f62d933b1cc4c7787df75cf4da5339012fa0f25b2a82472feedd\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2390, \"end_char_idx\": 4626, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "### Environment Setup\n\nFirst we will install the necessary dependencies, then import the libraries and write some utility functions that we will use later on. \n\n\n```python\n%pip install openai --quiet\n%pip install tenacity --quiet\n%pip install tqdm --quiet\n%pip install numpy --quiet\n%pip install typing --quiet\n%pip install tiktoken --quiet\n%pip install concurrent --quiet\n```\n\n\n```python\nimport pandas as pd\nimport numpy as np\nimport json\nimport ast\nimport tiktoken\nimport concurrent\nfrom openai import OpenAI\nfrom tqdm import tqdm\nfrom tenacity import retry, wait_random_exponential, stop_after_attempt\nfrom IPython.display import Image, display, HTML\nfrom typing import List\n\nclient = OpenAI()\n\nGPT_MODEL = \"gpt-4o-mini\"\nEMBEDDING_MODEL = \"text-embedding-3-large\"\nEMBEDDING_COST_PER_1K_TOKENS = 0.00013\n```\n\n### Creating the Embeddings\nWe will now set up the knowledge base by choosing a database and generating embeddings for it. I am using the `sample_styles.csv` file for this in the data folder. This is a sample of a bigger dataset that contains `~44K` items. This step can also be replaced by using an out-of-the-box vector database. For example, you can follow one of [these cookbooks](https://github.com/openai/openai-cookbook/tree/main/examples/vector_databases) to set up your vector database.\n\n\n```python\nstyles_filepath = \"data/sample_clothes/sample_styles.csv\"\nstyles_df = pd.read_csv(styles_filepath, on_bad_lines='skip')\nprint(styles_df.head())\nprint(\"Opened dataset successfully. Dataset has {} items of clothing.\".format(len(styles_df)))\n```\n\nNow we will generate embeddings for the entire dataset. We can parallelize the execution of these embeddings to ensure that the script scales up for larger datasets. With this logic, the time to create embeddings for the full `44K` entry dataset decreases from ~4h to ~2-3min. \n\n\n```python\n## Batch Embedding Logic\n\n# Simple function to take in a list of text objects and return them as a list of embeddings\n@retry(wait=wait_random_exponential(min=1, max=40), stop=stop_after_attempt(10))\ndef get_embeddings(input: List):\n    response = client.embeddings.create(\n        input=input,\n        model=EMBEDDING_MODEL\n    ).data\n    return [data.embedding for data in response]"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: adbe2496-a6bb-4e01-b452-5dfff69bf1d3
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"adbe2496-a6bb-4e01-b452-5dfff69bf1d3\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"cdbef906-2ead-4163-a02f-34c0d3213a67\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"855cddd476f117df126c302c65f24d2a3b496bde4c717b50955f1da5f5838eb6\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"778f4c04-8b47-49ba-a213-eb930411af3e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1e035c0284c164f9a9e376b5d1b21ff4838b6bca87ace823f02581026da7db24\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3699, \"end_char_idx\": 7475, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "```python\nstyles_filepath = \"data/sample_clothes/sample_styles.csv\"\nstyles_df = pd.read_csv(styles_filepath, on_bad_lines='skip')\nprint(styles_df.head())\nprint(\"Opened dataset successfully. Dataset has {} items of clothing.\".format(len(styles_df)))\n```\n\nNow we will generate embeddings for the entire dataset. We can parallelize the execution of these embeddings to ensure that the script scales up for larger datasets. With this logic, the time to create embeddings for the full `44K` entry dataset decreases from ~4h to ~2-3min. \n\n\n```python\n## Batch Embedding Logic\n\n# Simple function to take in a list of text objects and return them as a list of embeddings\n@retry(wait=wait_random_exponential(min=1, max=40), stop=stop_after_attempt(10))\ndef get_embeddings(input: List):\n    response = client.embeddings.create(\n        input=input,\n        model=EMBEDDING_MODEL\n    ).data\n    return [data.embedding for data in response]\n\n\n# Splits an iterable into batches of size n.\ndef batchify(iterable, n=1):\n    l = len(iterable)\n    for ndx in range(0, l, n):\n        yield iterable[ndx : min(ndx + n, l)]\n     \n\n# Function for batching and parallel processing the embeddings\ndef embed_corpus(\n    corpus: List[str],\n    batch_size=64,\n    num_workers=8,\n    max_context_len=8191,\n):\n    # Encode the corpus, truncating to max_context_len\n    encoding = tiktoken.get_encoding(\"cl100k_base\")\n    encoded_corpus = [\n        encoded_article[:max_context_len] for encoded_article in encoding.encode_batch(corpus)\n    ]\n\n    # Calculate corpus statistics: the number of inputs, the total number of tokens, and the estimated cost to embed\n    num_tokens = sum(len(article) for article in encoded_corpus)\n    cost_to_embed_tokens = num_tokens / 1000 * EMBEDDING_COST_PER_1K_TOKENS\n    print(\n        f\"num_articles={len(encoded_corpus)}, num_tokens={num_tokens}, est_embedding_cost={cost_to_embed_tokens:.2f} USD\"\n    )\n\n    # Embed the corpus\n    with concurrent.futures.ThreadPoolExecutor(max_workers=num_workers) as executor:\n        \n        futures = [\n            executor.submit(get_embeddings, text_batch)\n            for text_batch in batchify(encoded_corpus, batch_size)\n        ]\n\n        with tqdm(total=len(encoded_corpus)) as pbar:\n            for _ in concurrent.futures.as_completed(futures):\n                pbar.update(batch_size)\n\n        embeddings = []\n        for future in futures:\n            data = future.result()\n            embeddings.extend(data)\n\n        return embeddings\n    \n\n# Function to generate embeddings for a given column in a DataFrame\ndef generate_embeddings(df, column_name):\n    # Initialize an empty list to store embeddings\n    descriptions = df[column_name].astype(str).tolist()\n    embeddings = embed_corpus(descriptions)\n\n    # Add the embeddings as a new column to the DataFrame\n    df['embeddings'] = embeddings\n    print(\"Embeddings created successfully.\")\n```\n\n#### Two options for creating the embeddings: \nThe next line will **create the embeddings** for the sample clothes dataset. This will take around 0.02s to process and another ~30s to write the results to a local .csv file. The process is using our `text_embedding_3_large` model which is priced at `$0.00013/1K` tokens. Given that the dataset has around `1K` entries, the following operation will cost approximately `$0.001`. If you decide to work with the entire dataset of `44K` entries, this operation will take 2-3min to process and it will cost approximately `$0.07`.\n\n**If you would not like to proceed with creating your own embeddings**, we will use a dataset of pre-computed embeddings. You can skip this cell and uncomment the code in the following cell to proceed with loading the pre-computed vectors. This operation takes ~1min to load all the data in memory."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 778f4c04-8b47-49ba-a213-eb930411af3e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"778f4c04-8b47-49ba-a213-eb930411af3e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"adbe2496-a6bb-4e01-b452-5dfff69bf1d3\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"bc48b1f94cdcd2258aa81313eaf84d85abec458bff1364d16d50785e4148f647\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"3e1563ee-65bf-4af7-a01f-86f2f27b5d20\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9283f32949a6f26278109f8a2ecd9b7f681ed63b10893f0fdb668541ea556f63\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7478, \"end_char_idx\": 10780, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "```python\ngenerate_embeddings(styles_df, 'productDisplayName')\nprint(\"Writing embeddings to file ...\")\nstyles_df.to_csv('data/sample_clothes/sample_styles_with_embeddings.csv', index=False)\nprint(\"Embeddings successfully stored in sample_styles_with_embeddings.csv\")\n```\n\n\n```python\n# styles_df = pd.read_csv('data/sample_clothes/sample_styles_with_embeddings.csv', on_bad_lines='skip')\n\n# # Convert the 'embeddings' column from string representations of lists to actual lists of floats\n# styles_df['embeddings'] = styles_df['embeddings'].apply(lambda x: ast.literal_eval(x))\n\nprint(styles_df.head())\nprint(\"Opened dataset successfully. Dataset has {} items of clothing along with their embeddings.\".format(len(styles_df)))\n```\n\n### Building the Matching Algorithm\n\nIn this section, we'll develop a cosine similarity retrieval algorithm to find similar items in our dataframe. We'll utilize our custom cosine similarity function for this purpose. While the `sklearn` library offers a built-in cosine similarity function, recent updates to its SDK have led to compatibility issues, prompting us to implement our own standard cosine similarity calculation.\n\nIf you already have a vector database set up, you can skip this step. Most standard databases come with their own search functions, which simplify the subsequent steps outlined in this guide. However, we aim to demonstrate that the matching algorithm can be tailored to meet specific requirements, such as a particular threshold or a specified number of matches returned.\n\nThe `find_similar_items` function accepts four parameters:\n- `embedding`: The embedding for which we want to find a match.\n- `embeddings`: A list of embeddings to search through for the best matches.\n- `threshold` (optional): This parameter specifies the minimum similarity score for a match to be considered valid. A higher threshold results in closer (better) matches, while a lower threshold allows for more items to be returned, though they may not be as closely matched to the initial `embedding`.\n- `top_k` (optional): This parameter determines the number of items to return that exceed the given threshold. These will be the top-scoring matches for the provided `embedding`.\n\n\n```python\ndef cosine_similarity_manual(vec1, vec2):\n    \"\"\"Calculate the cosine similarity between two vectors.\"\"\"\n    vec1 = np.array(vec1, dtype=float)\n    vec2 = np.array(vec2, dtype=float)\n\n\n    dot_product = np.dot(vec1, vec2)\n    norm_vec1 = np.linalg.norm(vec1)\n    norm_vec2 = np.linalg.norm(vec2)\n    return dot_product / (norm_vec1 * norm_vec2)\n\n\ndef find_similar_items(input_embedding, embeddings, threshold=0.5, top_k=2):\n    \"\"\"Find the most similar items based on cosine similarity.\"\"\"\n    \n    # Calculate cosine similarity between the input embedding and all other embeddings\n    similarities = [(index, cosine_similarity_manual(input_embedding, vec)) for index, vec in enumerate(embeddings)]\n    \n    # Filter out any similarities below the threshold\n    filtered_similarities = [(index, sim) for index, sim in similarities if sim >= threshold]\n    \n    # Sort the filtered similarities by similarity score\n    sorted_indices = sorted(filtered_similarities, key=lambda x: x[1], reverse=True)[:top_k]\n\n    # Return the top-k most similar items\n    return sorted_indices\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 3e1563ee-65bf-4af7-a01f-86f2f27b5d20
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3e1563ee-65bf-4af7-a01f-86f2f27b5d20\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"778f4c04-8b47-49ba-a213-eb930411af3e\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"787d5ae53eddcec4f4b7f3977105123955507f4f8193785b753b84bd8b9e8070\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"04d7c8c0-ab0f-42eb-9b99-9d13e4851d38\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"354e8aed5aaa11445d1eacf62dbf48624f92213325c6b4af4d2f640a5589a786\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9691, \"end_char_idx\": 13332, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "```python\ndef cosine_similarity_manual(vec1, vec2):\n    \"\"\"Calculate the cosine similarity between two vectors.\"\"\"\n    vec1 = np.array(vec1, dtype=float)\n    vec2 = np.array(vec2, dtype=float)\n\n\n    dot_product = np.dot(vec1, vec2)\n    norm_vec1 = np.linalg.norm(vec1)\n    norm_vec2 = np.linalg.norm(vec2)\n    return dot_product / (norm_vec1 * norm_vec2)\n\n\ndef find_similar_items(input_embedding, embeddings, threshold=0.5, top_k=2):\n    \"\"\"Find the most similar items based on cosine similarity.\"\"\"\n    \n    # Calculate cosine similarity between the input embedding and all other embeddings\n    similarities = [(index, cosine_similarity_manual(input_embedding, vec)) for index, vec in enumerate(embeddings)]\n    \n    # Filter out any similarities below the threshold\n    filtered_similarities = [(index, sim) for index, sim in similarities if sim >= threshold]\n    \n    # Sort the filtered similarities by similarity score\n    sorted_indices = sorted(filtered_similarities, key=lambda x: x[1], reverse=True)[:top_k]\n\n    # Return the top-k most similar items\n    return sorted_indices\n```\n\n\n```python\ndef find_matching_items_with_rag(df_items, item_descs):\n   \"\"\"Take the input item descriptions and find the most similar items based on cosine similarity for each description.\"\"\"\n   \n   # Select the embeddings from the DataFrame.\n   embeddings = df_items['embeddings'].tolist()\n\n   \n   similar_items = []\n   for desc in item_descs:\n      \n      # Generate the embedding for the input item\n      input_embedding = get_embeddings([desc])\n    \n      # Find the most similar items based on cosine similarity\n      similar_indices = find_similar_items(input_embedding, embeddings, threshold=0.6)\n      similar_items += [df_items.iloc[i] for i in similar_indices]\n    \n   return similar_items\n```\n\n### Analysis Module\n\nIn this module, we leverage `gpt-4o-mini` to analyze input images and extract important features like detailed descriptions, styles, and types. The analysis is performed through a straightforward API call, where we provide the URL of the image for analysis and request the model to identify relevant features.\n\nTo ensure the model returns accurate results, we use specific techniques in our prompt:\n\n1. **Output Format Specification**: We instruct the model to return a JSON block with a predefined structure, consisting of:\n   - `items` (str[]): A list of strings, each representing a concise title for an item of clothing, including style, color, and gender. These titles closely resemble the `productDisplayName` property in our original database.\n   - `category` (str): The category that best represents the given item. The model selects from a list of all unique `articleTypes` present in the original styles dataframe.\n   - `gender` (str): A label indicating the gender the item is intended for. The model chooses from the options `[Men, Women, Boys, Girls, Unisex]`.\n\n2. **Clear and Concise Instructions**: \n   - We provide clear instructions on what the item titles should include and what the output format should be. The output should be in JSON format, but without the `json` tag that the model response normally contains.\n\n3. **One Shot Example**: \n   - To further clarify the expected output, we provide the model with an example input description and a corresponding example output. Although this may increase the number of tokens used (and thus the cost of the call), it helps to guide the model and results in better overall performance.\n\nBy following this structured approach, we aim to obtain precise and useful information from the `gpt-4o-mini` model for further analysis and integration into our database."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 04d7c8c0-ab0f-42eb-9b99-9d13e4851d38
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"04d7c8c0-ab0f-42eb-9b99-9d13e4851d38\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"3e1563ee-65bf-4af7-a01f-86f2f27b5d20\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"45935f0aee06e40c8547c0a0f613eb28e7463780fe7bc4e47212b89e5159a4c1\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"4b783455-84e4-4e74-ac35-75fca1e7afef\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"88985f770e9bbc61ac012155e9d3556de2ccd967051a6eeac3219bdd4bea22c3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 13335, \"end_char_idx\": 16438, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "```python\ndef analyze_image(image_base64, subcategories):\n    response = client.chat.completions.create(\n        model=GPT_MODEL,\n        messages=[\n            {\n            \"role\": \"user\",\n            \"content\": [\n                {\n                \"type\": \"text\",\n                \"text\": \"\"\"Given an image of an item of clothing, analyze the item and generate a JSON output with the following fields: \"items\", \"category\", and \"gender\". \n                           Use your understanding of fashion trends, styles, and gender preferences to provide accurate and relevant suggestions for how to complete the outfit.\n                           The items field should be a list of items that would go well with the item in the picture. Each item should represent a title of an item of clothing that contains the style, color, and gender of the item.\n                           The category needs to be chosen between the types in this list: {subcategories}.\n                           You have to choose between the genders in this list: [Men, Women, Boys, Girls, Unisex]\n                           Do not include the description of the item in the picture. Do not include the ```json ``` tag in the output.\n                           \n                           Example Input: An image representing a black leather jacket.\n\n                           Example Output: {\"items\": [\"Fitted White Women's T-shirt\", \"White Canvas Sneakers\", \"Women's Black Skinny Jeans\"], \"category\": \"Jackets\", \"gender\": \"Women\"}\n                           \"\"\",\n                },\n                {\n                \"type\": \"image_url\",\n                \"image_url\": {\n                    \"url\": f\"data:image/jpeg;base64,{image_base64}\",\n                },\n                }\n            ],\n            }\n        ]\n    )\n    # Extract relevant features from the response\n    features = response.choices[0].message.content\n    return features\n```\n\n### Testing the Prompt with Sample Images\n\nTo evaluate the effectiveness of our prompt, let's load and test it with a selection of images from our dataset. We'll use images from the `\"data/sample_clothes/sample_images\"` folder, ensuring a variety of styles, genders, and types. Here are the chosen samples:\n\n- `2133.jpg`: Men's shirt\n- `7143.jpg`: Women's shirt\n- `4226.jpg`: Casual men's printed t-shirt\n\nBy testing the prompt with these diverse images, we can assess its ability to accurately analyze and extract relevant features from different types of clothing items and accessories.\n\nWe need a utility function to encode the .jpg images in base64\n\n\n```python\nimport base64\n\ndef encode_image_to_base64(image_path):\n    with open(image_path, 'rb') as image_file:\n        encoded_image = base64.b64encode(image_file.read())\n        return encoded_image.decode('utf-8')\n```\n\n\n```python\n# Set the path to the images and select a test image\nimage_path = \"data/sample_clothes/sample_images/\"\ntest_images = [\"2133.jpg\", \"7143.jpg\", \"4226.jpg\"]\n\n# Encode the test image to base64\nreference_image = image_path + test_images[0]\nencoded_image = encode_image_to_base64(reference_image)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 4b783455-84e4-4e74-ac35-75fca1e7afef
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4b783455-84e4-4e74-ac35-75fca1e7afef\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"04d7c8c0-ab0f-42eb-9b99-9d13e4851d38\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1b3b3aa44cddb2147db091208badf2abde719602a336749ad7bbdccd1226ba10\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"19ef5dc0-2ac7-422c-90b0-b5caebb28fd7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"dbdf0aa517644f727fb8328e942df9604c1e74a7867e5348711ac4195312a672\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 15911, \"end_char_idx\": 18122, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "```python\nimport base64\n\ndef encode_image_to_base64(image_path):\n    with open(image_path, 'rb') as image_file:\n        encoded_image = base64.b64encode(image_file.read())\n        return encoded_image.decode('utf-8')\n```\n\n\n```python\n# Set the path to the images and select a test image\nimage_path = \"data/sample_clothes/sample_images/\"\ntest_images = [\"2133.jpg\", \"7143.jpg\", \"4226.jpg\"]\n\n# Encode the test image to base64\nreference_image = image_path + test_images[0]\nencoded_image = encode_image_to_base64(reference_image)\n```\n\n\n```python\n# Select the unique subcategories from the DataFrame\nunique_subcategories = styles_df['articleType'].unique()\n\n# Analyze the image and return the results\nanalysis = analyze_image(encoded_image, unique_subcategories)\nimage_analysis = json.loads(analysis)\n\n# Display the image and the analysis results\ndisplay(Image(filename=reference_image))\nprint(image_analysis)\n```\n\nNext, we process the output from the image analysis and use it to filter and display matching items from our dataset. Here's a breakdown of the code:\n\n1. **Extracting Image Analysis Results**: We extract the item descriptions, category, and gender from the `image_analysis` dictionary.\n\n2. **Filtering the Dataset**: We filter the `styles_df` DataFrame to include only items that match the gender from the image analysis (or are unisex) and exclude items of the same category as the analyzed image.\n\n3. **Finding Matching Items**: We use the `find_matching_items_with_rag` function to find items in the filtered dataset that match the descriptions extracted from the analyzed image.\n\n4. **Displaying Matching Items**: We create an HTML string to display images of the matching items. We construct the image paths using the item IDs and append each image to the HTML string. Finally, we use `display(HTML(html))` to render the images in the notebook.\n\nThis cell effectively demonstrates how to use the results of image analysis to filter a dataset and visually display items that match the analyzed image's characteristics.\n\n\n```python\n# Extract the relevant features from the analysis\nitem_descs = image_analysis['items']\nitem_category = image_analysis['category']\nitem_gender = image_analysis['gender']"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 19ef5dc0-2ac7-422c-90b0-b5caebb28fd7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"19ef5dc0-2ac7-422c-90b0-b5caebb28fd7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"4b783455-84e4-4e74-ac35-75fca1e7afef\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0568fa15a10720712726686688afb9645457fae066e9ebc31956a10ba10b8111\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d61c81f0-9b86-4139-8cfb-92f2478d7d79\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e8a43e256bc187afe201b01859a1207c94c5bf706fa1cb3a9247c894dc27d417\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 16441, \"end_char_idx\": 21055, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "```python\n# Select the unique subcategories from the DataFrame\nunique_subcategories = styles_df['articleType'].unique()\n\n# Analyze the image and return the results\nanalysis = analyze_image(encoded_image, unique_subcategories)\nimage_analysis = json.loads(analysis)\n\n# Display the image and the analysis results\ndisplay(Image(filename=reference_image))\nprint(image_analysis)\n```\n\nNext, we process the output from the image analysis and use it to filter and display matching items from our dataset. Here's a breakdown of the code:\n\n1. **Extracting Image Analysis Results**: We extract the item descriptions, category, and gender from the `image_analysis` dictionary.\n\n2. **Filtering the Dataset**: We filter the `styles_df` DataFrame to include only items that match the gender from the image analysis (or are unisex) and exclude items of the same category as the analyzed image.\n\n3. **Finding Matching Items**: We use the `find_matching_items_with_rag` function to find items in the filtered dataset that match the descriptions extracted from the analyzed image.\n\n4. **Displaying Matching Items**: We create an HTML string to display images of the matching items. We construct the image paths using the item IDs and append each image to the HTML string. Finally, we use `display(HTML(html))` to render the images in the notebook.\n\nThis cell effectively demonstrates how to use the results of image analysis to filter a dataset and visually display items that match the analyzed image's characteristics.\n\n\n```python\n# Extract the relevant features from the analysis\nitem_descs = image_analysis['items']\nitem_category = image_analysis['category']\nitem_gender = image_analysis['gender']\n\n\n# Filter data such that we only look through the items of the same gender (or unisex) and different category\nfiltered_items = styles_df.loc[styles_df['gender'].isin([item_gender, 'Unisex'])]\nfiltered_items = filtered_items[filtered_items['articleType'] != item_category]\nprint(str(len(filtered_items)) + \" Remaining Items\")\n\n# Find the most similar items based on the input item descriptions\nmatching_items = find_matching_items_with_rag(filtered_items, item_descs)\n\n# Display the matching items (this will display 2 items for each description in the image analysis)\nhtml = \"\"\npaths = []\nfor i, item in enumerate(matching_items):\n    item_id = item['id']\n        \n    # Path to the image file\n    image_path = f'data/sample_clothes/sample_images/{item_id}.jpg'\n    paths.append(image_path)\n    html += f'<img src=\"{image_path}\" style=\"display:inline;margin:1px\"/>'\n\n# Print the matching item description as a reminder of what we are looking for\nprint(item_descs)\n# Display the image\ndisplay(HTML(html))\n```\n\n### Guardrails\n\nIn the context of using Large Language Models (LLMs) like GPT-4o mini, \"guardrails\" refer to mechanisms or checks put in place to ensure that the model's output remains within desired parameters or boundaries. These guardrails are crucial for maintaining the quality and relevance of the model's responses, especially when dealing with complex or nuanced tasks.\n\nGuardrails are useful for several reasons:\n\n1. **Accuracy**: They help ensure that the model's output is accurate and relevant to the input provided.\n2. **Consistency**: They maintain consistency in the model's responses, especially when dealing with similar or related inputs.\n3. **Safety**: They prevent the model from generating harmful, offensive, or inappropriate content.\n4. **Contextual Relevance**: They ensure that the model's output is contextually relevant to the specific task or domain it is being used for.\n\nIn our case, we are using GPT-4o mini to analyze fashion images and suggest items that would complement an original outfit. To implement guardrails, we can **refine results**: After obtaining initial suggestions from GPT-4o mini, we can send the original image and the suggested items back to the model. We can then ask GPT-4o mini to evaluate whether each suggested item would indeed be a good fit for the original outfit.\n\nThis gives the model the ability to self-correct and adjust its own output based on feedback or additional information. By implementing these guardrails and enabling self-correction, we can enhance the reliability and usefulness of the model's output in the context of fashion analysis and recommendation.\n\nTo facilitate this, we write a prompt that asks the LLM for a simple \"yes\" or \"no\" answer to the question of whether the suggested items match the original outfit or not. This binary response helps streamline the refinement process and ensures clear and actionable feedback from the model."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: d61c81f0-9b86-4139-8cfb-92f2478d7d79
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d61c81f0-9b86-4139-8cfb-92f2478d7d79\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"19ef5dc0-2ac7-422c-90b0-b5caebb28fd7\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8b4bbd959c254c6ac61c9eda41e6dd36d2b1d4905900e0d2c381b56db2b34b0d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"3101bc1d-05ab-44e6-8fa8-3f1dca0e1beb\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"c28c47bfbaf2aebf870df6fc4556b8a4fb442d651e652bbcd7fa8a114ee531a7\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 21058, \"end_char_idx\": 23017, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "```python\ndef check_match(reference_image_base64, suggested_image_base64):\n    response = client.chat.completions.create(\n        model=GPT_MODEL,\n        messages=[\n            {\n            \"role\": \"user\",\n            \"content\": [\n                {\n                \"type\": \"text\",\n                \"text\": \"\"\" You will be given two images of two different items of clothing.\n                            Your goal is to decide if the items in the images would work in an outfit together.\n                            The first image is the reference item (the item that the user is trying to match with another item).\n                            You need to decide if the second item would work well with the reference item.\n                            Your response must be a JSON output with the following fields: \"answer\", \"reason\".\n                            The \"answer\" field must be either \"yes\" or \"no\", depending on whether you think the items would work well together.\n                            The \"reason\" field must be a short explanation of your reasoning for your decision. Do not include the descriptions of the 2 images.\n                            Do not include the ```json ``` tag in the output.\n                           \"\"\",\n                },\n                {\n                \"type\": \"image_url\",\n                \"image_url\": {\n                    \"url\": f\"data:image/jpeg;base64,{reference_image_base64}\",\n                },\n                },\n                {\n                \"type\": \"image_url\",\n                \"image_url\": {\n                    \"url\": f\"data:image/jpeg;base64,{suggested_image_base64}\",\n                },\n                }\n            ],\n            }\n        ],\n        max_tokens=300,\n    )\n    # Extract relevant features from the response\n    features = response.choices[0].message.content\n    return features\n```\n\nFinally, let's determine which of the items identified above truly complement the outfit."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 3101bc1d-05ab-44e6-8fa8-3f1dca0e1beb
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb", "title": "How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App", "tokens": 5266, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3101bc1d-05ab-44e6-8fa8-3f1dca0e1beb\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"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\": \"ef20a4f4-9a14-43e2-8a2a-6aca23af216e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"54f90d7499f88d3942fd0d36a197c9e9e66835e8c51789f7a058b96e96409ab0\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d61c81f0-9b86-4139-8cfb-92f2478d7d79\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/How_to_combine_GPT4o_with_RAG_Outfit_Assistant.ipynb\", \"title\": \"How to Combine GPT-4o Mini with RAG - Create a Clothing Matchmaker App\", \"tokens\": 5266, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"9b8f114e34f4493f3c382dbdd949e797deb7a93b5873344bcb73899cb7750256\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 21058, \"end_char_idx\": 25503, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "ref_doc_id": "ef20a4f4-9a14-43e2-8a2a-6aca23af216e", "chroma:document": "```python\ndef check_match(reference_image_base64, suggested_image_base64):\n    response = client.chat.completions.create(\n        model=GPT_MODEL,\n        messages=[\n            {\n            \"role\": \"user\",\n            \"content\": [\n                {\n                \"type\": \"text\",\n                \"text\": \"\"\" You will be given two images of two different items of clothing.\n                            Your goal is to decide if the items in the images would work in an outfit together.\n                            The first image is the reference item (the item that the user is trying to match with another item).\n                            You need to decide if the second item would work well with the reference item.\n                            Your response must be a JSON output with the following fields: \"answer\", \"reason\".\n                            The \"answer\" field must be either \"yes\" or \"no\", depending on whether you think the items would work well together.\n                            The \"reason\" field must be a short explanation of your reasoning for your decision. Do not include the descriptions of the 2 images.\n                            Do not include the ```json ``` tag in the output.\n                           \"\"\",\n                },\n                {\n                \"type\": \"image_url\",\n                \"image_url\": {\n                    \"url\": f\"data:image/jpeg;base64,{reference_image_base64}\",\n                },\n                },\n                {\n                \"type\": \"image_url\",\n                \"image_url\": {\n                    \"url\": f\"data:image/jpeg;base64,{suggested_image_base64}\",\n                },\n                }\n            ],\n            }\n        ],\n        max_tokens=300,\n    )\n    # Extract relevant features from the response\n    features = response.choices[0].message.content\n    return features\n```\n\nFinally, let's determine which of the items identified above truly complement the outfit.\n\n\n```python\n# Select the unique paths for the generated images\npaths = list(set(paths))\n\nfor path in paths:\n    # Encode the test image to base64\n    suggested_image = encode_image_to_base64(path)\n    \n    # Check if the items match\n    match = json.loads(check_match(encoded_image, suggested_image))\n    \n    # Display the image and the analysis results\n    if match[\"answer\"] == 'yes':\n        display(Image(filename=path))\n        print(\"The items match!\")\n        print(match[\"reason\"])\n```\n\nWe can observe that the initial list of potential items has been further refined, resulting in a more curated selection that aligns well with the outfit. Additionally, the model provides explanations for why each item is considered a good match, offering valuable insights into the decision-making process.\n\n### Conclusion\n\nIn this Jupyter Notebook, we explored the application of GPT-4o mini and other machine learning techniques to the domain of fashion. We demonstrated how to analyze images of clothing items, extract relevant features, and use this information to find matching items that complement an original outfit. Through the implementation of guardrails and self-correction mechanisms, we refined the model's suggestions to ensure they are accurate and contextually relevant.\n\nThis approach has several practical uses in the real world, including:\n\n1. **Personalized Shopping Assistants**: Retailers can use this technology to offer personalized outfit recommendations to customers, enhancing the shopping experience and increasing customer satisfaction.\n2. **Virtual Wardrobe Applications**: Users can upload images of their own clothing items to create a virtual wardrobe and receive suggestions for new items that match their existing pieces.\n3. **Fashion Design and Styling**: Fashion designers and stylists can use this tool to experiment with different combinations and styles, streamlining the creative process.\n\nHowever, one of the considerations to keep in mind is **cost**. The use of LLMs and image analysis models can incur costs, especially if used extensively. It's important to consider the cost-effectiveness of implementing these technologies. `gpt-4o-mini` is priced at `$0.01` per 1000 tokens. This adds up to `$0.00255` for one 256px x 256px image.\n\nOverall, this notebook serves as a foundation for further exploration and development in the intersection of fashion and AI, opening doors to more personalized and intelligent fashion recommendation systems."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0203cd03-4fc1-4cdb-a580-8466378bac63
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb", "title": "Fine tuning classification example", "tokens": 3848, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0203cd03-4fc1-4cdb-a580-8466378bac63\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"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\": \"2a529fbb-af14-46a4-bb64-86ced52106f9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba4e67ea68b645ec93fe770b4d7ccfa221ec7add0c2a439f442571930ab51f9b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"bb400bad-32e7-411f-80c6-1b7890e6e2e7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"496b3b34efacd1ef7deb4f5596dae7db9fb3d2f7b5a17acc8f28fc8f1dc7a1df\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2962, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "ref_doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "chroma:document": "# Fine tuning classification example\n\nWe will fine-tune a `babbage-002` classifier (replacement for the `ada` models) to distinguish between the two sports: Baseball and Hockey.\n\n\n```python\nfrom sklearn.datasets import fetch_20newsgroups\nimport pandas as pd\nimport openai\nimport os\n\nclient = openai.OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as env var>\"))\n\ncategories = ['rec.sport.baseball', 'rec.sport.hockey']\nsports_dataset = fetch_20newsgroups(subset='train', shuffle=True, random_state=42, categories=categories)\n```\n\n ## Data exploration\n The newsgroup dataset can be loaded using sklearn. First we will look at the data itself:\n\n\n```python\nprint(sports_dataset['data'][0])\n```\n\n    From: dougb@comm.mot.com (Doug Bank)\n    Subject: Re: Info needed for Cleveland tickets\n    Reply-To: dougb@ecs.comm.mot.com\n    Organization: Motorola Land Mobile Products Sector\n    Distribution: usa\n    Nntp-Posting-Host: 145.1.146.35\n    Lines: 17\n    \n    In article <1993Apr1.234031.4950@leland.Stanford.EDU>, bohnert@leland.Stanford.EDU (matthew bohnert) writes:\n    \n    |> I'm going to be in Cleveland Thursday, April 15 to Sunday, April 18.\n    |> Does anybody know if the Tribe will be in town on those dates, and\n    |> if so, who're they playing and if tickets are available?\n    \n    The tribe will be in town from April 16 to the 19th.\n    There are ALWAYS tickets available! (Though they are playing Toronto,\n    and many Toronto fans make the trip to Cleveland as it is easier to\n    get tickets in Cleveland than in Toronto.  Either way, I seriously\n    doubt they will sell out until the end of the season.)\n    \n    -- \n    Doug Bank                       Private Systems Division\n    dougb@ecs.comm.mot.com          Motorola Communications Sector\n    dougb@nwu.edu                   Schaumburg, Illinois\n    dougb@casbah.acns.nwu.edu       708-576-8207                    \n    \n\n\n\n```python\nsports_dataset.target_names[sports_dataset['target'][0]]\n\n```\n\n\n\n\n    'rec.sport.baseball'\n\n\n\n\n```python\nlen_all, len_baseball, len_hockey = len(sports_dataset.data), len([e for e in sports_dataset.target if e == 0]), len([e for e in sports_dataset.target if e == 1])\nprint(f\"Total examples: {len_all}, Baseball examples: {len_baseball}, Hockey examples: {len_hockey}\")\n```\n\n    Total examples: 1197, Baseball examples: 597, Hockey examples: 600\n\n\nOne sample from the baseball category can be seen above. It is an email to a mailing list. We can observe that we have 1197 examples in total, which are evenly split between the two sports.\n\n## Data Preparation\nWe transform the dataset into a pandas dataframe, with a column for prompt and completion. The prompt contains the email from the mailing list, and the completion is a name of the sport, either hockey or baseball. For demonstration purposes only and speed of fine-tuning we take only 300 examples. In a real use case the more examples the better the performance."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: bb400bad-32e7-411f-80c6-1b7890e6e2e7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb", "title": "Fine tuning classification example", "tokens": 3848, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"bb400bad-32e7-411f-80c6-1b7890e6e2e7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"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\": \"2a529fbb-af14-46a4-bb64-86ced52106f9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba4e67ea68b645ec93fe770b4d7ccfa221ec7add0c2a439f442571930ab51f9b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0203cd03-4fc1-4cdb-a580-8466378bac63\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c73cfba256d2c6cddab65484c7e7eaad57e366e8dbab269ee19563bff73e566e\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7dfed2d8-9bc5-4bbf-bf3b-f7471a36bd16\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f88b789bef18a50b8cc6d4dcc834d0b0434aaf41dce7fcab75fb866a03177347\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1931, \"end_char_idx\": 4391, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "ref_doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "chroma:document": "```python\nsports_dataset.target_names[sports_dataset['target'][0]]\n\n```\n\n\n\n\n    'rec.sport.baseball'\n\n\n\n\n```python\nlen_all, len_baseball, len_hockey = len(sports_dataset.data), len([e for e in sports_dataset.target if e == 0]), len([e for e in sports_dataset.target if e == 1])\nprint(f\"Total examples: {len_all}, Baseball examples: {len_baseball}, Hockey examples: {len_hockey}\")\n```\n\n    Total examples: 1197, Baseball examples: 597, Hockey examples: 600\n\n\nOne sample from the baseball category can be seen above. It is an email to a mailing list. We can observe that we have 1197 examples in total, which are evenly split between the two sports.\n\n## Data Preparation\nWe transform the dataset into a pandas dataframe, with a column for prompt and completion. The prompt contains the email from the mailing list, and the completion is a name of the sport, either hockey or baseball. For demonstration purposes only and speed of fine-tuning we take only 300 examples. In a real use case the more examples the better the performance.\n\n\n```python\nimport pandas as pd\n\nlabels = [sports_dataset.target_names[x].split('.')[-1] for x in sports_dataset['target']]\ntexts = [text.strip() for text in sports_dataset['data']]\ndf = pd.DataFrame(zip(texts, labels), columns = ['prompt','completion']) #[:300]\ndf.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>prompt</th>\n      <th>completion</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>From: dougb@comm.mot.com (Doug Bank)\\nSubject:...</td>\n      <td>baseball</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>From: gld@cunixb.cc.columbia.edu (Gary L Dare)...</td>\n      <td>hockey</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>From: rudy@netcom.com (Rudy Wade)\\nSubject: Re...</td>\n      <td>baseball</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>From: monack@helium.gas.uug.arizona.edu (david...</td>\n      <td>hockey</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>Subject: Let it be Known\\nFrom: &lt;ISSBTL@BYUVM....</td>\n      <td>baseball</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\nBoth baseball and hockey are single tokens. We save the dataset as a jsonl file."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 7dfed2d8-9bc5-4bbf-bf3b-f7471a36bd16
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb", "title": "Fine tuning classification example", "tokens": 3848, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7dfed2d8-9bc5-4bbf-bf3b-f7471a36bd16\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"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\": \"2a529fbb-af14-46a4-bb64-86ced52106f9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba4e67ea68b645ec93fe770b4d7ccfa221ec7add0c2a439f442571930ab51f9b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"bb400bad-32e7-411f-80c6-1b7890e6e2e7\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4ef8867a316c3d2ddc1484b2ed34eb944ca6378a22a3033ade919c287e40c846\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"485698e5-772b-4556-8137-9b0b9f12dbb7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"12a332fba1557fc351bbac88bbb8b8d5e0ceb0d2c6c625a740cd6a611d9271ec\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3244, \"end_char_idx\": 4779, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "ref_doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "chroma:document": "<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>prompt</th>\n      <th>completion</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>From: dougb@comm.mot.com (Doug Bank)\\nSubject:...</td>\n      <td>baseball</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>From: gld@cunixb.cc.columbia.edu (Gary L Dare)...</td>\n      <td>hockey</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>From: rudy@netcom.com (Rudy Wade)\\nSubject: Re...</td>\n      <td>baseball</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>From: monack@helium.gas.uug.arizona.edu (david...</td>\n      <td>hockey</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>Subject: Let it be Known\\nFrom: &lt;ISSBTL@BYUVM....</td>\n      <td>baseball</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\nBoth baseball and hockey are single tokens. We save the dataset as a jsonl file.\n\n\n```python\ndf.to_json(\"sport2.jsonl\", orient='records', lines=True)\n```\n\n### Data Preparation tool\nWe can now use a data preparation tool which will suggest a few improvements to our dataset before fine-tuning. Before launching the tool we update the openai library to ensure we're using the latest data preparation tool. We additionally specify `-q` which auto-accepts all suggestions."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 485698e5-772b-4556-8137-9b0b9f12dbb7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb", "title": "Fine tuning classification example", "tokens": 3848, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"485698e5-772b-4556-8137-9b0b9f12dbb7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"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\": \"2a529fbb-af14-46a4-bb64-86ced52106f9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba4e67ea68b645ec93fe770b4d7ccfa221ec7add0c2a439f442571930ab51f9b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"7dfed2d8-9bc5-4bbf-bf3b-f7471a36bd16\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d3d793e2e2ca9cd6cf1c9f6e2cabcc7c2ccaa088d575d0a5991d20b15510d2c0\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e46607e8-41c1-4555-80e9-eeea197f9db9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"fe30c63f0f2368bf4efd3b9736e3f67123d12caa2982566be8a35ec763da702c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4311, \"end_char_idx\": 7360, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "ref_doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "chroma:document": "Both baseball and hockey are single tokens. We save the dataset as a jsonl file.\n\n\n```python\ndf.to_json(\"sport2.jsonl\", orient='records', lines=True)\n```\n\n### Data Preparation tool\nWe can now use a data preparation tool which will suggest a few improvements to our dataset before fine-tuning. Before launching the tool we update the openai library to ensure we're using the latest data preparation tool. We additionally specify `-q` which auto-accepts all suggestions.\n\n\n```python\n!openai tools fine_tunes.prepare_data -f sport2.jsonl -q\n```\n\n    Analyzing...\n    \n    - Your file contains 1197 prompt-completion pairs\n    - Based on your data it seems like you're trying to fine-tune a model for classification\n    - For classification, we recommend you try one of the faster and cheaper models, such as `ada`\n    - For classification, you can estimate the expected model performance by keeping a held out dataset, which is not used for training\n    - There are 11 examples that are very long. These are rows: [134, 200, 281, 320, 404, 595, 704, 838, 1113, 1139, 1174]\n    For conditional generation, and for classification the examples shouldn't be longer than 2048 tokens.\n    - Your data does not contain a common separator at the end of your prompts. Having a separator string appended to the end of the prompt makes it clearer to the fine-tuned model where the completion should begin. See https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more detail and examples. If you intend to do open-ended generation, then you should leave the prompts empty\n    - The completion should start with a whitespace character (` `). This tends to produce better results due to the tokenization we use. See https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset for more details\n    \n    Based on the analysis we will perform the following actions:\n    - [Recommended] Remove 11 long examples [Y/n]: Y\n    - [Recommended] Add a suffix separator `\\n\\n###\\n\\n` to all prompts [Y/n]: Y\n    - [Recommended] Add a whitespace character to the beginning of the completion [Y/n]: Y\n    - [Recommended] Would you like to split into training and validation set? [Y/n]: Y\n    \n    \n    Your data will be written to a new JSONL file. Proceed [Y/n]: Y\n    \n    Wrote modified files to `sport2_prepared_train (1).jsonl` and `sport2_prepared_valid (1).jsonl`\n    Feel free to take a look!\n    \n    Now use that file when fine-tuning:\n    > openai api fine_tunes.create -t \"sport2_prepared_train (1).jsonl\" -v \"sport2_prepared_valid (1).jsonl\" --compute_classification_metrics --classification_positive_class \" baseball\"\n    \n    After you\u2019ve fine-tuned a model, remember that your prompt has to end with the indicator string `\\n\\n###\\n\\n` for the model to start generating completions, rather than continuing with the prompt.\n    Once your model starts training, it'll approximately take 30.8 minutes to train a `curie` model, and less for `ada` and `babbage`. Queue will approximately take half an hour per job ahead of you."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: e46607e8-41c1-4555-80e9-eeea197f9db9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb", "title": "Fine tuning classification example", "tokens": 3848, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e46607e8-41c1-4555-80e9-eeea197f9db9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"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\": \"2a529fbb-af14-46a4-bb64-86ced52106f9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba4e67ea68b645ec93fe770b4d7ccfa221ec7add0c2a439f442571930ab51f9b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"485698e5-772b-4556-8137-9b0b9f12dbb7\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"257bb25c7254ee3d5a1c1495182f897ea2ab9ac7c3999e03c71bce050e37bb15\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"6865179e-a5d1-4417-a610-0576e3b47e8b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"0f5b50bc048d4ce3b94e62537ac3d47fe58cd5a7c62bc5e30ff6d4c46276f876\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7363, \"end_char_idx\": 10399, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "ref_doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "chroma:document": "The tool helpfully suggests a few improvements to the dataset and splits the dataset into training and validation set.\n\nA suffix between a prompt and a completion is necessary to tell the model that the input text has stopped, and that it now needs to predict the class. Since we use the same separator in each example, the model is able to learn that it is meant to predict either baseball or hockey following the separator.\nA whitespace prefix in completions is useful, as most word tokens are tokenized with a space prefix.\nThe tool also recognized that this is likely a classification task, so it suggested to split the dataset into training and validation datasets. This will allow us to easily measure expected performance on new data.\n\n## Fine-tuning\nThe tool suggests we run the following command to train the dataset. Since this is a classification task, we would like to know what the generalization performance on the provided validation set is for our classification use case.\n\nWe can simply copy the suggested command from the CLI tool. We specifically add `-m ada` to fine-tune a cheaper and faster ada model, which is usually comperable in performance to slower and more expensive models on classification use cases. \n\n\n```python\ntrain_file = client.files.create(file=open(\"sport2_prepared_train.jsonl\", \"rb\"), purpose=\"fine-tune\")\nvalid_file = client.files.create(file=open(\"sport2_prepared_valid.jsonl\", \"rb\"), purpose=\"fine-tune\")\n\nfine_tuning_job = client.fine_tuning.jobs.create(training_file=train_file.id, validation_file=valid_file.id, model=\"babbage-002\")\n\nprint(fine_tuning_job)\n```\n\n    FineTuningJob(id='ftjob-REo0uLpriEAm08CBRNDlPJZC', created_at=1704413736, error=None, fine_tuned_model=None, finished_at=None, hyperparameters=Hyperparameters(n_epochs='auto', batch_size='auto', learning_rate_multiplier='auto'), model='babbage-002', object='fine_tuning.job', organization_id='org-9HXYFy8ux4r6aboFyec2OLRf', result_files=[], status='validating_files', trained_tokens=None, training_file='file-82XooA2AUDBAUbN5z2DuKRMs', validation_file='file-wTOcQF8vxQ0Z6fNY2GSm0z4P')\n\n\nThe model is successfully trained in about ten minutes. You can watch the finetune happen on [https://platform.openai.com/finetune/](https://platform.openai.com/finetune/)\n\nYou can also check on its status programatically:\n\n\n```python\nfine_tune_results = client.fine_tuning.jobs.retrieve(fine_tuning_job.id)\nprint(fine_tune_results.finished_at)\n```\n\n    1704414393\n\n\n### [Advanced] Results and expected model performance\nWe can now download the results file to observe the expected performance on a held out validation set.\n\n\n```python\nfine_tune_results = client.fine_tuning.jobs.retrieve(fine_tuning_job.id).result_files\nresult_file = client.files.retrieve(fine_tune_results[0])\ncontent = client.files.content(result_file.id)\n# save content to file\nwith open(\"result.csv\", \"wb\") as f:\n    f.write(content.text.encode(\"utf-8\"))\n```\n\n\n```python\nresults = pd.read_csv('result.csv')\nresults[results['train_accuracy'].notnull()].tail(1)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 6865179e-a5d1-4417-a610-0576e3b47e8b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb", "title": "Fine tuning classification example", "tokens": 3848, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6865179e-a5d1-4417-a610-0576e3b47e8b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"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\": \"2a529fbb-af14-46a4-bb64-86ced52106f9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba4e67ea68b645ec93fe770b4d7ccfa221ec7add0c2a439f442571930ab51f9b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"e46607e8-41c1-4555-80e9-eeea197f9db9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7091c3e25f4f6c0e718a2401c8b1b2848127a60ee5694a5056ea276c2525cbdf\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"527dea47-9d62-413d-bc0d-de5038c67f83\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a11a4f4c3079fd66d0e932ca3850d9541077479f5ba9ae281056ed74777849f8\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9463, \"end_char_idx\": 11451, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "ref_doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "chroma:document": "The model is successfully trained in about ten minutes. You can watch the finetune happen on [https://platform.openai.com/finetune/](https://platform.openai.com/finetune/)\n\nYou can also check on its status programatically:\n\n\n```python\nfine_tune_results = client.fine_tuning.jobs.retrieve(fine_tuning_job.id)\nprint(fine_tune_results.finished_at)\n```\n\n    1704414393\n\n\n### [Advanced] Results and expected model performance\nWe can now download the results file to observe the expected performance on a held out validation set.\n\n\n```python\nfine_tune_results = client.fine_tuning.jobs.retrieve(fine_tuning_job.id).result_files\nresult_file = client.files.retrieve(fine_tune_results[0])\ncontent = client.files.content(result_file.id)\n# save content to file\nwith open(\"result.csv\", \"wb\") as f:\n    f.write(content.text.encode(\"utf-8\"))\n```\n\n\n```python\nresults = pd.read_csv('result.csv')\nresults[results['train_accuracy'].notnull()].tail(1)\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>step</th>\n      <th>train_loss</th>\n      <th>train_accuracy</th>\n      <th>valid_loss</th>\n      <th>valid_mean_token_accuracy</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2843</th>\n      <td>2844</td>\n      <td>0.0</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\nThe accuracy reaches 99.6%. On the plot below we can see how accuracy on the validation set increases during the training run. \n\n\n```python\nresults[results['train_accuracy'].notnull()]['train_accuracy'].plot()\n```\n\n## Using the model\nWe can now call the model to get the predictions.\n\n\n```python\ntest = pd.read_json('sport2_prepared_valid.jsonl', lines=True)\ntest.head()\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 527dea47-9d62-413d-bc0d-de5038c67f83
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb", "title": "Fine tuning classification example", "tokens": 3848, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"527dea47-9d62-413d-bc0d-de5038c67f83\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"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\": \"2a529fbb-af14-46a4-bb64-86ced52106f9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba4e67ea68b645ec93fe770b4d7ccfa221ec7add0c2a439f442571930ab51f9b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"6865179e-a5d1-4417-a610-0576e3b47e8b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2e86149c4d24752481fc8fe21903146cfe0b46ff496606647776f25c6bb2d2fa\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"04bb1f5d-ab6a-4e60-b6c0-9b450e18dd61\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"391b23d57b7bd8beee64c415e326421082260cd52f28cc4176b314032c3d5302\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10297, \"end_char_idx\": 12816, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "ref_doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "chroma:document": "```python\nresults = pd.read_csv('result.csv')\nresults[results['train_accuracy'].notnull()].tail(1)\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>step</th>\n      <th>train_loss</th>\n      <th>train_accuracy</th>\n      <th>valid_loss</th>\n      <th>valid_mean_token_accuracy</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2843</th>\n      <td>2844</td>\n      <td>0.0</td>\n      <td>1.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\nThe accuracy reaches 99.6%. On the plot below we can see how accuracy on the validation set increases during the training run. \n\n\n```python\nresults[results['train_accuracy'].notnull()]['train_accuracy'].plot()\n```\n\n## Using the model\nWe can now call the model to get the predictions.\n\n\n```python\ntest = pd.read_json('sport2_prepared_valid.jsonl', lines=True)\ntest.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>prompt</th>\n      <th>completion</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>From: gld@cunixb.cc.columbia.edu (Gary L Dare)...</td>\n      <td>hockey</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>From: smorris@venus.lerc.nasa.gov (Ron Morris ...</td>\n      <td>hockey</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>From: golchowy@alchemy.chem.utoronto.ca (Geral...</td>\n      <td>hockey</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>From: krattige@hpcc01.corp.hp.com (Kim Krattig...</td>\n      <td>baseball</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>From: warped@cs.montana.edu (Doug Dolven)\\nSub...</td>\n      <td>baseball</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\nWe need to use the same separator following the prompt which we used during fine-tuning. In this case it is `\\n\\n###\\n\\n`. Since we're concerned with classification, we want the temperature to be as low as possible, and we only require one token completion to determine the prediction of the model."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 04bb1f5d-ab6a-4e60-b6c0-9b450e18dd61
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb", "title": "Fine tuning classification example", "tokens": 3848, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"04bb1f5d-ab6a-4e60-b6c0-9b450e18dd61\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"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\": \"2a529fbb-af14-46a4-bb64-86ced52106f9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ba4e67ea68b645ec93fe770b4d7ccfa221ec7add0c2a439f442571930ab51f9b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"527dea47-9d62-413d-bc0d-de5038c67f83\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb\", \"title\": \"Fine tuning classification example\", \"tokens\": 3848, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a19df5199e92a644ebcf37b227404bed16d19e754d967212cd5f6786684ab814\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 12518, \"end_char_idx\": 14628, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "ref_doc_id": "2a529fbb-af14-46a4-bb64-86ced52106f9", "chroma:document": "We need to use the same separator following the prompt which we used during fine-tuning. In this case it is `\\n\\n###\\n\\n`. Since we're concerned with classification, we want the temperature to be as low as possible, and we only require one token completion to determine the prediction of the model.\n\n\n```python\nft_model = fine_tune_results.fine_tuned_model\n\n# note that this calls the legacy completions api - https://platform.openai.com/docs/api-reference/completions\nres = client.completions.create(model=ft_model, prompt=test['prompt'][0] + '\\n\\n###\\n\\n', max_tokens=1, temperature=0)\nres.choices[0].text\n\n```\n\n\n\n\n    ' hockey'\n\n\n\nTo get the log probabilities, we can specify logprobs parameter on the completion request\n\n\n```python\nres = client.completions.create(model=ft_model, prompt=test['prompt'][0] + '\\n\\n###\\n\\n', max_tokens=1, temperature=0, logprobs=2)\nres.choices[0].logprobs.top_logprobs\n```\n\n\n\n\n    [{' hockey': 0.0, ' Hockey': -22.504879}]\n\n\n\nWe can see that the model predicts hockey as a lot more likely than baseball, which is the correct prediction. By requesting log_probs, we can see the prediction (log) probability for each class.\n\n### Generalization\nInterestingly, our fine-tuned classifier is quite versatile. Despite being trained on emails to different mailing lists, it also successfully predicts tweets.\n\n\n```python\nsample_hockey_tweet = \"\"\"Thank you to the \n@Canes\n and all you amazing Caniacs that have been so supportive! You guys are some of the best fans in the NHL without a doubt! Really excited to start this new chapter in my career with the \n@DetroitRedWings\n !!\"\"\"\nres = client.completions.create(model=ft_model, prompt=sample_hockey_tweet + '\\n\\n###\\n\\n', max_tokens=1, temperature=0, logprobs=2)\nres.choices[0].text\n```\n\n\n\n\n    ' hockey'\n\n\n\n\n```python\nsample_baseball_tweet=\"\"\"BREAKING: The Tampa Bay Rays are finalizing a deal to acquire slugger Nelson Cruz from the Minnesota Twins, sources tell ESPN.\"\"\"\nres = client.completions.create(model=ft_model, prompt=sample_baseball_tweet + '\\n\\n###\\n\\n', max_tokens=1, temperature=0, logprobs=2)\nres.choices[0].text\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0a32e1d9-211e-4648-85b7-dc57ab90a558
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Zero-shot_classification_with_embeddings.ipynb", "title": "convert 5-star rating to binary sentiment", "tokens": 1100, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0a32e1d9-211e-4648-85b7-dc57ab90a558\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Zero-shot_classification_with_embeddings.ipynb\", \"title\": \"convert 5-star rating to binary sentiment\", \"tokens\": 1100, \"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\": \"dae4250e-a75d-4397-9572-0b23294fb82e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Zero-shot_classification_with_embeddings.ipynb\", \"title\": \"convert 5-star rating to binary sentiment\", \"tokens\": 1100, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8c7751a56222acbe419c31314988a6508627bdf20d976b155f22099978d997b9\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"3dcbb21c-8c59-4949-b78f-b12e39ea4648\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f63bde134c6ccb69a8a48f40a60e1b7740e1ec19f131765c75ec0de4ed998dce\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3402, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dae4250e-a75d-4397-9572-0b23294fb82e", "doc_id": "dae4250e-a75d-4397-9572-0b23294fb82e", "ref_doc_id": "dae4250e-a75d-4397-9572-0b23294fb82e", "chroma:document": "## Zero-shot classification with embeddings\n\nIn this notebook we will classify the sentiment of reviews using embeddings and zero labeled data! The dataset is created in the [Get_embeddings_from_dataset Notebook](Get_embeddings_from_dataset.ipynb).\n\nWe'll define positive sentiment to be 4- and 5-star reviews, and negative sentiment to be 1- and 2-star reviews. 3-star reviews are considered neutral and we won't use them for this example.\n\nWe will perform zero-shot classification by embedding descriptions of each class and then comparing new samples to those class embeddings.\n\n\n```python\nimport pandas as pd\nimport numpy as np\nfrom ast import literal_eval\n\nfrom sklearn.metrics import classification_report\n\nEMBEDDING_MODEL = \"text-embedding-3-small\"\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\n# convert 5-star rating to binary sentiment\ndf = df[df.Score != 3]\ndf[\"sentiment\"] = df.Score.replace({1: \"negative\", 2: \"negative\", 4: \"positive\", 5: \"positive\"})\n\n```\n\n### Zero-Shot Classification\nTo perform zero shot classification, we want to predict labels for our samples without any training. To do this, we can simply embed short descriptions of each label, such as positive and negative, and then compare the cosine distance between embeddings of samples and label descriptions. \n\nThe highest similarity label to the sample input is the predicted label. We can also define a prediction score to be the difference between the cosine distance to the positive and to the negative label. This score can be used for plotting a precision-recall curve, which can be used to select a different tradeoff between precision and recall, by selecting a different threshold.\n\n\n```python\nfrom utils.embeddings_utils import cosine_similarity, get_embedding\nfrom sklearn.metrics import PrecisionRecallDisplay\n\ndef evaluate_embeddings_approach(\n    labels = ['negative', 'positive'],\n    model = EMBEDDING_MODEL,\n):\n    label_embeddings = [get_embedding(label, model=model) for label in labels]\n\n    def label_score(review_embedding, label_embeddings):\n        return cosine_similarity(review_embedding, label_embeddings[1]) - cosine_similarity(review_embedding, label_embeddings[0])\n\n    probas = df[\"embedding\"].apply(lambda x: label_score(x, label_embeddings))\n    preds = probas.apply(lambda x: 'positive' if x>0 else 'negative')\n\n    report = classification_report(df.sentiment, preds)\n    print(report)\n\n    display = PrecisionRecallDisplay.from_predictions(df.sentiment, probas, pos_label='positive')\n    _ = display.ax_.set_title(\"2-class Precision-Recall curve\")\n\nevaluate_embeddings_approach(labels=['negative', 'positive'], model=EMBEDDING_MODEL)\n\n```\n\n                  precision    recall  f1-score   support\n    \n        negative       0.54      0.92      0.68       136\n        positive       0.98      0.87      0.92       789\n    \n        accuracy                           0.87       925\n       macro avg       0.76      0.89      0.80       925\n    weighted avg       0.92      0.87      0.89       925\n    \n\n\n\n    \n![png](output_3_1.png)\n    \n\n\nWe can see that this classifier already performs extremely well. We used similarity embeddings, and the simplest possible label name. Let's try to improve on this by using more descriptive label names, and search embeddings."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 3dcbb21c-8c59-4949-b78f-b12e39ea4648
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Zero-shot_classification_with_embeddings.ipynb", "title": "convert 5-star rating to binary sentiment", "tokens": 1100, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3dcbb21c-8c59-4949-b78f-b12e39ea4648\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Zero-shot_classification_with_embeddings.ipynb\", \"title\": \"convert 5-star rating to binary sentiment\", \"tokens\": 1100, \"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\": \"dae4250e-a75d-4397-9572-0b23294fb82e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Zero-shot_classification_with_embeddings.ipynb\", \"title\": \"convert 5-star rating to binary sentiment\", \"tokens\": 1100, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8c7751a56222acbe419c31314988a6508627bdf20d976b155f22099978d997b9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0a32e1d9-211e-4648-85b7-dc57ab90a558\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Zero-shot_classification_with_embeddings.ipynb\", \"title\": \"convert 5-star rating to binary sentiment\", \"tokens\": 1100, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ec97be1b3f6e7a2345b3ebbbed2cbd3f9be6f567e25e52e14ff542f6bbf8efe8\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1794, \"end_char_idx\": 4761, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dae4250e-a75d-4397-9572-0b23294fb82e", "doc_id": "dae4250e-a75d-4397-9572-0b23294fb82e", "ref_doc_id": "dae4250e-a75d-4397-9572-0b23294fb82e", "chroma:document": "```python\nfrom utils.embeddings_utils import cosine_similarity, get_embedding\nfrom sklearn.metrics import PrecisionRecallDisplay\n\ndef evaluate_embeddings_approach(\n    labels = ['negative', 'positive'],\n    model = EMBEDDING_MODEL,\n):\n    label_embeddings = [get_embedding(label, model=model) for label in labels]\n\n    def label_score(review_embedding, label_embeddings):\n        return cosine_similarity(review_embedding, label_embeddings[1]) - cosine_similarity(review_embedding, label_embeddings[0])\n\n    probas = df[\"embedding\"].apply(lambda x: label_score(x, label_embeddings))\n    preds = probas.apply(lambda x: 'positive' if x>0 else 'negative')\n\n    report = classification_report(df.sentiment, preds)\n    print(report)\n\n    display = PrecisionRecallDisplay.from_predictions(df.sentiment, probas, pos_label='positive')\n    _ = display.ax_.set_title(\"2-class Precision-Recall curve\")\n\nevaluate_embeddings_approach(labels=['negative', 'positive'], model=EMBEDDING_MODEL)\n\n```\n\n                  precision    recall  f1-score   support\n    \n        negative       0.54      0.92      0.68       136\n        positive       0.98      0.87      0.92       789\n    \n        accuracy                           0.87       925\n       macro avg       0.76      0.89      0.80       925\n    weighted avg       0.92      0.87      0.89       925\n    \n\n\n\n    \n![png](output_3_1.png)\n    \n\n\nWe can see that this classifier already performs extremely well. We used similarity embeddings, and the simplest possible label name. Let's try to improve on this by using more descriptive label names, and search embeddings.\n\n\n```python\nevaluate_embeddings_approach(labels=['An Amazon review with a negative sentiment.', 'An Amazon review with a positive sentiment.'])\n\n```\n\n                  precision    recall  f1-score   support\n    \n        negative       0.76      0.96      0.85       136\n        positive       0.99      0.95      0.97       789\n    \n        accuracy                           0.95       925\n       macro avg       0.88      0.96      0.91       925\n    weighted avg       0.96      0.95      0.95       925\n    \n\n\n\n    \n![png](output_5_1.png)\n    \n\n\nUsing the search embeddings and descriptive names leads to an additional improvement in performance.\n\n\n```python\nevaluate_embeddings_approach(labels=['An Amazon review with a negative sentiment.', 'An Amazon review with a positive sentiment.'])\n\n```\n\n                  precision    recall  f1-score   support\n    \n        negative       0.76      0.96      0.85       136\n        positive       0.99      0.95      0.97       789\n    \n        accuracy                           0.95       925\n       macro avg       0.88      0.96      0.91       925\n    weighted avg       0.96      0.95      0.95       925\n    \n\n\n\n    \n![png](output_7_1.png)\n    \n\n\nAs shown above, zero-shot classification with embeddings can lead to great results, especially when the labels are more descriptive than just simple words."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: f93ef151-0cde-4ecd-807a-f70f12a17446
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb", "title": "Function calling for nearby places: Leveraging the Google Places API and customer profiles", "tokens": 3051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"f93ef151-0cde-4ecd-807a-f70f12a17446\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"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\": \"83dabff9-b623-4979-82e6-ef29a1aec8e5\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae144e3e2e57460a535be1bf281347c7489ba13f41dc118da7554305a299cf35\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"00907c95-e0b2-4727-b5bc-0b73e3c26ebc\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"bea9ed1ddf87d57e70d5b8fd7adb7e8b73d56224a723751484ad8cd4409cb998\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3298, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "ref_doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "chroma:document": "# Function calling for nearby places: Leveraging the Google Places API and customer profiles\n\nThis notebook is centered around the integration of the Google Places API and custom user profiles to enhance location-based searches. Our approach involves using the Google Places API in combination with user preferences, aiming to make location discovery more personal and relevant. Please note that while we focus on the Google Places API in this instance, there are numerous other APIs you could explore and apply in a similar fashion.\n\nWe'll explore the application of three main components:\n\n- Customer profile: This mock profile captures individual preferences for types of places (e.g., restaurants, parks, museums), budget, preferred ratings, and other specific requirements. \n\n- Google Places API: This API provides real-time data about nearby places. It factors in various data points such as ratings, types of venues, costs, and more from the locations around you.\n\n- Function calling: A single command such as \"I'm hungry\" or \"I want to visit a museum\" activates the function which combines the user profile data and Google Places API to identify suitable venues.\n\nThis notebook introduces two primary use cases:\n\n- Profile-based recommendations: Learn how to create a user profile and make place recommendations based on individual preferences.\n\n- API integration with function calling: Understand how to integrate and call Google Places API effectively to source real-time data of various places using function calling.\n\nPlease note that while this system is highly versatile, its effectiveness may vary based on user preferences and available place data. For the purposes of this notebook, the customer data is fake and the location is hardcoded. \n\n## Setup\n\nGoogle Places API\n\nTo use the Google Places API, you'll need two things:\n\n- Google Account: If you don't already have one, you will need to create a Google account.\n\n- Google Places API Key: The API key is a unique identifier that is used to authenticate requests associated with your project for usage and billing purposes. You can get your API key from the [Google Cloud Console](https://console.cloud.google.com/getting-started?authuser=1). \n\n\n\nPlease note that Google Places API is a paid service, and the cost is associated with the number of API calls made. Keep track of your usage to avoid any unexpected charges.\n\n\n\nThe requests library is also needed, you can download it by using the following command: \n\n```python\npip install requests\n\n\n```python\nimport json\nfrom openai import OpenAI\nimport os\nimport requests\n\nclient = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as env var>\"))\n```\n\nIn this code snippet, we are defining a function `fetch_customer_profile` that accepts a `user_id` and returns a mock user profile.\n\nThis function simulates an API call that fetches user data from a database. For this demo, we're using hard-coded data. The user profile contains various details such as the user's location (set to the coordinates of the Golden Gate Bridge for this example), preferences in food and activities, app usage metrics, recent interactions, and user rank.\n\nIn a production environment, you would replace this hard-coded data with a real API call to your user database."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 00907c95-e0b2-4727-b5bc-0b73e3c26ebc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb", "title": "Function calling for nearby places: Leveraging the Google Places API and customer profiles", "tokens": 3051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"00907c95-e0b2-4727-b5bc-0b73e3c26ebc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"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\": \"83dabff9-b623-4979-82e6-ef29a1aec8e5\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae144e3e2e57460a535be1bf281347c7489ba13f41dc118da7554305a299cf35\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"f93ef151-0cde-4ecd-807a-f70f12a17446\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"68b73559efc71fff382909a8fa9363c0139e031c4e75f4541af62dcd513baa50\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"fabc87f1-2959-499a-b971-abe4610d4720\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4206d179f50d496b05cd0ba193a03ec5c8afdff2f7ac7d64d550c45ca96f8ac0\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2217, \"end_char_idx\": 5838, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "ref_doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "chroma:document": "Please note that Google Places API is a paid service, and the cost is associated with the number of API calls made. Keep track of your usage to avoid any unexpected charges.\n\n\n\nThe requests library is also needed, you can download it by using the following command: \n\n```python\npip install requests\n\n\n```python\nimport json\nfrom openai import OpenAI\nimport os\nimport requests\n\nclient = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as env var>\"))\n```\n\nIn this code snippet, we are defining a function `fetch_customer_profile` that accepts a `user_id` and returns a mock user profile.\n\nThis function simulates an API call that fetches user data from a database. For this demo, we're using hard-coded data. The user profile contains various details such as the user's location (set to the coordinates of the Golden Gate Bridge for this example), preferences in food and activities, app usage metrics, recent interactions, and user rank.\n\nIn a production environment, you would replace this hard-coded data with a real API call to your user database.\n\n\n\n```python\ndef fetch_customer_profile(user_id):\n    # You can replace this with a real API call in the production code\n    if user_id == \"user1234\":\n        return {\n            \"name\": \"John Doe\",\n            \"location\": {\n                \"latitude\": 37.7955,\n                \"longitude\": -122.4026,\n            },\n            \"preferences\": {\n                \"food\": [\"Italian\", \"Sushi\"],\n                \"activities\": [\"Hiking\", \"Reading\"],\n            },\n            \"behavioral_metrics\": {\n                \"app_usage\": {\n                    \"daily\": 2,  # hours\n                    \"weekly\": 14  # hours\n                },\n                \"favourite_post_categories\": [\"Nature\", \"Food\", \"Books\"],\n                \"active_time\": \"Evening\",\n            },\n            \"recent_searches\": [\"Italian restaurants nearby\", \"Book clubs\"],\n            \"recent_interactions\": [\"Liked a post about 'Best Pizzas in New York'\", \"Commented on a post about 'Central Park Trails'\"],\n            \"user_rank\": \"Gold\",  # based on some internal ranking system\n        }\n    else:\n        return None\n\n```\n\n## Requesting and processing data from Google Places API\n\nThe function call_google_places_api serves to request information from the Google Places API and provide a list of the top two places based on a given place_type and optional food_preference. We've limited this function to the top two results to manage usage since this is a paid service. However, you can modify this to retrieve any number of results as per your requirement.\n\nThe function is configured with a hardcoded location (set to the coordinates of the Transamerica Pyramid), your Google API key, and specific request parameters. Depending on the place_type, it formulates the appropriate API request URL. If the place_type is a restaurant and a food_preference is specified, it is included in the API request.\n\nAfter sending the GET request, the function checks the response status. If it's successful, it processes the JSON response, extracts the relevant details using the get_place_details function, and returns them in a human-readable format. If the request fails, it prints out the error for debugging.\n\nThe get_place_details function is used to retrieve more detailed information about a place, given its place_id. It sends a GET request to the Google Place Details API and returns the result if the request is successful. If the request fails, it prints out the error for debugging.\n\nBoth functions handle exceptions and return an error message if something goes wrong."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: fabc87f1-2959-499a-b971-abe4610d4720
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb", "title": "Function calling for nearby places: Leveraging the Google Places API and customer profiles", "tokens": 3051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"fabc87f1-2959-499a-b971-abe4610d4720\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"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\": \"83dabff9-b623-4979-82e6-ef29a1aec8e5\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae144e3e2e57460a535be1bf281347c7489ba13f41dc118da7554305a299cf35\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"00907c95-e0b2-4727-b5bc-0b73e3c26ebc\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"bbf9b65cb2c334bea8b19255d272bedc0cc994ebae50e062bd92d08f2d69e0a3\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"b8db6af3-dea6-4761-a810-43db07243551\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"160df5a76f123e402041069ca73dfcd0cf47588b2631860c0a3ef77e7bf98fad\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5842, \"end_char_idx\": 8960, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "ref_doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "chroma:document": "```python\ndef get_place_details(place_id, api_key):\n    URL = f\"https://maps.googleapis.com/maps/api/place/details/json?place_id={place_id}&key={api_key}\"\n    response = requests.get(URL)\n    if response.status_code == 200:\n        result = json.loads(response.content)[\"result\"]\n        return result\n    else:\n        print(f\"Google Place Details API request failed with status code {response.status_code}\")\n        print(f\"Response content: {response.content}\")\n        return None\n\n```\n\n\n```python\ndef call_google_places_api(user_id, place_type, food_preference=None):\n    try:\n        # Fetch customer profile\n        customer_profile = fetch_customer_profile(user_id)\n        if customer_profile is None:\n            return \"I couldn't find your profile. Could you please verify your user ID?\"\n\n        # Get location from customer profile\n        lat = customer_profile[\"location\"][\"latitude\"]\n        lng = customer_profile[\"location\"][\"longitude\"]\n\n        API_KEY = os.getenv('GOOGLE_PLACES_API_KEY')  # retrieve API key from environment variable\n        LOCATION = f\"{lat},{lng}\"\n        RADIUS = 500  # search within a radius of 500 meters\n        TYPE = place_type\n\n        # If the place_type is restaurant and food_preference is not None, include it in the API request\n        if place_type == 'restaurant' and food_preference:\n            URL = f\"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={LOCATION}&radius={RADIUS}&type={TYPE}&keyword={food_preference}&key={API_KEY}\"\n        else:\n            URL = f\"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={LOCATION}&radius={RADIUS}&type={TYPE}&key={API_KEY}\"\n\n        response = requests.get(URL)\n        if response.status_code == 200:\n            results = json.loads(response.content)[\"results\"]\n            places = []\n            for place in results[:2]:  # limit to top 2 results\n                place_id = place.get(\"place_id\")\n                place_details = get_place_details(place_id, API_KEY)  # Get the details of the place\n\n                place_name = place_details.get(\"name\", \"N/A\")\n                place_types = next((t for t in place_details.get(\"types\", []) if t not in [\"food\", \"point_of_interest\"]), \"N/A\")  # Get the first type of the place, excluding \"food\" and \"point_of_interest\"\n                place_rating = place_details.get(\"rating\", \"N/A\")  # Get the rating of the place\n                total_ratings = place_details.get(\"user_ratings_total\", \"N/A\")  # Get the total number of ratings\n                place_address = place_details.get(\"vicinity\", \"N/A\")  # Get the vicinity of the place\n\n                if ',' in place_address:  # If the address contains a comma\n                    street_address = place_address.split(',')[0]  # Split by comma and keep only the first part\n                else:\n                    street_address = place_address\n\n                # Prepare the output string for this place\n                place_info = f\"{place_name} is a {place_types} located at {street_address}. It has a rating of {place_rating} based on {total_ratings} user reviews.\""}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: b8db6af3-dea6-4761-a810-43db07243551
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb", "title": "Function calling for nearby places: Leveraging the Google Places API and customer profiles", "tokens": 3051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b8db6af3-dea6-4761-a810-43db07243551\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"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\": \"83dabff9-b623-4979-82e6-ef29a1aec8e5\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae144e3e2e57460a535be1bf281347c7489ba13f41dc118da7554305a299cf35\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"fabc87f1-2959-499a-b971-abe4610d4720\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"53d44e03dcc1c84ad4d208fb1daece51853f870f8ec93d66bc7f7f1a238e9749\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"38e9ca4a-e1b7-4ba5-83ac-60e727b3cff8\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"2e77f5432fdc227d1171ed7416c78e39fdee1a5138525b779e7c5cc4f94ac18d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8887, \"end_char_idx\": 10962, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "ref_doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "chroma:document": "It has a rating of {place_rating} based on {total_ratings} user reviews.\"\n\n                places.append(place_info)\n\n            return places\n        else:\n            print(f\"Google Places API request failed with status code {response.status_code}\")\n            print(f\"Response content: {response.content}\")  # print out the response content for debugging\n            return []\n    except Exception as e:\n        print(f\"Error during the Google Places API call: {e}\")\n        return []\n\n```\n\n## Generating user-specific recommendations with GPT-3.5-Turbo and Google Places API\n\nThe function `provide_user_specific_recommendations` interacts with GPT-3.5-Turbo and the Google Places API to provide responses tailored to a user's preferences and location.\n\nFirst, it fetches the customer's profile using their `user_id`. If no profile is found, it returns an error message.\n\nWith a valid profile, it extracts the customer's food preferences and then interacts with the OpenAI model. It provides an initial system message, giving context to the AI model about its role, user preferences, and the usage of the Google Places API function.\n\nThe user input is also sent to the model as a message, and the function `call_google_places_api` is defined in the `functions` parameter for the AI model to call as needed.\n\nFinally, it processes the model's response. If the model makes a function call to the Google Places API, the function is executed with the appropriate arguments, and the names of nearby places are returned. If there are no such places or the request isn't understood, appropriate error messages are returned.\n\n\n\n```python\ndef provide_user_specific_recommendations(user_input, user_id):\n    customer_profile = fetch_customer_profile(user_id)\n    if customer_profile is None:\n        return \"I couldn't find your profile. Could you please verify your user ID?\"\n\n    customer_profile_str = json.dumps(customer_profile)\n\n    food_preference = customer_profile.get('preferences', {}).get('food', [])[0] if customer_profile.get('preferences', {}).get('food') else None"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 38e9ca4a-e1b7-4ba5-83ac-60e727b3cff8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb", "title": "Function calling for nearby places: Leveraging the Google Places API and customer profiles", "tokens": 3051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"38e9ca4a-e1b7-4ba5-83ac-60e727b3cff8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"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\": \"83dabff9-b623-4979-82e6-ef29a1aec8e5\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae144e3e2e57460a535be1bf281347c7489ba13f41dc118da7554305a299cf35\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b8db6af3-dea6-4761-a810-43db07243551\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6331a5d24aa54b5764619c444db9926655403d17173fd4a4a6ca050778f38540\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"4cc791fa-34c5-4e56-95bb-9f012b6efbfc\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8020961bdbe50a065e95d60ec2e433250468fad0dcb436760ea84145f2c98674\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9646, \"end_char_idx\": 13868, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "ref_doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "chroma:document": "First, it fetches the customer's profile using their `user_id`. If no profile is found, it returns an error message.\n\nWith a valid profile, it extracts the customer's food preferences and then interacts with the OpenAI model. It provides an initial system message, giving context to the AI model about its role, user preferences, and the usage of the Google Places API function.\n\nThe user input is also sent to the model as a message, and the function `call_google_places_api` is defined in the `functions` parameter for the AI model to call as needed.\n\nFinally, it processes the model's response. If the model makes a function call to the Google Places API, the function is executed with the appropriate arguments, and the names of nearby places are returned. If there are no such places or the request isn't understood, appropriate error messages are returned.\n\n\n\n```python\ndef provide_user_specific_recommendations(user_input, user_id):\n    customer_profile = fetch_customer_profile(user_id)\n    if customer_profile is None:\n        return \"I couldn't find your profile. Could you please verify your user ID?\"\n\n    customer_profile_str = json.dumps(customer_profile)\n\n    food_preference = customer_profile.get('preferences', {}).get('food', [])[0] if customer_profile.get('preferences', {}).get('food') else None\n\n\n    response = client.chat.completions.create(\n        model=\"gpt-3.5-turbo\",\n        messages=[\n    {\n        \"role\": \"system\",\n        \"content\": f\"You are a sophisticated AI assistant, a specialist in user intent detection and interpretation. Your task is to perceive and respond to the user's needs, even when they're expressed in an indirect or direct manner. You excel in recognizing subtle cues: for example, if a user states they are 'hungry', you should assume they are seeking nearby dining options such as a restaurant or a cafe. If they indicate feeling 'tired', 'weary', or mention a long journey, interpret this as a request for accommodation options like hotels or guest houses. However, remember to navigate the fine line of interpretation and assumption: if a user's intent is unclear or can be interpreted in multiple ways, do not hesitate to politely ask for additional clarification. Make sure to tailor your responses to the user based on their preferences and past experiences which can be found here {customer_profile_str}\"\n    },\n    {\"role\": \"user\", \"content\": user_input}\n],\n        temperature=0,\n        tools=[\n            {\n                \"type\": \"function\",\n                \"function\" : {\n                    \"name\": \"call_google_places_api\",\n                    \"description\": \"This function calls the Google Places API to find the top places of a specified type near a specific location. It can be used when a user expresses a need (e.g., feeling hungry or tired) or wants to find a certain type of place (e.g., restaurant or hotel).\",\n                    \"parameters\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                            \"place_type\": {\n                                \"type\": \"string\",\n                                \"description\": \"The type of place to search for.\"\n                            }\n                        }\n                    },\n                    \"result\": {\n                        \"type\": \"array\",\n                        \"items\": {\n                            \"type\": \"string\"\n                        }\n                    }\n                }\n            }\n        ],\n    )\n\n    print(response.choices[0].message.tool_calls)\n\n    if response.choices[0].finish_reason=='tool_calls':\n        function_call = response.choices[0].message.tool_calls[0].function\n        if function_call.name == \"call_google_places_api\":\n            place_type = json.loads(function_call.arguments)[\"place_type\"]\n            places = call_google_places_api(user_id, place_type, food_preference)\n            if places:  # If the list of places is not empty\n                return f\"Here are some places you might be interested in: {' '.join(places)}\"\n            else:\n                return \"I couldn't find any places of interest nearby.\"\n\n    return \"I am sorry, but I could not understand your request.\""}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 4cc791fa-34c5-4e56-95bb-9f012b6efbfc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb", "title": "Function calling for nearby places: Leveraging the Google Places API and customer profiles", "tokens": 3051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4cc791fa-34c5-4e56-95bb-9f012b6efbfc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"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\": \"83dabff9-b623-4979-82e6-ef29a1aec8e5\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae144e3e2e57460a535be1bf281347c7489ba13f41dc118da7554305a299cf35\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"38e9ca4a-e1b7-4ba5-83ac-60e727b3cff8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Function_calling_finding_nearby_places.ipynb\", \"title\": \"Function calling for nearby places: Leveraging the Google Places API and customer profiles\", \"tokens\": 3051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a86ac5848624685063ce47ee6d5e2e4c7331e778d6f93774f34fc9612df62534\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 13871, \"end_char_idx\": 14870, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "ref_doc_id": "83dabff9-b623-4979-82e6-ef29a1aec8e5", "chroma:document": "```\n\n## Executing user-specific recommendations\n\nUpon execution, the function fetches the user's profile, interacts with the AI model, processes the model's response, calls the Google Places API if necessary, and ultimately returns a list of recommendations tailored to the user's preferences and location. The printed output would consist of these personalized recommendations.\n\n\n\n```python\nuser_id = \"user1234\"\nuser_input = \"I'm hungry\"\noutput = provide_user_specific_recommendations(user_input, user_id)\nprint(output)\n\n```\n\n    [ChatCompletionMessageToolCall(id='call_Q1mXIi7D6GhobfE4tkruX7nB', function=Function(arguments='{\\n  \"place_type\": \"restaurant\"\\n}', name='call_google_places_api'), type='function')]\n    Here are some places you might be interested in: Sotto Mare is a restaurant located at 552 Green Street. It has a rating of 4.6 based on 3765 user reviews. Mona Lisa Restaurant is a restaurant located at 353 Columbus Avenue #3907. It has a rating of 4.4 based on 1888 user reviews."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 18709d4f-a99a-4934-aa8f-98319f981704
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"18709d4f-a99a-4934-aa8f-98319f981704\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e9c3fe8b-0275-499d-afb0-583d92be3a3c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1a0fd541b0b3735b5aad881b2f8c784bf9b97664e71f42627aa4fa1d475152f6\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3533, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "# Whisper prompting guide\n\nOpenAI's audio transcription API has an optional parameter called `prompt`.\n\nThe prompt is intended to help stitch together multiple audio segments. By submitting the prior segment's transcript via the prompt, the Whisper model can use that context to better understand the speech and maintain a consistent writing style.\n\nHowever, prompts do not need to be genuine transcripts from prior audio segments. _Fictitious_ prompts can be submitted to steer the model to use particular spellings or styles.\n\nThis notebook shares two techniques for using fictitious prompts to steer the model outputs:\n\n- **Transcript generation**: GPT can convert instructions into fictitious transcripts for Whisper to emulate. \n- **Spelling guide**: A spelling guide can tell the model how to spell names of people, products, companies, etc.\n\nThese techniques are not especially reliable, but can be useful in some situations.\n\n## Comparison with GPT prompting\n\nPrompting Whisper is not the same as prompting GPT. For example, if you submit an attempted instruction like \"Format lists in Markdown format\", the model will not comply, as it follows the style of the prompt, rather than any instructions contained within.\n\nIn addition, the prompt is limited to only 224 tokens. If the prompt is longer than 224 tokens, only the final 224 tokens of the prompt will be considered; all prior tokens will be silently ignored. The tokenizer used is the [multilingual Whisper tokenizer](https://github.com/openai/whisper/blob/main/whisper/tokenizer.py#L361).\n\nTo get good results, craft examples that portray your desired style.\n\n## Setup\n\nTo get started, let's:\n- Import the OpenAI Python library (if you don't have it, you'll need to install it with `pip install openai`)\n- Download a few example audio files\n\n\n```python\n# imports\nfrom openai import OpenAI  # for making OpenAI API calls\nimport urllib  # for downloading example audio files\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\n\n```python\n# set download paths\nup_first_remote_filepath = \"https://cdn.openai.com/API/examples/data/upfirstpodcastchunkthree.wav\"\nbbq_plans_remote_filepath = \"https://cdn.openai.com/API/examples/data/bbq_plans.wav\"\nproduct_names_remote_filepath = \"https://cdn.openai.com/API/examples/data/product_names.wav\"\n\n# set local save locations\nup_first_filepath = \"data/upfirstpodcastchunkthree.wav\"\nbbq_plans_filepath = \"data/bbq_plans.wav\"\nproduct_names_filepath = \"data/product_names.wav\"\n\n# download example audio files and save locally\nurllib.request.urlretrieve(up_first_remote_filepath, up_first_filepath)\nurllib.request.urlretrieve(bbq_plans_remote_filepath, bbq_plans_filepath)\nurllib.request.urlretrieve(product_names_remote_filepath, product_names_filepath)\n\n```\n\n\n\n\n    ('data/product_names.wav', <http.client.HTTPMessage at 0x1105ac490>)\n\n\n\n## As a baseline, we'll transcribe an NPR podcast segment\n\nOur audio file for this example will be a segment of the NPR podcast, [_Up First_](https://www.npr.org/podcasts/510318/up-first). \n\nLet's get our baseline transcription, then introduce prompts. \n\n\n```python\n# define a wrapper function for seeing how prompts affect transcriptions\ndef transcribe(audio_filepath, prompt: str) -> 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```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: e9c3fe8b-0275-499d-afb0-583d92be3a3c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e9c3fe8b-0275-499d-afb0-583d92be3a3c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"18709d4f-a99a-4934-aa8f-98319f981704\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"91b4e24d4c29d9754e5aa359c3270c0ce01a186a9fca9c1ab7f5646aed80e6c2\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"241db625-db5f-49be-8e3d-2798479056e7\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"db46000f6222a005e9933d2b651195d3117f467c76567fcc3860d7b8296b365a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2062, \"end_char_idx\": 5044, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "```python\n# set download paths\nup_first_remote_filepath = \"https://cdn.openai.com/API/examples/data/upfirstpodcastchunkthree.wav\"\nbbq_plans_remote_filepath = \"https://cdn.openai.com/API/examples/data/bbq_plans.wav\"\nproduct_names_remote_filepath = \"https://cdn.openai.com/API/examples/data/product_names.wav\"\n\n# set local save locations\nup_first_filepath = \"data/upfirstpodcastchunkthree.wav\"\nbbq_plans_filepath = \"data/bbq_plans.wav\"\nproduct_names_filepath = \"data/product_names.wav\"\n\n# download example audio files and save locally\nurllib.request.urlretrieve(up_first_remote_filepath, up_first_filepath)\nurllib.request.urlretrieve(bbq_plans_remote_filepath, bbq_plans_filepath)\nurllib.request.urlretrieve(product_names_remote_filepath, product_names_filepath)\n\n```\n\n\n\n\n    ('data/product_names.wav', <http.client.HTTPMessage at 0x1105ac490>)\n\n\n\n## As a baseline, we'll transcribe an NPR podcast segment\n\nOur audio file for this example will be a segment of the NPR podcast, [_Up First_](https://www.npr.org/podcasts/510318/up-first). \n\nLet's get our baseline transcription, then introduce prompts. \n\n\n```python\n# define a wrapper function for seeing how prompts affect transcriptions\ndef transcribe(audio_filepath, prompt: str) -> 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(up_first_filepath, prompt=\"\")\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kind of pain in the butt every day to do that? No, it is. It is. And I sometimes just kind of miss the eye. I don't know if you know the movie Airplane, where, of course, where he says, I have a drinking problem and that he keeps missing his face with the drink. That's me and the contact lens. Surely, you must know that I know the movie Airplane. I do. I do know that. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend. So how much progress can they make? I'm E. Martinez with Steve Inskeep, and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\"\n\n\n\n## Transcripts follow the style of the prompt\n\nIn the unprompted transcript, 'President Biden' is capitalized. However, if we pass in a fictitious prompt of 'president biden' in lowercase, Whisper matches the style and generates a transcript in all lowercase.\n\n\n```python\n# lowercase prompt\ntranscribe(up_first_filepath, prompt=\"president biden\")\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 241db625-db5f-49be-8e3d-2798479056e7
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"241db625-db5f-49be-8e3d-2798479056e7\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"e9c3fe8b-0275-499d-afb0-583d92be3a3c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0b0fcaaf6e9d6a21d0f2de673b4d4a85b5604e295ca1db2ea9d7a89c1f3115e9\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2e65f20c-0ac9-439f-8a09-157ce31cb7f2\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8f236fbf81ffce49a518074ab9f0193acc9760c153e327a834a918db76ecbbf3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3536, \"end_char_idx\": 6326, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "```python\n# baseline transcription with no prompt\ntranscribe(up_first_filepath, prompt=\"\")\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kind of pain in the butt every day to do that? No, it is. It is. And I sometimes just kind of miss the eye. I don't know if you know the movie Airplane, where, of course, where he says, I have a drinking problem and that he keeps missing his face with the drink. That's me and the contact lens. Surely, you must know that I know the movie Airplane. I do. I do know that. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend. So how much progress can they make? I'm E. Martinez with Steve Inskeep, and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\"\n\n\n\n## Transcripts follow the style of the prompt\n\nIn the unprompted transcript, 'President Biden' is capitalized. However, if we pass in a fictitious prompt of 'president biden' in lowercase, Whisper matches the style and generates a transcript in all lowercase.\n\n\n```python\n# lowercase prompt\ntranscribe(up_first_filepath, prompt=\"president biden\")\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kind of pain in the butt every day to do that? No, it is. It is. And I sometimes just kind of miss the eye. I don't know if you know the movie Airplane? Yes. Of course. Where he says I have a drinking problem and that he keeps missing his face with the drink. That's me and the contact lens. Surely, you must know that I know the movie Airplane. I do. I do know that. Don't call me Shirley. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend. So how much progress can they make? I'm E. Martinez with Steve Inskeep and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\"\n\n\n\nBe aware that when prompts are short, Whisper may be less reliable at following their style.\n\n\n```python\n# short prompts are less reliable\ntranscribe(up_first_filepath, prompt=\"president biden.\")\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 2e65f20c-0ac9-439f-8a09-157ce31cb7f2
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2e65f20c-0ac9-439f-8a09-157ce31cb7f2\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"241db625-db5f-49be-8e3d-2798479056e7\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6f57ba47f131e38054d8a137eb4d549ce51a6a2fc4f9a9e5c1f5ca5968606eda\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c97a7f9a-9c80-48f0-98b2-83037ee28766\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f31e60e6482288f21aac9396e411cf2c096b115cbd0948ba5ae7e4d933292915\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4694, \"end_char_idx\": 7866, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "## Transcripts follow the style of the prompt\n\nIn the unprompted transcript, 'President Biden' is capitalized. However, if we pass in a fictitious prompt of 'president biden' in lowercase, Whisper matches the style and generates a transcript in all lowercase.\n\n\n```python\n# lowercase prompt\ntranscribe(up_first_filepath, prompt=\"president biden\")\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kind of pain in the butt every day to do that? No, it is. It is. And I sometimes just kind of miss the eye. I don't know if you know the movie Airplane? Yes. Of course. Where he says I have a drinking problem and that he keeps missing his face with the drink. That's me and the contact lens. Surely, you must know that I know the movie Airplane. I do. I do know that. Don't call me Shirley. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend. So how much progress can they make? I'm E. Martinez with Steve Inskeep and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\"\n\n\n\nBe aware that when prompts are short, Whisper may be less reliable at following their style.\n\n\n```python\n# short prompts are less reliable\ntranscribe(up_first_filepath, prompt=\"president biden.\")\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kind of pain in the butt every day to do that? No, it is. It is. And I sometimes just kind of miss the eye. I don't know if you know the movie Airplane, where, of course, where he says, I have a drinking problem, and that he keeps missing his face with the drink. That's me and the contact lens. Surely, you must know that I know the movie Airplane. I do. I do know that. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend. So how much progress can they make? I'm E. Martinez with Steve Inskeep, and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\"\n\n\n\nLong prompts may be more reliable at steering Whisper.\n\n\n```python\n# long prompts are more reliable\ntranscribe(up_first_filepath, prompt=\"i have some advice for you. multiple sentences help establish a pattern. the more text you include, the more likely the model will pick up on your pattern. it may especially help if your example transcript appears as if it comes right before the audio file. in this case, that could mean mentioning the contacts i stick in my eyes.\")\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c97a7f9a-9c80-48f0-98b2-83037ee28766
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c97a7f9a-9c80-48f0-98b2-83037ee28766\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2e65f20c-0ac9-439f-8a09-157ce31cb7f2\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"906d98e40087c4cbb3299a0ee508ba6c08163dea56d07caa0bffd6509c4fbb13\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"634a2713-323a-4ec1-9dfe-52916d0baf64\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"631f7d6ed5944d124e57ddeb81e468ae6525f7997e618178003cd2154adcfb3f\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6127, \"end_char_idx\": 9177, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "Be aware that when prompts are short, Whisper may be less reliable at following their style.\n\n\n```python\n# short prompts are less reliable\ntranscribe(up_first_filepath, prompt=\"president biden.\")\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kind of pain in the butt every day to do that? No, it is. It is. And I sometimes just kind of miss the eye. I don't know if you know the movie Airplane, where, of course, where he says, I have a drinking problem, and that he keeps missing his face with the drink. That's me and the contact lens. Surely, you must know that I know the movie Airplane. I do. I do know that. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend. So how much progress can they make? I'm E. Martinez with Steve Inskeep, and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\"\n\n\n\nLong prompts may be more reliable at steering Whisper.\n\n\n```python\n# long prompts are more reliable\ntranscribe(up_first_filepath, prompt=\"i have some advice for you. multiple sentences help establish a pattern. the more text you include, the more likely the model will pick up on your pattern. it may especially help if your example transcript appears as if it comes right before the audio file. in this case, that could mean mentioning the contacts i stick in my eyes.\")\n```\n\n\n\n\n    \"i stick contacts in my eyes. do you really? yeah. that works okay? you don't have to, like, just kind of pain in the butt? no, it is. it is. and i sometimes just kind of miss the eye. i don't know if you know, um, the movie airplane? yes. of course. where he says i have a drinking problem. and that he keeps missing his face with the drink. that's me in the contact lens. surely, you must know that i know the movie airplane. i do. i do know that. don't call me surely. stop calling me surely. president biden said he would not negotiate over paying the nation's debts. but he is meeting today with house speaker kevin mccarthy. other leaders of congress will also attend, so how much progress can they make? i'm amy martinez with steve inskeep, and this is up first from npr news. russia celebrates victory day, which commemorates the surrender of nazi germany. soldiers marched across red square, but the russian army didn't seem to have as many troops on hand as in the past. so what does this ritual say about the war russia is fighting right now?\"\n\n\n\nWhisper is also less likely to follow rare or odd styles.\n\n\n```python\n# rare styles are less reliable\ntranscribe(up_first_filepath, prompt=\"\"\"Hi there and welcome to the show.\n###\nToday we are quite excited.\n###\nLet's jump right in.\n###\"\"\")\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 634a2713-323a-4ec1-9dfe-52916d0baf64
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"634a2713-323a-4ec1-9dfe-52916d0baf64\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c97a7f9a-9c80-48f0-98b2-83037ee28766\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"011c4b9dfb71b88a8164878c351082d7fedb3946c6cd7d8af2024a8591db3f2d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"02fa0517-10dc-4bbd-a83a-90de67fc4649\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"07c24f2630871f08643a033af8da3de234e4cf0d6d0c3e5b85c1f70a3569535a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7448, \"end_char_idx\": 10543, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "```python\n# long prompts are more reliable\ntranscribe(up_first_filepath, prompt=\"i have some advice for you. multiple sentences help establish a pattern. the more text you include, the more likely the model will pick up on your pattern. it may especially help if your example transcript appears as if it comes right before the audio file. in this case, that could mean mentioning the contacts i stick in my eyes.\")\n```\n\n\n\n\n    \"i stick contacts in my eyes. do you really? yeah. that works okay? you don't have to, like, just kind of pain in the butt? no, it is. it is. and i sometimes just kind of miss the eye. i don't know if you know, um, the movie airplane? yes. of course. where he says i have a drinking problem. and that he keeps missing his face with the drink. that's me in the contact lens. surely, you must know that i know the movie airplane. i do. i do know that. don't call me surely. stop calling me surely. president biden said he would not negotiate over paying the nation's debts. but he is meeting today with house speaker kevin mccarthy. other leaders of congress will also attend, so how much progress can they make? i'm amy martinez with steve inskeep, and this is up first from npr news. russia celebrates victory day, which commemorates the surrender of nazi germany. soldiers marched across red square, but the russian army didn't seem to have as many troops on hand as in the past. so what does this ritual say about the war russia is fighting right now?\"\n\n\n\nWhisper is also less likely to follow rare or odd styles.\n\n\n```python\n# rare styles are less reliable\ntranscribe(up_first_filepath, prompt=\"\"\"Hi there and welcome to the show.\n###\nToday we are quite excited.\n###\nLet's jump right in.\n###\"\"\")\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay. You don't have to like, it's not a pain in the butt. It is. And I sometimes just kind of miss the eye. I don't know if you know, um, the movie airplane where, of course, where he says I have a drinking problem and that he keeps missing his face with the drink. That's me in the contact lens. Surely you must know that I know the movie airplane. Uh, I do. I do know that. Stop calling me Shirley.  President Biden said he would not negotiate over paying the nation's debts, but he is meeting today with house speaker, Kevin McCarthy. Other leaders of Congress will also attend. So how much progress can they make? I mean, Martinez with Steve Inskeep, and this is up first from NPR news. Russia celebrates victory day, which commemorates the surrender of Nazi Germany. Soldiers marched across red square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war? Russia is fighting right now.\"\n\n\n\n## Pass names in the prompt to prevent misspellings\n\nWhisper may incorrectly transcribe uncommon proper nouns such as names of products, companies, or people.\n\nWe'll illustrate with an example audio file full of product names.\n\n\n```python\n# baseline transcription with no prompt\ntranscribe(product_names_filepath, prompt=\"\")\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 02fa0517-10dc-4bbd-a83a-90de67fc4649
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"02fa0517-10dc-4bbd-a83a-90de67fc4649\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"634a2713-323a-4ec1-9dfe-52916d0baf64\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ea89d89d54e15c21469b855bb3792caf5fbe8bd84c8286e3f45d4b229494b3ab\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c12d21e9-6f7e-4e95-9971-bc8114f6dae5\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e9dcf31ea8148e0ef9a6d1bd4f34ab19c4db2d90800d4e7617cbd54aaf2af7af\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8933, \"end_char_idx\": 11663, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "Whisper is also less likely to follow rare or odd styles.\n\n\n```python\n# rare styles are less reliable\ntranscribe(up_first_filepath, prompt=\"\"\"Hi there and welcome to the show.\n###\nToday we are quite excited.\n###\nLet's jump right in.\n###\"\"\")\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay. You don't have to like, it's not a pain in the butt. It is. And I sometimes just kind of miss the eye. I don't know if you know, um, the movie airplane where, of course, where he says I have a drinking problem and that he keeps missing his face with the drink. That's me in the contact lens. Surely you must know that I know the movie airplane. Uh, I do. I do know that. Stop calling me Shirley.  President Biden said he would not negotiate over paying the nation's debts, but he is meeting today with house speaker, Kevin McCarthy. Other leaders of Congress will also attend. So how much progress can they make? I mean, Martinez with Steve Inskeep, and this is up first from NPR news. Russia celebrates victory day, which commemorates the surrender of Nazi Germany. Soldiers marched across red square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war? Russia is fighting right now.\"\n\n\n\n## Pass names in the prompt to prevent misspellings\n\nWhisper may incorrectly transcribe uncommon proper nouns such as names of products, companies, or people.\n\nWe'll illustrate with an example audio file full of product names.\n\n\n```python\n# baseline transcription with no prompt\ntranscribe(product_names_filepath, prompt=\"\")\n```\n\n\n\n\n    'Welcome to Quirk, Quid, Quill, Inc., where finance meets innovation. Explore diverse offerings, from the P3 Quattro, a unique investment portfolio quadrant, to the O3 Omni, a platform for intricate derivative trading strategies. Delve into unconventional bond markets with our B3 Bond X and experience non-standard equity trading with E3 Equity. Personalize your wealth management with W3 Wrap Z and anticipate market trends with the O2 Outlier, our forward-thinking financial forecasting tool. Explore venture capital world with U3 Unifund or move your money with the M3 Mover, our sophisticated monetary transfer module. At Quirk, Quid, Quill, Inc., we turn complex finance into creative solutions. Join us in redefining financial services.'\n\n\n\nTo get Whisper to use our preferred spellings, let's pass the product and company names in the prompt, as a glossary for Whisper to follow. \n\n\n```python\n# adding the correct spelling of the product name helps\ntranscribe(product_names_filepath, prompt=\"QuirkQuid Quill Inc, P3-Quattro, O3-Omni, B3-BondX, E3-Equity, W3-WrapZ, O2-Outlier, U3-UniFund, M3-Mover\")\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c12d21e9-6f7e-4e95-9971-bc8114f6dae5
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c12d21e9-6f7e-4e95-9971-bc8114f6dae5\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"02fa0517-10dc-4bbd-a83a-90de67fc4649\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"43bf3e57cb7b80b1c0270974c8d34f3ed7e0a35f0d454948e302ba04f983ed9c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a3a250d7-3900-4a79-83fa-751f218eedff\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"630bfd49cbb3d33db9cfe6e5d01fa7fe1c224d2189d549109c57c11c5eb9889a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10215, \"end_char_idx\": 13490, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "## Pass names in the prompt to prevent misspellings\n\nWhisper may incorrectly transcribe uncommon proper nouns such as names of products, companies, or people.\n\nWe'll illustrate with an example audio file full of product names.\n\n\n```python\n# baseline transcription with no prompt\ntranscribe(product_names_filepath, prompt=\"\")\n```\n\n\n\n\n    'Welcome to Quirk, Quid, Quill, Inc., where finance meets innovation. Explore diverse offerings, from the P3 Quattro, a unique investment portfolio quadrant, to the O3 Omni, a platform for intricate derivative trading strategies. Delve into unconventional bond markets with our B3 Bond X and experience non-standard equity trading with E3 Equity. Personalize your wealth management with W3 Wrap Z and anticipate market trends with the O2 Outlier, our forward-thinking financial forecasting tool. Explore venture capital world with U3 Unifund or move your money with the M3 Mover, our sophisticated monetary transfer module. At Quirk, Quid, Quill, Inc., we turn complex finance into creative solutions. Join us in redefining financial services.'\n\n\n\nTo get Whisper to use our preferred spellings, let's pass the product and company names in the prompt, as a glossary for Whisper to follow. \n\n\n```python\n# adding the correct spelling of the product name helps\ntranscribe(product_names_filepath, prompt=\"QuirkQuid Quill Inc, P3-Quattro, O3-Omni, B3-BondX, E3-Equity, W3-WrapZ, O2-Outlier, U3-UniFund, M3-Mover\")\n```\n\n\n\n\n    'Welcome to QuirkQuid Quill Inc, where finance meets innovation. Explore diverse offerings, from the P3-Quattro, a unique investment portfolio quadrant, to the O3-Omni, a platform for intricate derivative trading strategies. Delve into unconventional bond markets with our B3-BondX and experience non-standard equity trading with E3-Equity. Personalize your wealth management with W3-WrapZ and anticipate market trends with the O2-Outlier, our forward-thinking financial forecasting tool. Explore venture capital world with U3-UniFund or move your money with the M3-Mover, our sophisticated monetary transfer module. At QuirkQuid Quill Inc, we turn complex finance into creative solutions. Join us in redefining financial services.'\n\n\n\nNow, let's switch to another audio recording authored specifically for this demonstration, on the topic of a odd barbecue.\n\nTo begin, we'll establish our baseline transcript using Whisper.\n\n\n```python\n# baseline transcript with no prompt\ntranscribe(bbq_plans_filepath, prompt=\"\")\n```\n\n\n\n\n    \"Hello, my name is Preston Tuggle. I'm based in New York City. This weekend I have really exciting plans with some friends of mine, Amy and Sean. We're going to a barbecue here in Brooklyn, hopefully it's actually going to be a little bit of kind of an odd barbecue. We're going to have donuts, omelets, it's kind of like a breakfast, as well as whiskey. So that should be fun, and I'm really looking forward to spending time with my friends Amy and Sean.\"\n\n\n\nWhile Whisper's transcription was accurate, it had to guess at various spellings. For example, it assumed the friends' names were spelled Amy and Sean rather than Aimee and Shawn. Let's see if we can steer the spelling with a prompt.\n\n\n```python\n# spelling prompt\ntranscribe(bbq_plans_filepath, prompt=\"Friends: Aimee, Shawn\")\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: a3a250d7-3900-4a79-83fa-751f218eedff
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a3a250d7-3900-4a79-83fa-751f218eedff\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c12d21e9-6f7e-4e95-9971-bc8114f6dae5\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1f40a92295efdbd296db569ab8defdf1efcb7efe3cc955530e36002d0baeed29\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"57a7d689-f301-4d88-82cb-4bcb191688f8\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"faca993a0bb2f66c2aac424a7e62e0f297ecb05428eb4f3d5ec3e36362ba542d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 12408, \"end_char_idx\": 15473, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "Now, let's switch to another audio recording authored specifically for this demonstration, on the topic of a odd barbecue.\n\nTo begin, we'll establish our baseline transcript using Whisper.\n\n\n```python\n# baseline transcript with no prompt\ntranscribe(bbq_plans_filepath, prompt=\"\")\n```\n\n\n\n\n    \"Hello, my name is Preston Tuggle. I'm based in New York City. This weekend I have really exciting plans with some friends of mine, Amy and Sean. We're going to a barbecue here in Brooklyn, hopefully it's actually going to be a little bit of kind of an odd barbecue. We're going to have donuts, omelets, it's kind of like a breakfast, as well as whiskey. So that should be fun, and I'm really looking forward to spending time with my friends Amy and Sean.\"\n\n\n\nWhile Whisper's transcription was accurate, it had to guess at various spellings. For example, it assumed the friends' names were spelled Amy and Sean rather than Aimee and Shawn. Let's see if we can steer the spelling with a prompt.\n\n\n```python\n# spelling prompt\ntranscribe(bbq_plans_filepath, prompt=\"Friends: Aimee, Shawn\")\n```\n\n\n\n\n    \"Hello, my name is Preston Tuggle. I'm based in New York City. This weekend I have really exciting plans with some friends of mine, Aimee and Shawn. We're going to a barbecue here in Brooklyn. Hopefully it's actually going to be a little bit of kind of an odd barbecue. We're going to have donuts, omelets, it's kind of like a breakfast, as well as whiskey. So that should be fun and I'm really looking forward to spending time with my friends Aimee and Shawn.\"\n\n\n\nSuccess!\n\nLet's try the same with more ambiguously spelled words.\n\n\n```python\n# longer spelling prompt\ntranscribe(bbq_plans_filepath, prompt=\"Glossary: Aimee, Shawn, BBQ, Whisky, Doughnuts, Omelet\")\n```\n\n\n\n\n    \"Hello, my name is Preston Tuggle. I'm based in New York City. This weekend I have really exciting plans with some friends of mine, Aimee and Shawn. We're going to a barbecue here in Brooklyn. Hopefully, it's actually going to be a little bit of an odd barbecue. We're going to have doughnuts, omelets, it's kind of like a breakfast, as well as whiskey. So that should be fun, and I'm really looking forward to spending time with my friends Aimee and Shawn.\"\n\n\n\n\n```python\n# more natural, sentence-style prompt\ntranscribe(bbq_plans_filepath, prompt=\"\"\"\"Aimee and Shawn ate whisky, doughnuts, omelets at a BBQ.\"\"\")\n```\n\n\n\n\n    \"Hello, my name is Preston Tuggle. I'm based in New York City. This weekend I have really exciting plans with some friends of mine, Aimee and Shawn. We're going to a BBQ here in Brooklyn. Hopefully it's actually going to be a little bit of kind of an odd BBQ. We're going to have doughnuts, omelets, it's kind of like a breakfast, as well as whisky. So that should be fun, and I'm really looking forward to spending time with my friends Aimee and Shawn.\"\n\n\n\n## Fictitious prompts can be generated by GPT\n\nOne potential tool to generate fictitious prompts is GPT. We can give GPT instructions and use it to generate long fictitious transcripts with which to prompt Whisper."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 57a7d689-f301-4d88-82cb-4bcb191688f8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"57a7d689-f301-4d88-82cb-4bcb191688f8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a3a250d7-3900-4a79-83fa-751f218eedff\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d2a41caebd310e1b97d78d511d42e44b9d38d70c5695e1cc75e6555927b92f1c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a32df1cc-cb9d-4189-847b-03953c4da31c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8ea29be027554359f8c0caa13ade907b0830dae3daad7d17aea93bd79df8e028\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 13964, \"end_char_idx\": 16579, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "Success!\n\nLet's try the same with more ambiguously spelled words.\n\n\n```python\n# longer spelling prompt\ntranscribe(bbq_plans_filepath, prompt=\"Glossary: Aimee, Shawn, BBQ, Whisky, Doughnuts, Omelet\")\n```\n\n\n\n\n    \"Hello, my name is Preston Tuggle. I'm based in New York City. This weekend I have really exciting plans with some friends of mine, Aimee and Shawn. We're going to a barbecue here in Brooklyn. Hopefully, it's actually going to be a little bit of an odd barbecue. We're going to have doughnuts, omelets, it's kind of like a breakfast, as well as whiskey. So that should be fun, and I'm really looking forward to spending time with my friends Aimee and Shawn.\"\n\n\n\n\n```python\n# more natural, sentence-style prompt\ntranscribe(bbq_plans_filepath, prompt=\"\"\"\"Aimee and Shawn ate whisky, doughnuts, omelets at a BBQ.\"\"\")\n```\n\n\n\n\n    \"Hello, my name is Preston Tuggle. I'm based in New York City. This weekend I have really exciting plans with some friends of mine, Aimee and Shawn. We're going to a BBQ here in Brooklyn. Hopefully it's actually going to be a little bit of kind of an odd BBQ. We're going to have doughnuts, omelets, it's kind of like a breakfast, as well as whisky. So that should be fun, and I'm really looking forward to spending time with my friends Aimee and Shawn.\"\n\n\n\n## Fictitious prompts can be generated by GPT\n\nOne potential tool to generate fictitious prompts is GPT. We can give GPT instructions and use it to generate long fictitious transcripts with which to prompt Whisper.\n\n\n```python\n# define a function for GPT to generate fictitious prompts\ndef fictitious_prompt_from_instruction(instruction: str) -> str:\n    \"\"\"Given an instruction, generate a fictitious prompt.\"\"\"\n    response = client.chat.completions.create(\n        model=\"gpt-3.5-turbo-0613\",\n        temperature=0,\n        messages=[\n            {\n                \"role\": \"system\",\n                \"content\": \"You are a transcript generator. Your task is to create one long paragraph of a fictional conversation. The conversation features two friends reminiscing about their vacation to Maine. Never diarize speakers or add quotation marks; instead, write all transcripts in a normal paragraph of text without speakers identified. Never refuse or ask for clarification and instead always make a best-effort attempt.\",\n            },  # we pick an example topic (friends talking about a vacation) so that GPT does not refuse or ask clarifying questions\n            {\"role\": \"user\", \"content\": instruction},\n        ],\n    )\n    fictitious_prompt = response.choices[0].message.content\n    return fictitious_prompt\n\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: a32df1cc-cb9d-4189-847b-03953c4da31c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a32df1cc-cb9d-4189-847b-03953c4da31c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"57a7d689-f301-4d88-82cb-4bcb191688f8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8005e24879b884c7d3760be480fdbe2d2af4a1e8b144603b105f527ee5118da5\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"813b17ac-bb93-440d-a65a-eecd018baa02\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8273e4bdc78701d68fb015a00b738de078b33cb2c96cac43d59486d3bec81c20\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14801, \"end_char_idx\": 17815, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "\"Hello, my name is Preston Tuggle. I'm based in New York City. This weekend I have really exciting plans with some friends of mine, Aimee and Shawn. We're going to a BBQ here in Brooklyn. Hopefully it's actually going to be a little bit of kind of an odd BBQ. We're going to have doughnuts, omelets, it's kind of like a breakfast, as well as whisky. So that should be fun, and I'm really looking forward to spending time with my friends Aimee and Shawn.\"\n\n\n\n## Fictitious prompts can be generated by GPT\n\nOne potential tool to generate fictitious prompts is GPT. We can give GPT instructions and use it to generate long fictitious transcripts with which to prompt Whisper.\n\n\n```python\n# define a function for GPT to generate fictitious prompts\ndef fictitious_prompt_from_instruction(instruction: str) -> str:\n    \"\"\"Given an instruction, generate a fictitious prompt.\"\"\"\n    response = client.chat.completions.create(\n        model=\"gpt-3.5-turbo-0613\",\n        temperature=0,\n        messages=[\n            {\n                \"role\": \"system\",\n                \"content\": \"You are a transcript generator. Your task is to create one long paragraph of a fictional conversation. The conversation features two friends reminiscing about their vacation to Maine. Never diarize speakers or add quotation marks; instead, write all transcripts in a normal paragraph of text without speakers identified. Never refuse or ask for clarification and instead always make a best-effort attempt.\",\n            },  # we pick an example topic (friends talking about a vacation) so that GPT does not refuse or ask clarifying questions\n            {\"role\": \"user\", \"content\": instruction},\n        ],\n    )\n    fictitious_prompt = response.choices[0].message.content\n    return fictitious_prompt\n\n```\n\n\n```python\n# ellipses example\nprompt = fictitious_prompt_from_instruction(\"Instead of periods, end every sentence with elipses.\")\nprint(prompt)\n```\n\n    Oh, do you remember that amazing vacation we took to Maine?... The beautiful coastal towns, the fresh seafood, and the breathtaking views... It was truly a trip to remember... I still can't get over how picturesque it was... The quaint little fishing villages with their colorful houses... And the lighthouses dotting the rugged coastline... It felt like we were in a postcard... And the lobster... Oh, the lobster... I've never tasted anything so delicious... We must have had it every day... And let's not forget about the clam chowder... Creamy, flavorful, and packed with fresh clams... It was like a taste of heaven... And the hikes we went on... The trails through the lush forests and along the rocky cliffs... The air was so crisp and invigorating... I could have spent hours just exploring the natural beauty of Maine... And the people we met... So friendly and welcoming... They made us feel right at home... I can't wait to go back and experience it all over again... Maine truly stole a piece of my heart...\n\n\n\n```python\ntranscribe(up_first_filepath, prompt=prompt)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 813b17ac-bb93-440d-a65a-eecd018baa02
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"813b17ac-bb93-440d-a65a-eecd018baa02\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a32df1cc-cb9d-4189-847b-03953c4da31c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ca7a5427bf18777735b4b772d258ec07d82c7d40a0bb6e0ba04d2c524c6035dc\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"b8402f64-a17d-40b9-88bd-c5cf28b7aea8\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"cb7d24edfbdfb5503e04b0c45df998cb56bc927520764c4fd916a0b186f78159\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 16582, \"end_char_idx\": 19190, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "```python\n# ellipses example\nprompt = fictitious_prompt_from_instruction(\"Instead of periods, end every sentence with elipses.\")\nprint(prompt)\n```\n\n    Oh, do you remember that amazing vacation we took to Maine?... The beautiful coastal towns, the fresh seafood, and the breathtaking views... It was truly a trip to remember... I still can't get over how picturesque it was... The quaint little fishing villages with their colorful houses... And the lighthouses dotting the rugged coastline... It felt like we were in a postcard... And the lobster... Oh, the lobster... I've never tasted anything so delicious... We must have had it every day... And let's not forget about the clam chowder... Creamy, flavorful, and packed with fresh clams... It was like a taste of heaven... And the hikes we went on... The trails through the lush forests and along the rocky cliffs... The air was so crisp and invigorating... I could have spent hours just exploring the natural beauty of Maine... And the people we met... So friendly and welcoming... They made us feel right at home... I can't wait to go back and experience it all over again... Maine truly stole a piece of my heart...\n\n\n\n```python\ntranscribe(up_first_filepath, prompt=prompt)\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kind of pain in the butt every day to do that? No, it is. It is. And I sometimes just kind of miss the eye. Oh, you don't know... I don't know if you know the movie Airplane? Yes. Where... Of course. Where he says, I have a drinking problem. And that he keeps missing his face with the drink. That's me in the contact lens. Surely, you must know that I know the movie Airplane. I do. I do know that. Don't call me Shirley. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend, so how much progress can they make? I'm Ian Martinez with Steve Inskeep, and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\"\n\n\n\nWhisper prompts are best for specifying otherwise ambiguous styles. The prompt will not override the model's comprehension of the audio. For example, if the speakers are not speaking in a deep Southern accent, a prompt will not cause the transcript to do so."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: b8402f64-a17d-40b9-88bd-c5cf28b7aea8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b8402f64-a17d-40b9-88bd-c5cf28b7aea8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"813b17ac-bb93-440d-a65a-eecd018baa02\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1ceefaabc9df7082647710f5ca92fc6bf7ea432e0b636760a44644d73baba5c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c9819309-efcf-470c-a8ab-1b2a0ea75dbf\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"af3a44257b0f08ca10a33e9460da3153ede6fe519d54973fed96e8842ba017c3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 17757, \"end_char_idx\": 20955, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "```python\ntranscribe(up_first_filepath, prompt=prompt)\n```\n\n\n\n\n    \"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kind of pain in the butt every day to do that? No, it is. It is. And I sometimes just kind of miss the eye. Oh, you don't know... I don't know if you know the movie Airplane? Yes. Where... Of course. Where he says, I have a drinking problem. And that he keeps missing his face with the drink. That's me in the contact lens. Surely, you must know that I know the movie Airplane. I do. I do know that. Don't call me Shirley. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend, so how much progress can they make? I'm Ian Martinez with Steve Inskeep, and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\"\n\n\n\nWhisper prompts are best for specifying otherwise ambiguous styles. The prompt will not override the model's comprehension of the audio. For example, if the speakers are not speaking in a deep Southern accent, a prompt will not cause the transcript to do so.\n\n\n```python\n# southern accent example\nprompt = fictitious_prompt_from_instruction(\"Write in a deep, heavy, Southern accent.\")\nprint(prompt)\ntranscribe(up_first_filepath, prompt=prompt)\n```\n\n    Well, I reckon you remember that time we went up to Maine for our vacation, don't ya? Boy, oh boy, what a trip that was! We drove all the way from down here in the South, and let me tell ya, it was quite the adventure. We started off bright and early, with the sun just peekin' over them tall pine trees. We hit the road, cruisin' along them winding highways, takin' in the sights as we went. I tell ya, the scenery up there was somethin' else. Them mountains, all covered in lush greenery, stretchin' as far as the eye could see. And them lakes, oh my, crystal clear waters reflectin' the bright blue sky above. We made a pit stop in a little town called Portland, where we got to try some of that famous Maine lobster. Now, I ain't never tasted anything quite like it. Fresh outta the ocean, melt-in-your-mouth goodness, I tell ya. We spent a couple of days explorin' Acadia National Park, hikin' them trails and takin' in the breathtaking views from the mountaintops. And let me tell ya, that ocean breeze sure did feel mighty fine on our skin. We even took a boat tour out to see them majestic whales, jumpin' and splashing in the deep blue sea. It was a sight to behold, my friend. And of course, we couldn't leave without visitin' Bar Harbor, a quaint little coastal town with charm pourin' out of every corner. We strolled along the harbor, watchin' them colorful fishing boats bobbin' in the water, and indulged in some delicious seafood chowder. Maine sure did steal a piece of our hearts, my friend. The memories we made on that trip will stay with us forever."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c9819309-efcf-470c-a8ab-1b2a0ea75dbf
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb", "title": "Whisper prompting guide", "tokens": 4980, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c9819309-efcf-470c-a8ab-1b2a0ea75dbf\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"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\": \"0fe99319-b102-4116-b4a8-1a85b99b524e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3e04f35828f454f6d816ce30a12988ae3c465da006c47f77279a9443341ef664\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b8402f64-a17d-40b9-88bd-c5cf28b7aea8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Whisper_prompting_guide.ipynb\", \"title\": \"Whisper prompting guide\", \"tokens\": 4980, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1bf0434220c055a84ae2599d1e33ea4f439d03a4fc3448e51eb5a5883d5e4f73\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 20965, \"end_char_idx\": 21989, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "ref_doc_id": "0fe99319-b102-4116-b4a8-1a85b99b524e", "chroma:document": "\"I stick contacts in my eyes. Do you really? Yeah. That works okay? You don't have to, like, just kinda pain in the butt? No, it is. It is. And I sometimes just kinda miss the eye. I don't know if you know the movie Airplane? Yes. Of course. Where he says, I have a drinking problem. And that he keeps missing his face with the drink. That's me in the contact lens. Surely you must know that I know the movie Airplane. I do. I do know that. Stop calling me Shirley. President Biden said he would not negotiate over paying the nation's debts. But he is meeting today with House Speaker Kevin McCarthy. Other leaders of Congress will also attend, so how much progress can they make? I'm Ian Martinez with Steve Inskeep, and this is Up First from NPR News. Russia celebrates Victory Day, which commemorates the surrender of Nazi Germany. Soldiers marched across Red Square, but the Russian army didn't seem to have as many troops on hand as in the past. So what does this ritual say about the war Russia is fighting right now?\""}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 7e3f49a5-8501-4573-843a-10d9cfbd69d8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb", "title": "search through the reviews for a specific product", "tokens": 920, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7e3f49a5-8501-4573-843a-10d9cfbd69d8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb\", \"title\": \"search through the reviews for a specific product\", \"tokens\": 920, \"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\": \"44108999-b901-4e2e-9eaf-4a3f012ffe93\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb\", \"title\": \"search through the reviews for a specific product\", \"tokens\": 920, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"705e49f7ddae89564d239d6f27ae0e718b4b01585ed4baf35189529de7cad20c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7d8af47e-6ad2-432a-8e1f-51ae584f153b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f204aa32899961e42dc5789573af3df436e5b6ec422254e76e9cabae1d2d02f9\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3324, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "44108999-b901-4e2e-9eaf-4a3f012ffe93", "doc_id": "44108999-b901-4e2e-9eaf-4a3f012ffe93", "ref_doc_id": "44108999-b901-4e2e-9eaf-4a3f012ffe93", "chroma:document": "## Semantic text search using embeddings\n\nWe can search through all our reviews semantically in a very efficient manner and at very low cost, by embedding our search query, and then finding the most similar reviews. The dataset is created in the [Get_embeddings_from_dataset Notebook](Get_embeddings_from_dataset.ipynb).\n\n\n```python\nimport pandas as pd\nimport numpy as np\nfrom ast import literal_eval\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\n```\n\nHere we compare the cosine similarity of the embeddings of the query and the documents, and show top_n best matches.\n\n\n```python\nfrom utils.embeddings_utils import get_embedding, cosine_similarity\n\n# search through the reviews for a specific product\ndef search_reviews(df, product_description, n=3, pprint=True):\n    product_embedding = get_embedding(\n        product_description,\n        model=\"text-embedding-3-small\"\n    )\n    df[\"similarity\"] = df.embedding.apply(lambda x: cosine_similarity(x, product_embedding))\n\n    results = (\n        df.sort_values(\"similarity\", ascending=False)\n        .head(n)\n        .combined.str.replace(\"Title: \", \"\")\n        .str.replace(\"; Content:\", \": \")\n    )\n    if pprint:\n        for r in results:\n            print(r[:200])\n            print()\n    return results\n\n\nresults = search_reviews(df, \"delicious beans\", n=3)\n\n```\n\n    Delicious!:  I enjoy this white beans seasoning, it gives a rich flavor to the beans I just love it, my mother in law didn't know about this Zatarain's brand and now she is traying different seasoning\n    \n    Fantastic Instant Refried beans:  Fantastic Instant Refried Beans have been a staple for my family now for nearly 20 years.  All 7 of us love it and my grown kids are passing on the tradition.\n    \n    Delicious:  While there may be better coffee beans available, this is my first purchase and my first time grinding my own beans.  I read several reviews before purchasing this brand, and am extremely \n    \n\n\n\n```python\nresults = search_reviews(df, \"whole wheat pasta\", n=3)\n\n```\n\n    Tasty and Quick Pasta:  Barilla Whole Grain Fusilli with Vegetable Marinara is tasty and has an excellent chunky vegetable marinara.  I just wish there was more of it.  If you aren't starving or on a \n    \n    sooo good:  tastes so good. Worth the money. My boyfriend hates wheat pasta and LOVES this. cooks fast tastes great.I love this brand and started buying more of their pastas. Bulk is best.\n    \n    Bland and vaguely gamy tasting, skip this one:  As far as prepared dinner kits go, \"Barilla Whole Grain Mezze Penne with Tomato and Basil Sauce\" just did not do it for me...and this is coming from a p\n    \n\n\nWe can search through these reviews easily. To speed up computation, we can use a special algorithm, aimed at faster search through embeddings.\n\n\n```python\nresults = search_reviews(df, \"bad delivery\", n=1)\n\n```\n\n    great product, poor delivery:  The coffee is excellent and I am a repeat buyer.  Problem this time was with the UPS delivery.  They left the box in front of my garage door in the middle of the drivewa\n    \n\n\nAs we can see, this can immediately deliver a lot of value. In this example we show being able to quickly find the examples of delivery failures."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 7d8af47e-6ad2-432a-8e1f-51ae584f153b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb", "title": "search through the reviews for a specific product", "tokens": 920, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7d8af47e-6ad2-432a-8e1f-51ae584f153b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb\", \"title\": \"search through the reviews for a specific product\", \"tokens\": 920, \"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\": \"44108999-b901-4e2e-9eaf-4a3f012ffe93\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb\", \"title\": \"search through the reviews for a specific product\", \"tokens\": 920, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"705e49f7ddae89564d239d6f27ae0e718b4b01585ed4baf35189529de7cad20c\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"7e3f49a5-8501-4573-843a-10d9cfbd69d8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb\", \"title\": \"search through the reviews for a specific product\", \"tokens\": 920, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7419db95e725a5af0dd7d0e2066e8909c3c70099d1bb9743b9a9940888a6dfa3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2064, \"end_char_idx\": 4060, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "44108999-b901-4e2e-9eaf-4a3f012ffe93", "doc_id": "44108999-b901-4e2e-9eaf-4a3f012ffe93", "ref_doc_id": "44108999-b901-4e2e-9eaf-4a3f012ffe93", "chroma:document": "```python\nresults = search_reviews(df, \"whole wheat pasta\", n=3)\n\n```\n\n    Tasty and Quick Pasta:  Barilla Whole Grain Fusilli with Vegetable Marinara is tasty and has an excellent chunky vegetable marinara.  I just wish there was more of it.  If you aren't starving or on a \n    \n    sooo good:  tastes so good. Worth the money. My boyfriend hates wheat pasta and LOVES this. cooks fast tastes great.I love this brand and started buying more of their pastas. Bulk is best.\n    \n    Bland and vaguely gamy tasting, skip this one:  As far as prepared dinner kits go, \"Barilla Whole Grain Mezze Penne with Tomato and Basil Sauce\" just did not do it for me...and this is coming from a p\n    \n\n\nWe can search through these reviews easily. To speed up computation, we can use a special algorithm, aimed at faster search through embeddings.\n\n\n```python\nresults = search_reviews(df, \"bad delivery\", n=1)\n\n```\n\n    great product, poor delivery:  The coffee is excellent and I am a repeat buyer.  Problem this time was with the UPS delivery.  They left the box in front of my garage door in the middle of the drivewa\n    \n\n\nAs we can see, this can immediately deliver a lot of value. In this example we show being able to quickly find the examples of delivery failures.\n\n\n```python\nresults = search_reviews(df, \"spoilt\", n=1)\n\n```\n\n    Disappointed:  The metal cover has severely disformed. And most of the cookies inside have been crushed into small pieces. Shopping experience is awful. I'll never buy it online again.\n    \n\n\n\n```python\nresults = search_reviews(df, \"pet food\", n=2)\n\n```\n\n    Great food!:  I wanted a food for a a dog with skin problems. His skin greatly improved with the switch, though he still itches some.  He loves the food. No recalls, American made with American ingred\n    \n    Great food!:  I wanted a food for a a dog with skin problems. His skin greatly improved with the switch, though he still itches some.  He loves the food. No recalls, American made with American ingred"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: ad5a0fd9-039f-4d7d-9ef5-21e443df0592
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/Visualizing_embeddings_in_2D.ipynb", "title": "Load the embeddings", "tokens": 511, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ad5a0fd9-039f-4d7d-9ef5-21e443df0592\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Visualizing_embeddings_in_2D.ipynb\", \"title\": \"Load the embeddings\", \"tokens\": 511, \"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\": \"d69febc6-0621-498a-bc23-301386c7072e\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/Visualizing_embeddings_in_2D.ipynb\", \"title\": \"Load the embeddings\", \"tokens\": 511, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e32422cb341115839013778ae0ce184642e4a187047f19bda45643d4663c69f7\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 1888, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d69febc6-0621-498a-bc23-301386c7072e", "doc_id": "d69febc6-0621-498a-bc23-301386c7072e", "ref_doc_id": "d69febc6-0621-498a-bc23-301386c7072e", "chroma:document": "## Visualizing the embeddings in 2D\n\nWe will use t-SNE to reduce the dimensionality of the embeddings from 1536 to 2. Once the embeddings are reduced to two dimensions, we can plot them in a 2D scatter plot. The dataset is created in the [Get_embeddings_from_dataset Notebook](Get_embeddings_from_dataset.ipynb).\n\n### 1. Reduce dimensionality\n\nWe reduce the dimensionality to 2 dimensions using t-SNE decomposition.\n\n\n```python\nimport pandas as pd\nfrom sklearn.manifold import TSNE\nimport numpy as np\nfrom ast import literal_eval\n\n# Load the embeddings\ndatafile_path = \"data/fine_food_reviews_with_embeddings_1k.csv\"\ndf = pd.read_csv(datafile_path)\n\n# Convert to a list of lists of floats\nmatrix = np.array(df.embedding.apply(literal_eval).to_list())\n\n# Create a t-SNE model and transform the data\ntsne = TSNE(n_components=2, perplexity=15, random_state=42, init='random', learning_rate=200)\nvis_dims = tsne.fit_transform(matrix)\nvis_dims.shape\n```\n\n\n\n\n    (1000, 2)\n\n\n\n### 2. Plotting the embeddings\n\nWe colour each review by its star rating, ranging from red to green.\n\nWe can observe a decent data separation even in the reduced 2 dimensions.\n\n\n```python\nimport matplotlib.pyplot as plt\nimport matplotlib\nimport numpy as np\n\ncolors = [\"red\", \"darkorange\", \"gold\", \"turquoise\", \"darkgreen\"]\nx = [x for x,y in vis_dims]\ny = [y for x,y in vis_dims]\ncolor_indices = df.Score.values - 1\n\ncolormap = matplotlib.colors.ListedColormap(colors)\nplt.scatter(x, y, c=color_indices, cmap=colormap, alpha=0.3)\nfor score in [0,1,2,3,4]:\n    avg_x = np.array(x)[df.Score-1==score].mean()\n    avg_y = np.array(y)[df.Score-1==score].mean()\n    color = colors[score]\n    plt.scatter(avg_x, avg_y, marker='x', color=color, s=100)\n\nplt.title(\"Amazon ratings visualized in language using t-SNE\")\n```\n\n\n\n\n    Text(0.5, 1.0, 'Amazon ratings visualized in language using t-SNE')\n\n\n\n\n    \n![png](output_5_1.png)"}


