{"id":8189,"date":"2023-11-22T17:27:55","date_gmt":"2023-11-23T01:27:55","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=8189"},"modified":"2025-04-24T17:04:22","modified_gmt":"2025-04-24T17:04:22","slug":"create-a-simple-e-commerce-chatbot-with-openai","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/","title":{"rendered":"Create a Simple E-commerce Chatbot With OpenAI"},"content":{"rendered":"\n<h2 class=\"wp-block-heading pw-subtitle-paragraph tt fy tg be b tu tv tw tx ty tz ua ub uc ud ue uf ug uh ui ro dq\" id=\"e533\">Forget about complicated Deep Learning algorithms \u2014 making a chatbot is way simpler with OpenAI and CometLLM<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter bg xl abo c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*RPJnm1-q-d7dJoTK.png\" alt=\"Create an e-commerce chatbot \/ shopbot with OpenAI and CometLLM\"\/><figcaption class=\"wp-element-caption\">Chatbot in Ecommerce (Credit: Maksym Pundyk in ideainyou.com)<\/figcaption><\/figure>\n\n\n\n<div class=\"ew tb tc td te\">\n<div class=\"ab cm\">\n<div class=\"hy bg hz ia ib ic\">\n<h3><span style=\"color: var(--wpex-heading-color); font-size: var(--wpex-text-3xl); font-weight: var(--wpex-heading-font-weight); font-family: var(--wpex-body-font-family, var(--wpex-font-sans));\">Table of Contents<\/span><\/h3>\n<p id=\"eeb0\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">Introduction<\/em><\/p>\n<p id=\"b025\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">I. Prompting for Developers: A Guideline<\/em><\/p>\n<p id=\"c355\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">II. Building a Shopbot using OpenAI and CometLLM<\/em><\/p>\n<ol class=\"\">\n<li id=\"fce6\" class=\"yu yv tg be b tu zn yx yy tx zo za zb mq zs zd ze mv zt zg zh na zu zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><em class=\"zm\">Understanding the Basics<\/em><\/li>\n<li id=\"1797\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><em class=\"zm\">Setting Up the Environment<\/em><\/li>\n<li id=\"c61a\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><em class=\"zm\">Defining Product Information<\/em><\/li>\n<li id=\"3af8\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><em class=\"zm\">Creating the Chatbot<\/em><\/li>\n<li id=\"00bf\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><em class=\"zm\">Interacting with Customers<\/em><\/li>\n<\/ol>\n<p id=\"9b75\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">III. Reference<\/em><\/p>\n<p id=\"0ce6\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">Conclusion<\/em><\/p>\n<h3 id=\"6735\" class=\"ya yb tg be yc yd ye tw mk yf yg tz mp yh yi yj yk yl ym yn yo yp yq yr ys yt bj\">Introduction<\/h3>\n<p id=\"f3c3\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\">OpenAI makes it easier than ever to create chatbots for your e-commerce business, eliminating the need for complex deep learning algorithms. Discover simple and effective approaches to increase customer engagement and optimize the online shopping experience. This step-by-step tutorial will walk you through the key components and make it easy to bring your own AI-powered ShopBot to life. Easily transform your e-commerce platform into an interactive, customer-centric shopping destination.<\/p>\n<figure class=\"abe abf abg abh abi abj lp lq paragraph-image\">\n<div class=\"abk abl dl abm bg abn\" tabindex=\"0\" role=\"button\">\n<div class=\"lp lq abd\">\n<picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/0*RPJnm1-q-d7dJoTK.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/0*RPJnm1-q-d7dJoTK.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/0*RPJnm1-q-d7dJoTK.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/0*RPJnm1-q-d7dJoTK.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/0*RPJnm1-q-d7dJoTK.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/0*RPJnm1-q-d7dJoTK.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/0*RPJnm1-q-d7dJoTK.png 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/0*RPJnm1-q-d7dJoTK.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/0*RPJnm1-q-d7dJoTK.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/0*RPJnm1-q-d7dJoTK.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/0*RPJnm1-q-d7dJoTK.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/0*RPJnm1-q-d7dJoTK.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/0*RPJnm1-q-d7dJoTK.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*RPJnm1-q-d7dJoTK.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture>\n<\/div>\n<\/div>\n<\/figure>\n<blockquote class=\"abt abu abv\"><p id=\"61da\" class=\"yu yv zm be b tu zn yx yy tx zo za zb abw zp zd ze abx zq zg zh aby zr zj zk zl ew bj\" data-selectable-paragraph=\"\">\ud83d\udca1I write about Machine Learning on&nbsp;<a class=\"af hd\" href=\"https:\/\/medium.com\/@yennhi95zz\/subscribe\" rel=\"noopener\">Medium<\/a>&nbsp;||&nbsp;<a class=\"af hd\" href=\"https:\/\/github.com\/yennhi95zz\" target=\"_blank\" rel=\"noopener ugc nofollow\">Github<\/a>&nbsp;||&nbsp;<a class=\"af hd\" href=\"https:\/\/www.kaggle.com\/nhiyen\/code\" target=\"_blank\" rel=\"noopener ugc nofollow\">Kaggle<\/a>&nbsp;||&nbsp;<a class=\"af hd\" href=\"https:\/\/www.linkedin.com\/in\/yennhi95zz\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Linkedin<\/a>. \ud83d\udd14 Follow \u201cNhi Yen\u201d for future updates!<\/p><\/blockquote>\n<p id=\"0397\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">\ud83d\udc49 Get UNLIMITED access to every story on Medium with just $1\/week \u2014&nbsp;<\/em><a class=\"af hd\" href=\"https:\/\/medium.com\/@yennhi95zz\/membership\" rel=\"noopener\"><strong class=\"be fx\"><em class=\"zm\">HERE<\/em><\/strong><\/a><\/p>\n<h3 id=\"9c64\" class=\"ya yb tg be yc yd ye tw mk yf yg tz mp yh yi yj yk yl ym yn yo yp yq yr ys yt bj\">I. Prompting for Developers: A Guideline<\/h3>\n<h4 id=\"1757\" class=\"abz yb tg be yc mg aca mh mk ml acb mm mp mq acc mr mu mv acd mw mz na ace nb ne acf bj\">Principle 1: Write Clear and Specific Instructions<\/h4>\n<ol class=\"\">\n<li id=\"d6ce\" class=\"yu yv tg be b tu yw yx yy tx yz za zb mq acg zd ze mv ach zg zh na aci zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\">Delimiters for Precision<\/strong>: start clearly. Use delimiters such as triple quotes (<code class=\"eg acj ack acl acm b\">\u201c\u2018xxx\u2019\u201d<\/code>), triple backticks (<code class=\"eg acj ack acl acm b\">```<\/code>), triple dashes (&nbsp;<code class=\"eg acj ack acl acm b\">\u2014 -<\/code>), angle brackets (<code class=\"eg acj ack acl acm b\">&lt; &gt;<\/code>), and XML tags. These act as navigational aids, precisely guiding the model through the various components of the message.<\/li>\n<li id=\"5a9d\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\">Structured output for increased accuracy<\/strong>: Specify the desired format of the output (HTML or JSON). A structured framework ensures that the model accurately understands and fulfills requests, avoiding misunderstandings.<\/li>\n<li id=\"5b29\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\">Validate trust assumptions<\/strong>: Validate whether the required conditions are met before assigning a task. Clearly explain the prerequisites required for the task and ensure that your understanding of the model aligns with your expectations for safe execution.<\/li>\n<li id=\"55c1\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\">Few-Shot Prompting for Guidance<\/strong>: Before instructing the model, provide examples of successful task completion. This not only guides the model on the right path, but also increases the probability of accurate results.<\/li>\n<\/ol>\n<h4 id=\"6822\" class=\"abz yb tg be yc mg aca mh mk ml acb mm mp mq acc mr mu mv acd mw mz na ace nb ne acf bj\">Principle 2: Give the Model Time to \u201cThink\u201d<\/h4>\n<ol class=\"\">\n<li id=\"0c30\" class=\"yu yv tg be b tu yw yx yy tx yz za zb mq acg zd ze mv ach zg zh na aci zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\">Comprehensive task steps<\/strong>: Break down complex tasks into step-by-step instructions. This allows the model to understand the complexity of the task and increases the likelihood of accurate and complete results.<\/li>\n<li id=\"4093\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\">Encourage thoughtful solutions<\/strong>: Give it time to find its own solutions instead of urging the model\u2019s conclusions. This patient approach reduces the potential for error caused by hasty action and encourages more thoughtful responses., enhancing the likelihood of accurate and comprehensive outputs.<\/li>\n<\/ol>\n<h3 id=\"9298\" class=\"abz yb tg be yc mg aca mh mk ml acb mm mp mq acc mr mu mv acd mw mz na ace nb ne acf bj\">A Complex prompt<\/h3>\n<p id=\"b9f7\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\">Now, considering the concept of complex indicators, these principles can be applied to indicators that cover at least 3 of the following parameters:<\/p>\n<ol class=\"\">\n<li id=\"8890\" class=\"yu yv tg be b tu zn yx yy tx zo za zb mq zs zd ze mv zt zg zh na zu zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\">Role: Assign an expert role to a task.<\/li>\n<li id=\"230b\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\">Task: Enter a brief summary of the task.<\/li>\n<li id=\"ac11\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\">Context: Provide relevant background.<\/li>\n<li id=\"d0fc\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\">Steps to complete the task: Provide specific steps.<\/li>\n<li id=\"6607\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\">Output format: Specify the desired format, style, or tone.<\/li>\n<li id=\"4625\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\">Limitations: Please note any limitations or requirements.<\/li>\n<li id=\"a7f5\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl zv zw zx bj\" data-selectable-paragraph=\"\">Purpose: Describe the purpose for the results.<\/li>\n<\/ol>\n<p id=\"3a13\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\">Example:<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"959b\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\"><span class=\"hljs-string\">You<\/span> <span class=\"hljs-string\">are<\/span> <span class=\"hljs-string\">a<\/span> <span class=\"hljs-string\">travel<\/span> <span class=\"hljs-string\">assistant.<\/span>\n\n<span class=\"hljs-string\">Please<\/span> <span class=\"hljs-string\">plan<\/span> <span class=\"hljs-string\">a<\/span> <span class=\"hljs-string\">week-long<\/span> <span class=\"hljs-string\">itinerary<\/span> <span class=\"hljs-string\">for<\/span> <span class=\"hljs-string\">a<\/span> <span class=\"hljs-string\">solo<\/span> <span class=\"hljs-string\">traveler<\/span> <span class=\"hljs-string\">visiting<\/span> <span class=\"hljs-string\">Paris.<\/span>\n\n<span class=\"hljs-string\">The<\/span> <span class=\"hljs-string\">traveler<\/span> <span class=\"hljs-string\">is<\/span> <span class=\"hljs-string\">interested<\/span> <span class=\"hljs-string\">in<\/span> <span class=\"hljs-string\">art,<\/span> <span class=\"hljs-string\">history,<\/span> <span class=\"hljs-string\">and<\/span> <span class=\"hljs-string\">local<\/span> <span class=\"hljs-string\">cuisine.<\/span> <span class=\"hljs-string\">They<\/span> <span class=\"hljs-string\">prefer<\/span> <span class=\"hljs-string\">walking<\/span> <span class=\"hljs-string\">and<\/span> <span class=\"hljs-string\">public<\/span> <span class=\"hljs-string\">transportation.<\/span>\n\n<span class=\"hljs-attr\">Follow the steps below:<\/span>\n<span class=\"hljs-bullet\">-<\/span> <span class=\"hljs-string\">Provide<\/span> <span class=\"hljs-string\">a<\/span> <span class=\"hljs-string\">list<\/span> <span class=\"hljs-string\">of<\/span> <span class=\"hljs-string\">must-visit<\/span> <span class=\"hljs-string\">art<\/span> <span class=\"hljs-string\">museums<\/span> <span class=\"hljs-string\">and<\/span> <span class=\"hljs-string\">historical<\/span> <span class=\"hljs-string\">sites.<\/span>\n<span class=\"hljs-bullet\">-<\/span> <span class=\"hljs-string\">Suggest<\/span> <span class=\"hljs-string\">walking<\/span> <span class=\"hljs-string\">routes<\/span> <span class=\"hljs-string\">that<\/span> <span class=\"hljs-string\">connect<\/span> <span class=\"hljs-string\">these<\/span> <span class=\"hljs-string\">attractions<\/span> <span class=\"hljs-string\">efficiently.<\/span>\n<span class=\"hljs-bullet\">-<\/span> <span class=\"hljs-string\">Recommend<\/span> <span class=\"hljs-string\">local<\/span> <span class=\"hljs-string\">restaurants<\/span> <span class=\"hljs-string\">for<\/span> <span class=\"hljs-string\">each<\/span> <span class=\"hljs-string\">day,<\/span> <span class=\"hljs-string\">considering<\/span> <span class=\"hljs-string\">the<\/span> <span class=\"hljs-string\">traveler's<\/span> <span class=\"hljs-string\">preference<\/span> <span class=\"hljs-string\">for<\/span> <span class=\"hljs-string\">diverse<\/span> <span class=\"hljs-string\">cuisine.<\/span>\n\n<span class=\"hljs-string\">Present<\/span> <span class=\"hljs-string\">the<\/span> <span class=\"hljs-string\">itinerary<\/span> <span class=\"hljs-string\">in<\/span> <span class=\"hljs-string\">a<\/span> <span class=\"hljs-string\">clear<\/span> <span class=\"hljs-string\">and<\/span> <span class=\"hljs-string\">organized<\/span> <span class=\"hljs-string\">document,<\/span> <span class=\"hljs-string\">with<\/span> <span class=\"hljs-string\">each<\/span> <span class=\"hljs-string\">day's<\/span> <span class=\"hljs-string\">plan<\/span> <span class=\"hljs-string\">distinctively<\/span> <span class=\"hljs-string\">outlined.<\/span>\n\n<span class=\"hljs-string\">Keep<\/span> <span class=\"hljs-string\">the<\/span> <span class=\"hljs-string\">budget<\/span> <span class=\"hljs-string\">moderate,<\/span> <span class=\"hljs-string\">and<\/span> <span class=\"hljs-string\">consider<\/span> <span class=\"hljs-string\">any<\/span> <span class=\"hljs-string\">current<\/span> <span class=\"hljs-string\">travel<\/span> <span class=\"hljs-string\">restrictions<\/span> <span class=\"hljs-string\">or<\/span> <span class=\"hljs-string\">events<\/span> <span class=\"hljs-string\">in<\/span> <span class=\"hljs-string\">Paris.<\/span>\n\n<span class=\"hljs-string\">Create<\/span> <span class=\"hljs-string\">an<\/span> <span class=\"hljs-string\">engaging<\/span> <span class=\"hljs-string\">and<\/span> <span class=\"hljs-string\">culturally<\/span> <span class=\"hljs-string\">rich<\/span> <span class=\"hljs-string\">itinerary<\/span> <span class=\"hljs-string\">that<\/span> <span class=\"hljs-string\">balances<\/span> <span class=\"hljs-string\">art,<\/span> <span class=\"hljs-string\">history,<\/span> <span class=\"hljs-string\">and<\/span> <span class=\"hljs-string\">local<\/span> <span class=\"hljs-string\">culinary<\/span> <span class=\"hljs-string\">experiences<\/span> <span class=\"hljs-string\">for<\/span> <span class=\"hljs-string\">the<\/span> <span class=\"hljs-string\">solo<\/span> <span class=\"hljs-string\">traveler.<\/span><\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"ab cm acv acw pk hb\" role=\"separator\"><\/div>\n\n\n\n<div class=\"ew tb tc td te\">\n<div class=\"ab cm\">\n<div class=\"hy bg hz ia ib ic\">\n<blockquote class=\"ada\"><p id=\"37fa\" class=\"adb adc tg be add ade adf adg adh adi adj zl dq\" data-selectable-paragraph=\"\"><em class=\"adk\">Want to learn how to build modern software with LLMs using the newest tools and techniques in the field?&nbsp;<\/em><a class=\"af hd\" href=\"https:\/\/www.comet.com\/production\/site\/llm-course\/?utm_source=Heartbeat&amp;utm_medium=referral&amp;utm_content=Medium&amp;utm_campaign=Heartbeat_LangChain_Series_HS\" target=\"_blank\" rel=\"noopener ugc nofollow\"><em class=\"adk\">Check out this free LLMOps course<\/em><\/a><em class=\"adk\">&nbsp;from industry expert Elvis Saravia of DAIR.AI!<\/em><\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"ab cm acv acw pk hb\" role=\"separator\"><\/div>\n\n\n\n<div class=\"ew tb tc td te\">\n<div class=\"ab cm\">\n<div class=\"hy bg hz ia ib ic\">\n<h2 id=\"eee3\" class=\"ya yb tg be yc yd adl tw mk yf adm tz mp yh adn yj yk yl ado yn yo yp adp yr ys yt bj\">II. Building a Shopbot using OpenAI and CometLLM<\/h2>\n<h3 id=\"96c6\" class=\"abz yb tg be yc mg aca mh mk ml acb mm mp mq acc mr mu mv acd mw mz na ace nb ne acf bj\">1. Understanding the Basics<\/h3>\n<p id=\"860c\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\">Before we dive into the code, let\u2019s understand the main components and features of a chatbot. This chatbot, called ShopBot, helps customers find products, provides information, and guides them through the checkout process. It is friendly and helpful and can recommend products based on customer preferences.<\/p>\n<p id=\"0957\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">\ud83d\udc49 Feel free to check out this&nbsp;<\/em><a class=\"af hd\" href=\"https:\/\/github.com\/yennhi95zz\/e-commerce-chatbot-using-openai\" target=\"_blank\" rel=\"noopener ugc nofollow\"><strong class=\"be fx\"><em class=\"zm\">GitHub repository<\/em><\/strong><\/a><em class=\"zm\">&nbsp;as we move forward in the process.<\/em><\/p>\n<h3 id=\"c7db\" class=\"abz yb tg be yc mg aca mh mk ml acb mm mp mq acc mr mu mv acd mw mz na ace nb ne acf bj\">2. Setting Up the Environment<\/h3>\n<p id=\"c98e\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\">First, we\u2019ll use Github Codespace and Python in conjunction with the&nbsp;<strong class=\"be fx\">OpenAI GPT-3.5 Turbo<\/strong>&nbsp;model for natural language processing. Make sure you have the required Python packages installed and obtain your OpenAI API and Comet API keys. (Reference:&nbsp;<a class=\"af hd\" href=\"https:\/\/help.openai.com\/en\/articles\/4936850-where-do-i-find-my-api-key\" target=\"_blank\" rel=\"noopener ugc nofollow\"><em class=\"zm\">OpenAI Help Center \u2014 Where can I find my API key?<\/em><\/a>;&nbsp;<a class=\"af hd\" href=\"https:\/\/www.comet.com\/docs\/v2\/api-and-sdk\/rest-api\/overview\/\" target=\"_blank\" rel=\"noopener ugc nofollow\"><em class=\"zm\">CometLLM \u2014 Obtaining your API key<\/em><\/a>)<\/p>\n<div><\/div>\n<p id=\"42a6\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\">The provided code snippet initializes the required components.<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"b848\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">import<\/span> os\n<span class=\"hljs-keyword\">from<\/span> openai <span class=\"hljs-keyword\">import<\/span> <span class=\"hljs-title.class\">OpenAI<\/span>\n<span class=\"hljs-keyword\">import<\/span> comet_llm\n<span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-title.class\">IPython<\/span>.<span class=\"hljs-property\">display<\/span> <span class=\"hljs-keyword\">import<\/span> display\n<span class=\"hljs-keyword\">import<\/span> ipywidgets <span class=\"hljs-keyword\">as<\/span> widgets\n<span class=\"hljs-keyword\">import<\/span> time\n<span class=\"hljs-keyword\">import<\/span> dotenv <\/span><\/pre>\n<pre class=\"adq acn acm aco bo acp ba bj\"><span id=\"04d9\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\"><span class=\"hljs-comment\"># Input API keys<\/span>\n\nMY_OPENAI_KEY = os.getenv(<span class=\"hljs-string\">'MY_OPENAI_KEY'<\/span>)\nMY_COMET_KEY = os.getenv(<span class=\"hljs-string\">'MY_COMET_KEY'<\/span>)\n\n\ncomet_llm.init(project=<span class=\"hljs-string\">\"ecom_shopbot_openai\"<\/span>,\n               api_key=MY_COMET_KEY)<\/span><\/pre>\n<h3 id=\"3ba5\" class=\"abz yb tg be yc mg aca mh mk ml acb mm mp mq acc mr mu mv acd mw mz na ace nb ne acf bj\">3. Defining Product Information<\/h3>\n<p id=\"d2ad\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\">The e-commerce chatbot needs information about the products available in your store. Product list includes details such as name, price, available sizes, colors, etc. This information is stored in a structured format, making it easier for chatbots to provide accurate details to customers.<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"f085\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\">product_list = <span class=\"hljs-string\">'''\n# Fashion Shop Product List\n\n## Women's Clothing:\n- T-shirt\n  - Price: $20\n  - Available Sizes: Small, Medium, Large, XL\n  - Available Colors: Red, White, Black, Gray, Navy\n\n# ... (Other product categories and details)\n'''<\/span><\/span><\/pre>\n<div><\/div>\n<p id=\"4364\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\">This step allows you to enter the product list for your store. Keep in mind that the more complex your product list, the more detailed its&nbsp;<code class=\"eg acj ack acl acm b\">context<\/code>&nbsp;needs to be so that the generative AI can clearly understand its requirements.<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"f752\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\">context = [{<span class=\"hljs-string\">'role'<\/span>: <span class=\"hljs-string\">'system'<\/span>,\n            <span class=\"hljs-string\">'content'<\/span>: <span class=\"hljs-string\">f\"\"\"\nYou are ShopBot, an AI assistant for my online fashion shop - Nhi Yen.\n\nYour role is to assist customers in browsing products, providing information, and guiding them through the checkout process.\n\nBe friendly and helpful in your interactions.\n\nWe offer a variety of products across categories such as Women's Clothing, Men's clothing, Accessories, Kids' Collection, Footwears and Activewear products.\n\nFeel free to ask customers about their preferences, recommend products, and inform them about any ongoing promotions.\n\nThe Current Product List is limited as below:\n\n```<span class=\"hljs-subst\">{product_list}<\/span>```\n\nMake the shopping experience enjoyable and encourage customers to reach out if they have any questions or need assistance.\n\"\"\"<\/span>}]<\/span><\/pre>\n<h3 id=\"8f39\" class=\"abz yb tg be yc mg aca mh mk ml acb mm mp mq acc mr mu mv acd mw mz na ace nb ne acf bj\">4. Creating the Chatbot<\/h3>\n<p id=\"e443\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\">After you configure your environment and define your product information, you can create your ShopBot chatbot. The&nbsp;<code class=\"eg acj ack acl acm b\">get_completion_from_messages<\/code>&nbsp;function sends messages to the OpenAI GPT-3.5 Turbo model and retrieves responses from the model.<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"f9df\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\"><span class=\"hljs-function\">def <span class=\"hljs-title\">get_completion_from_messages<\/span><span class=\"hljs-params\">(messages, model=<span class=\"hljs-string\">\"gpt-3.5-turbo\"<\/span>)<\/span>:\n    client =<\/span> <span class=\"hljs-built_in\">OpenAI<\/span>(\n        api_key=MY_OPENAI_KEY,\n    )\n\n    chat_completion = client.chat.completions.<span class=\"hljs-built_in\">create<\/span>(\n        messages=messages,\n        model=model,\n    )\n    <span class=\"hljs-keyword\">return<\/span> chat_completion.choices[<span class=\"hljs-number\">0<\/span>].message.content<\/span><\/pre>\n<h3 id=\"6e4d\" class=\"abz yb tg be yc mg aca mh mk ml acb mm mp mq acc mr mu mv acd mw mz na ace nb ne acf bj\">5. Interacting with Customers<\/h3>\n<p id=\"920a\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\">To interact with customers, use a simple user interface with text entry for customer messages and a button to start a conversation. The&nbsp;<code class=\"eg acj ack acl acm b\">collect_messages<\/code>&nbsp;function processes user input, updates conversation context, and displays chat history.<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"9a14\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\"><span class=\"hljs-comment\"># Interacting with Customers<\/span>\n\n<span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title.function\">collect_messages<\/span>(<span class=\"hljs-params\">_<\/span>):\n    user_input = inp.value\n    inp.value = <span class=\"hljs-string\">''<\/span>\n    context.append({<span class=\"hljs-string\">'role'<\/span>:<span class=\"hljs-string\">'user'<\/span>, <span class=\"hljs-string\">'content'<\/span>:<span class=\"hljs-string\">f\"<span class=\"hljs-subst\">{user_input}<\/span>\"<\/span>})\n\n    <span class=\"hljs-comment\"># Record the start time<\/span>\n    start_time = time.time()\n\n    response = get_completion_from_messages(context)\n\n    <span class=\"hljs-comment\"># Record the end time<\/span>\n    end_time = time.time()\n\n    <span class=\"hljs-comment\"># Calculate the duration<\/span>\n    duration = end_time - start_time\n\n    <span class=\"hljs-comment\"># Log to comet_llm<\/span>\n    comet_llm.log_prompt(\n        prompt=user_input,\n        output=response,\n        duration=duration,\n        metadata={\n        <span class=\"hljs-string\">\"role\"<\/span>: context[-<span class=\"hljs-number\">1<\/span>][<span class=\"hljs-string\">'role'<\/span>],\n        <span class=\"hljs-string\">\"content\"<\/span>: context[-<span class=\"hljs-number\">1<\/span>][<span class=\"hljs-string\">'content'<\/span>],\n        <span class=\"hljs-string\">\"context\"<\/span>: context,\n        <span class=\"hljs-string\">\"product_list\"<\/span>: product_list\n        },\n\n    )\n\n    context.append({<span class=\"hljs-string\">'role'<\/span>: <span class=\"hljs-string\">'assistant'<\/span>, <span class=\"hljs-string\">'content'<\/span>: <span class=\"hljs-string\">f\"<span class=\"hljs-subst\">{response}<\/span>\"<\/span>})\n\n    user_pane = widgets.Output()\n    <span class=\"hljs-keyword\">with<\/span> user_pane:\n        display(widgets.HTML(<span class=\"hljs-string\">f\"&lt;b&gt;User:&lt;\/b&gt; <span class=\"hljs-subst\">{user_input}<\/span>\"<\/span>))\n\n    assistant_pane = widgets.Output()\n    <span class=\"hljs-keyword\">with<\/span> assistant_pane:\n        display(widgets.HTML(<span class=\"hljs-string\">f\"&lt;b&gt;Assistant:&lt;\/b&gt; <span class=\"hljs-subst\">{response}<\/span>\"<\/span>))\n\n    display(widgets.VBox([user_pane, assistant_pane]))\n\ninp = widgets.Text(value=<span class=\"hljs-string\">\"Hi\"<\/span>, placeholder=<span class=\"hljs-string\">'Enter text here\u2026'<\/span>)\nbutton_conversation = widgets.Button(description=<span class=\"hljs-string\">\"Chat!\"<\/span>)\nbutton_conversation.on_click(collect_messages)\n\ndashboard = widgets.VBox([inp, button_conversation])\n\ndisplay(dashboard)<\/span><\/pre>\n<p id=\"fc68\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\">Let\u2019s play with the bot. Tailor the context to your own needs by following the&nbsp;<strong class=\"be fx\">Prompting for Developers: A Guideline<\/strong>&nbsp;above.<\/p>\n<figure class=\"abe abf abg abh abi abj lp lq paragraph-image\">\n<div class=\"abk abl dl abm bg abn\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg xl abo c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*T8j34K4GwukNZsNc2D-b_g.gif\" alt=\"\" width=\"700\" height=\"281\"><\/figure><div class=\"lp lq adr\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*T8j34K4GwukNZsNc2D-b_g.gif 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*T8j34K4GwukNZsNc2D-b_g.gif 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*T8j34K4GwukNZsNc2D-b_g.gif 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*T8j34K4GwukNZsNc2D-b_g.gif 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*T8j34K4GwukNZsNc2D-b_g.gif 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*T8j34K4GwukNZsNc2D-b_g.gif 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*T8j34K4GwukNZsNc2D-b_g.gif 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*T8j34K4GwukNZsNc2D-b_g.gif 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*T8j34K4GwukNZsNc2D-b_g.gif 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*T8j34K4GwukNZsNc2D-b_g.gif 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*T8j34K4GwukNZsNc2D-b_g.gif 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*T8j34K4GwukNZsNc2D-b_g.gif 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*T8j34K4GwukNZsNc2D-b_g.gif 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*T8j34K4GwukNZsNc2D-b_g.gif 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div><figcaption class=\"abp fp abq lp lq abr abs be b bf z dq\" data-selectable-paragraph=\"\">Demo Shopbot (Image by Author)<\/figcaption><\/figure>\n<p id=\"6709\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\">In this project, I\u2019m using&nbsp;<code class=\"eg acj ack acl acm b\">comet_llm<\/code>&nbsp;to keep track of what users ask, how the bot responds, and how long each interaction takes. The information is logged to this&nbsp;<a class=\"af hd\" href=\"https:\/\/www.comet.com\/yennhi95zz\/ecom-shopbot-openai\" target=\"_blank\" rel=\"noopener ugc nofollow\"><strong class=\"be fx\"><em class=\"zm\">comet project<\/em><\/strong><\/a>. This helps in improving the model for future training. You can learn more about experiment tracking with&nbsp;<a class=\"af hd\" href=\"https:\/\/github.com\/comet-ml\/comet-llm\" target=\"_blank\" rel=\"noopener ugc nofollow\">Comet LLM<\/a>.<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"d44f\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\">    <span class=\"hljs-comment\"># Log to comet_llm<\/span>\n    comet_llm.log_prompt(\n        prompt=user_input,\n        output=response,\n        duration=duration,\n        metadata={\n        <span class=\"hljs-string\">\"role\"<\/span>: context[-<span class=\"hljs-number\">1<\/span>][<span class=\"hljs-string\">'role'<\/span>],\n        <span class=\"hljs-string\">\"content\"<\/span>: context[-<span class=\"hljs-number\">1<\/span>][<span class=\"hljs-string\">'content'<\/span>],\n        <span class=\"hljs-string\">\"context\"<\/span>: context,\n        <span class=\"hljs-string\">\"product_list\"<\/span>: product_list\n        },\n    )<\/span><\/pre>\n<p id=\"8230\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\">The logs in the Comet UI appear like this. By analyzing these logs, you can use various strategies to make responses quicker, improve accuracy, enhance customer satisfaction, and eliminate unnecessary steps in your ecommerce operations.<\/p>\n<figure class=\"abe abf abg abh abi abj lp lq paragraph-image\">\n<div class=\"abk abl dl abm bg abn\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg xl abo c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*bNHc_2A67fPdPTyGtiqWJw.png\" alt=\"\" width=\"700\" height=\"261\"><\/figure><div class=\"lp lq ads\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*bNHc_2A67fPdPTyGtiqWJw.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*bNHc_2A67fPdPTyGtiqWJw.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*bNHc_2A67fPdPTyGtiqWJw.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*bNHc_2A67fPdPTyGtiqWJw.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*bNHc_2A67fPdPTyGtiqWJw.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*bNHc_2A67fPdPTyGtiqWJw.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*bNHc_2A67fPdPTyGtiqWJw.png 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*bNHc_2A67fPdPTyGtiqWJw.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*bNHc_2A67fPdPTyGtiqWJw.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*bNHc_2A67fPdPTyGtiqWJw.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*bNHc_2A67fPdPTyGtiqWJw.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*bNHc_2A67fPdPTyGtiqWJw.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*bNHc_2A67fPdPTyGtiqWJw.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*bNHc_2A67fPdPTyGtiqWJw.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div>\n<figcaption class=\"abp fp abq lp lq abr abs be b bf z dq\" data-selectable-paragraph=\"\">Further LLM training based on the logs (Image by Author)<\/figcaption>\n<\/figure>\n<p id=\"0979\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\"><em class=\"zm\">Additional<\/em><\/strong>: Summarize the order details and send to the user and the respective departments as follows:<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"17a3\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\">messages =  context.<span class=\"hljs-built_in\">copy<\/span>()\nmessages.<span class=\"hljs-built_in\">append<\/span>(\n{<span class=\"hljs-string\">'role'<\/span>:<span class=\"hljs-string\">'system'<\/span>\n , <span class=\"hljs-string\">'content'<\/span>:<span class=\"hljs-string\">'create a table summary of the previous order.'<\/span>}\n)\n\nresponse = get_completion_from_messages(messages)\n<span class=\"hljs-built_in\">print<\/span>(response)<\/span><\/pre>\n<p id=\"1a1f\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\">Output:<\/p>\n<pre class=\"abe abf abg abh abi acn acm aco bo acp ba bj\"><span id=\"bd99\" class=\"acq yb tg acm b bf acr acs l act acu\" data-selectable-paragraph=\"\"><span class=\"hljs-string\">Certainly!<\/span> <span class=\"hljs-string\">Here's<\/span> <span class=\"hljs-attr\">a summary of your previous order:<\/span>\n\n<span class=\"hljs-string\">|<\/span>     <span class=\"hljs-string\">Product<\/span> <span class=\"hljs-string\">Name<\/span>    <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-string\">Type<\/span>   <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-string\">Size<\/span>   <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-string\">Color<\/span>   <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-string\">Price<\/span>   <span class=\"hljs-string\">|<\/span>\n<span class=\"hljs-string\">|---------------------|----------|----------|-----------|-----------|<\/span>\n<span class=\"hljs-string\">|<\/span>     <span class=\"hljs-string\">Red<\/span> <span class=\"hljs-string\">T-shirt<\/span>     <span class=\"hljs-string\">|<\/span>  <span class=\"hljs-string\">Women<\/span>   <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-string\">Small<\/span>  <span class=\"hljs-string\">|<\/span>    <span class=\"hljs-string\">Red<\/span>    <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-string\">$20<\/span>     <span class=\"hljs-string\">|<\/span>\n<span class=\"hljs-string\">|<\/span> <span class=\"hljs-string\">Comfortable<\/span> <span class=\"hljs-string\">Sneakers|<\/span>  <span class=\"hljs-string\">Women<\/span>   <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-number\">12<\/span>     <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-string\">Black<\/span>   <span class=\"hljs-string\">|<\/span>   <span class=\"hljs-string\">$55<\/span>     <span class=\"hljs-string\">|<\/span>\n\n<span class=\"hljs-string\">If<\/span> <span class=\"hljs-string\">you<\/span> <span class=\"hljs-string\">have<\/span> <span class=\"hljs-string\">any<\/span> <span class=\"hljs-string\">other<\/span> <span class=\"hljs-string\">questions<\/span> <span class=\"hljs-string\">or<\/span> <span class=\"hljs-string\">need<\/span> <span class=\"hljs-string\">further<\/span> <span class=\"hljs-string\">assistance,<\/span> <span class=\"hljs-string\">please<\/span> <span class=\"hljs-string\">let<\/span> <span class=\"hljs-string\">me<\/span> <span class=\"hljs-string\">know.<\/span><\/span><\/pre>\n<h2 id=\"df27\" class=\"ya yb tg be yc yd ye tw mk yf yg tz mp yh yi yj yk yl ym yn yo yp yq yr ys yt bj\"><strong class=\"al\">III. Reference<\/strong><\/h2>\n<ul class=\"\">\n<li id=\"1954\" class=\"yu yv tg be b tu yw yx yy tx yz za zb mq acg zd ze mv ach zg zh na aci zj zk zl adt zw zx bj\" data-selectable-paragraph=\"\">Find the complete code on this&nbsp;<a class=\"af hd\" href=\"https:\/\/github.com\/yennhi95zz\/e-commerce-chatbot-using-openai\/tree\/main\" target=\"_blank\" rel=\"noopener ugc nofollow\"><strong class=\"be fx\">GitHub repository<\/strong><\/a>.<\/li>\n<li id=\"208c\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl adt zw zx bj\" data-selectable-paragraph=\"\">Explore a detailed explanation in my&nbsp;<a class=\"af hd\" href=\"https:\/\/heartbeat.comet.ml\/how-to-create-a-simple-chatbot-for-e-commerce-using-openai-aa0539b9875b\" target=\"_blank\" rel=\"noopener ugc nofollow\"><strong class=\"be fx\">Medium article<\/strong><\/a>.<\/li>\n<\/ul>\n<p id=\"ac7d\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\">For a more advanced e-commerce chatbot, additional training is necessary.&nbsp;<a class=\"af hd\" href=\"https:\/\/www.comet.com\/site\/products\/llmops\/\" target=\"_blank\" rel=\"noopener ugc nofollow\"><strong class=\"be fx\"><em class=\"zm\">Comet LLM<\/em><\/strong><\/a>&nbsp;simplifies the development of chatbot language models and improves workflow by serving as a valuable tool for logging and viewing messages and threads. It helps you identify effective strategies, streamline problem solving, ensure reproducibility of workflows, and provides insights for efficient model development and optimization.<\/p>\n<p id=\"5946\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">\ud83d\udc49 Explore Comet in action by reviewing my past hands-on projects.<\/em><\/p>\n<ul class=\"\">\n<li id=\"6efe\" class=\"yu yv tg be b tu zn yx yy tx zo za zb mq zs zd ze mv zt zg zh na zu zj zk zl adt zw zx bj\" data-selectable-paragraph=\"\"><a class=\"af hd\" href=\"https:\/\/heartbeat.comet.ml\/a-hands-on-project-enhancing-customer-churn-prediction-with-continuous-experiment-tracking-in-77aeaff242f7\" target=\"_blank\" rel=\"noopener ugc nofollow\"><em class=\"zm\">Enhancing Customer Churn Prediction with Continuous Experiment Tracking<\/em><\/a><\/li>\n<li id=\"6d0f\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl adt zw zx bj\" data-selectable-paragraph=\"\"><a class=\"af hd\" href=\"https:\/\/heartbeat.comet.ml\/hyperparameter-tuning-in-machine-learning-a-key-to-optimize-model-performance-1d520934bb99\" target=\"_blank\" rel=\"noopener ugc nofollow\"><em class=\"zm\">Hyperparameter Tuning in Machine Learning: A Key to Optimize Model Performance<\/em><\/a><\/li>\n<li id=\"36ca\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl adt zw zx bj\" data-selectable-paragraph=\"\"><a class=\"af hd\" href=\"https:\/\/medium.com\/mlearning-ai\/the-magic-of-model-stacking-boosting-machine-learning-performance-2f6719a0bfd8\" rel=\"noopener\"><em class=\"zm\">The Magic of Model Stacking: Boosting Machine Learning Performance<\/em><\/a><\/li>\n<li id=\"918e\" class=\"yu yv tg be b tu zy yx yy tx zz za zb mq aba zd ze mv abb zg zh na abc zj zk zl adt zw zx bj\" data-selectable-paragraph=\"\"><a class=\"af hd\" href=\"https:\/\/medium.com\/p\/e1eb04e74eb5\" rel=\"noopener\"><em class=\"zm\">Logging \u2014 The Effective Management of Machine Learning Systems<\/em><\/a><\/li>\n<\/ul>\n<h2 id=\"a4ee\" class=\"ya yb tg be yc yd ye tw mk yf yg tz mp yh yi yj yk yl ym yn yo yp yq yr ys yt bj\">Conclusion<\/h2>\n<p id=\"b250\" class=\"pw-post-body-paragraph yu yv tg be b tu yw yx yy tx yz za zb mq zc zd ze mv zf zg zh na zi zj zk zl ew bj\" data-selectable-paragraph=\"\">With this simple chatbot, e-commerce stores can offer their customers a personalized and interactive shopping experience. Don\u2019t forget to continually improve and expand your chatbot\u2019s functionality based on user feedback and evolving business needs. Incorporating chatbots into your platform can improve customer satisfaction, increase sales, and make the online purchasing process more enjoyable for everyone involved.<\/p>\n<p id=\"5ed0\" class=\"pw-post-body-paragraph yu yv tg be b tu zn yx yy tx zo za zb mq zp zd ze mv zq zg zh na zr zj zk zl ew bj\" data-selectable-paragraph=\"\"><em class=\"zm\">#ChatbotDevelopment #EcommerceChatbot #OpenAI #SimpleChatbot #NoDeepLearning<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"ab cm acv acw pk hb\" role=\"separator\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Forget about complicated Deep Learning algorithms \u2014 making a chatbot is way simpler with OpenAI and CometLLM Table of Contents Introduction I. Prompting for Developers: A Guideline II. Building a Shopbot using OpenAI and CometLLM Understanding the Basics Setting Up the Environment Defining Product Information Creating the Chatbot Interacting with Customers III. Reference Conclusion Introduction [&hellip;]<\/p>\n","protected":false},"author":95,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","footnotes":""},"categories":[65,9,7],"tags":[72,40,14,64,15,73,71,52,31,33,34],"coauthors":[192],"class_list":["post-8189","post","type-post","status-publish","format-standard","hentry","category-llmops","category-product","category-tutorials","tag-chatbots","tag-comet","tag-comet-ml","tag-cometllm","tag-deep-learning-experiment-management","tag-e-commerce","tag-language-models","tag-llm","tag-llmops","tag-openai","tag-prompt-engineering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create a Simple E-commerce Chatbot With OpenAI - Comet<\/title>\n<meta name=\"description\" content=\"Forget about complicated Deep Learning algorithms\u200a-\u200amaking an e-commerce chatbot is way simpler with OpenAI and CometLLM\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create a Simple E-commerce Chatbot With OpenAI\" \/>\n<meta property=\"og:description\" content=\"Forget about complicated Deep Learning algorithms\u200a-\u200amaking an e-commerce chatbot is way simpler with OpenAI and CometLLM\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-23T01:27:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T17:04:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*RPJnm1-q-d7dJoTK.png\" \/>\n<meta name=\"author\" content=\"Nhi Yen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Cometml\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nhi Yen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Create a Simple E-commerce Chatbot With OpenAI - Comet","description":"Forget about complicated Deep Learning algorithms\u200a-\u200amaking an e-commerce chatbot is way simpler with OpenAI and CometLLM","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/","og_locale":"en_US","og_type":"article","og_title":"Create a Simple E-commerce Chatbot With OpenAI","og_description":"Forget about complicated Deep Learning algorithms\u200a-\u200amaking an e-commerce chatbot is way simpler with OpenAI and CometLLM","og_url":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2023-11-23T01:27:55+00:00","article_modified_time":"2025-04-24T17:04:22+00:00","og_image":[{"url":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*RPJnm1-q-d7dJoTK.png","type":"","width":"","height":""}],"author":"Nhi Yen","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Nhi Yen","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/"},"author":{"name":"Nhi Yen","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/1a873c6cf609e07d582cd696f147609b"},"headline":"Create a Simple E-commerce Chatbot With OpenAI","datePublished":"2023-11-23T01:27:55+00:00","dateModified":"2025-04-24T17:04:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/"},"wordCount":1156,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*RPJnm1-q-d7dJoTK.png","keywords":["Chatbots","Comet","Comet ML","CometLLM","Deep Learning Experiment Management","E-commerce","Language Models","LLM","LLMOps","OpenAI","Prompt Engineering"],"articleSection":["LLMOps","Product","Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/","url":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/","name":"Create a Simple E-commerce Chatbot With OpenAI - Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*RPJnm1-q-d7dJoTK.png","datePublished":"2023-11-23T01:27:55+00:00","dateModified":"2025-04-24T17:04:22+00:00","description":"Forget about complicated Deep Learning algorithms\u200a-\u200amaking an e-commerce chatbot is way simpler with OpenAI and CometLLM","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/#primaryimage","url":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*RPJnm1-q-d7dJoTK.png","contentUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*RPJnm1-q-d7dJoTK.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/create-a-simple-e-commerce-chatbot-with-openai\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"Create a Simple E-commerce Chatbot With OpenAI"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/1a873c6cf609e07d582cd696f147609b","name":"Nhi Yen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/cbe7005c33fc937d23d6bbbff99e5223","url":"https:\/\/secure.gravatar.com\/avatar\/ec9f8f996211d944f352679e89c48b4cdaf7a1609d7409846408ac93045893d9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ec9f8f996211d944f352679e89c48b4cdaf7a1609d7409846408ac93045893d9?s=96&d=mm&r=g","caption":"Nhi Yen"},"url":"https:\/\/www.comet.com\/site\/blog\/author\/nhi-yen\/"}]}},"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/95"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=8189"}],"version-history":[{"count":1,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8189\/revisions"}],"predecessor-version":[{"id":15446,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8189\/revisions\/15446"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=8189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=8189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=8189"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=8189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}