-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathSelectAI4Py -1- Chat.dsnb
More file actions
1 lines (1 loc) · 36.4 KB
/
SelectAI4Py -1- Chat.dsnb
File metadata and controls
1 lines (1 loc) · 36.4 KB
1
[{"layout":"jupyter","isRunnable":true,"template":null,"templateConfig":null,"isEditable":true,"name":"SelectAI4Py -1- Chat","description":null,"type":"low","paragraphs":[{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":null,"title":null,"message":[],"enabled":true,"result":{"startTime":1760327940331,"interpreter":"md.low","endTime":1760327940773,"results":[],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":true,"width":0,"hideResult":true,"dynamicFormParams":"{}","row":0,"hasTitle":false,"hideVizConfig":true,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"html","title":null,"message":["%md","# Using Select AI for Chat-Based LLM Interactions ","","Select AI enables you to interact with large language models (LLMs) directly from your database through natural language prompts. ","The `chat` action sends your prompt to the LLM and returns the response, supporting more traditional chatbot-like interactions.","","The `chat` action provides your prompt to the LLM without augmentation - supporting a wide range of use cases, for example:","","* Content generation","* Question answering","* Information extraction","* Sentiment analysis","* Chatbot/conversation","* Content translation","* Document summarization","* Write email responses","* Code generation","* Discover topics/themes","","You can apply manual prompt engineering techniques to customize results.","","---","Copyright (c) 2025 Oracle Corporation ","###### [The Universal Permissive License (UPL), Version 1.0](https://oss.oracle.com/licenses/upl/)"],"enabled":true,"result":{"startTime":1760327941139,"interpreter":"md.low","endTime":1760327941476,"results":[{"message":"<h1 id=\"using-select-ai-for-chat-based-llm-interactions\">Using Select AI for Chat-Based LLM Interactions<\/h1>\n<p>Select AI enables you to interact with large language models (LLMs) directly from your database through natural language prompts.\nThe <code>chat<\/code> action sends your prompt to the LLM and returns the response, supporting more traditional chatbot-like interactions.<\/p>\n<p>The <code>chat<\/code> action provides your prompt to the LLM without augmentation - supporting a wide range of use cases, for example:<\/p>\n<ul>\n<li>Content generation<\/li>\n<li>Question answering<\/li>\n<li>Information extraction<\/li>\n<li>Sentiment analysis<\/li>\n<li>Chatbot/conversation<\/li>\n<li>Content translation<\/li>\n<li>Document summarization<\/li>\n<li>Write email responses<\/li>\n<li>Code generation<\/li>\n<li>Discover topics/themes<\/li>\n<\/ul>\n<p>You can apply manual prompt engineering techniques to customize results.<\/p>\n<hr />\n<p>Copyright (c) 2025 Oracle Corporation<\/p>\n<h6 id=\"the-universal-permissive-license-upl-version-10\"><a href=\"https://oss.oracle.com/licenses/upl/\">The Universal Permissive License (UPL), Version 1.0<\/a><\/h6>\n","type":"HTML"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":true,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":false,"hideVizConfig":true,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"html","title":null,"message":["%md","### For more information...","","<a href=\"https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/pysai/index.html\" target=\"_blank\">Select AI for Python documentation<\/a>"],"enabled":true,"result":{"startTime":1760327941857,"interpreter":"md.low","endTime":1760327942267,"results":[{"message":"<h3 id=\"for-more-information\">For more information...<\/h3>\n<p><a href=\"https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/pysai/index.html\" target=\"_blank\">Select AI for Python documentation<\/a><\/p>\n","type":"HTML"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":true,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":false,"hideVizConfig":true,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"html","title":null,"message":["%md","## Prerequisites","","Before proceeding, you must complete the required setup steps in the **SelectAI4Py -0- Prerequisites and Setup** notebook:","","* ADMIN: grants and network access","* Select AI user: OCI_GENAI_PY_DEMO profile definition","","These steps are required for the chat commands in this notebook to run correctly."],"enabled":true,"result":{"startTime":1760327942634,"interpreter":"md.low","endTime":1760327942960,"results":[{"message":"<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<p>Before proceeding, you must complete the required setup steps in the <strong>SelectAI4Py -0- Prerequisites and Setup<\/strong> notebook:<\/p>\n<ul>\n<li>ADMIN: grants and network access<\/li>\n<li>Select AI user: OCI_GENAI_PY_DEMO profile definition<\/li>\n<\/ul>\n<p>These steps are required for the chat commands in this notebook to run correctly.<\/p>\n","type":"HTML"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":true,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":false,"hideVizConfig":true,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"html","title":"Create a profile proxy object for the current session","message":["%python","","import select_ai","","profile = select_ai.Profile(profile_name = \"OCI_GENAI_PY_DEMO\")"],"enabled":true,"result":{"startTime":1760327943346,"interpreter":"python.low","endTime":1760327943716,"results":[],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Use 'chat' to learn about Autonomous Database","message":["%python","","response = profile.chat(prompt = \"What is Oracle Autonomous Database?\")","print(response)"],"enabled":true,"result":{"startTime":1760327944101,"interpreter":"python.low","endTime":1760327960999,"results":[{"message":"Oracle Autonomous Database is a cloud-based database service that uses artificial intelligence (AI) and machine learning (ML) to automate many of the tasks associated with managing a database. It is a self-driving, self-securing, and self-repairing database that eliminates the need for manual database administration, allowing users to focus on higher-level tasks.\n\nKey features of Oracle Autonomous Database include:\n\n1. **Autonomous Operations**: The database automatically performs tasks such as provisioning, patching, upgrading, and tuning, without human intervention.\n2. **Self-Driving**: The database can automatically optimize its own performance, adjust to changing workloads, and detect and respond to security threats.\n3. **Self-Securing**: The database includes advanced security features, such as encryption, access control, and auditing, to protect sensitive data.\n4. **Self-Repairing**: The database can automatically detect and repair errors, reducing downtime and improving overall availability.\n5. **Machine Learning**: The database uses machine learning algorithms to analyze usage patterns, predict performance, and optimize resource allocation.\n6. **Cloud-Native**: The database is designed to run on Oracle Cloud Infrastructure (OCI), providing a scalable, on-demand, and pay-as-you-go pricing model.\n\nOracle Autonomous Database offers several benefits, including:\n\n1. **Reduced Administration**: Automated database management reduces the need for manual intervention, freeing up DBAs to focus on higher-level tasks.\n2. **Improved Performance**: The database's self-optimizing capabilities ensure optimal performance, even in complex and dynamic environments.\n3. **Enhanced Security**: Advanced security features and automated patching reduce the risk of security breaches and data loss.\n4. **Increased Availability**: Self-repairing capabilities minimize downtime, ensuring high availability and reliability.\n5. **Lower Costs**: Automated management and optimized resource allocation reduce operational costs and improve ROI.\n\nOracle Autonomous Database is available in several editions, including:\n\n1. **Autonomous Transaction Processing (ATP)**: Optimized for transactional workloads, such as OLTP and real-time analytics.\n2. **Autonomous Data Warehouse (ADW)**: Optimized for data warehousing and analytics workloads.\n3. **Autonomous JSON Database**: Optimized for JSON data storage and processing.\n\nOverall, Oracle Autonomous Database represents a significant shift in the way databases are managed and operated, enabling organizations to focus on innovation and growth, rather than manual database administration.\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Use conversation history to find out when \"it\" was released","message":["%python","","# Adds previous prompt to this prompt in a \"conversation\", which is provided to the LLM","response = profile.chat(prompt = \"when was it first released?\")","print(response)"],"enabled":true,"result":{"startTime":1760327961379,"interpreter":"python.low","endTime":1760327967454,"results":[{"message":"Oracle Autonomous Database was first released in March 2018, as part of Oracle Cloud Infrastructure (OCI). It was initially announced by Oracle CEO Mark Hurd at the Oracle OpenWorld conference in October 2017, and was made generally available to customers in March 2018.\n\nAt the time of its release, Oracle Autonomous Database was available in two main services:\n\n1. **Autonomous Data Warehouse (ADW)**: Released in March 2018, ADW was the first autonomous database service to be made available, and was designed to support data warehousing and analytics workloads.\n2. **Autonomous Transaction Processing (ATP)**: Released in August 2018, ATP was the second autonomous database service to be made available, and was designed to support transactional workloads, such as OLTP and real-time analytics.\n\nSince its initial release, Oracle Autonomous Database has undergone several updates and enhancements, with new features and services being added regularly.\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Use conversation history to learn how \"it\" integrates with Oracle Cloud services","message":["%python","","response = profile.chat(prompt = \"How does it integrate with other Oracle Cloud services?\")","print(response)"],"enabled":true,"result":{"startTime":1760327967839,"interpreter":"python.low","endTime":1760327985832,"results":[{"message":"Oracle Autonomous Database integrates seamlessly with other Oracle Cloud services, enabling a wide range of use cases and applications. Here are some examples of how it integrates with other Oracle Cloud services:\n\n1. **Oracle Cloud Infrastructure (OCI)**: Autonomous Database is built on top of OCI, which provides a scalable, secure, and high-performance infrastructure for the database.\n2. **Oracle Cloud Applications**: Autonomous Database can be used as a database service for Oracle Cloud Applications, such as Oracle ERP Cloud, Oracle HCM Cloud, and Oracle CX Cloud.\n3. **Oracle Analytics Cloud**: Autonomous Database can be used as a data source for Oracle Analytics Cloud, which provides a comprehensive analytics platform for data visualization, reporting, and machine learning.\n4. **Oracle Machine Learning**: Autonomous Database can be used with Oracle Machine Learning, which provides a platform for building, deploying, and managing machine learning models.\n5. **Oracle Data Integration**: Autonomous Database can be used with Oracle Data Integration, which provides a platform for integrating data from multiple sources, transforming data, and loading data into the database.\n6. **Oracle GoldenGate**: Autonomous Database can be used with Oracle GoldenGate, which provides a platform for real-time data integration and replication.\n7. **Oracle API Gateway**: Autonomous Database can be used with Oracle API Gateway, which provides a platform for creating, managing, and securing APIs.\n8. **Oracle Identity Cloud Service**: Autonomous Database can be used with Oracle Identity Cloud Service, which provides a platform for identity and access management.\n\nSome of the key integration benefits include:\n\n1. **Simplified Data Management**: Autonomous Database can be used to manage data from multiple Oracle Cloud services, providing a single source of truth for data.\n2. **Improved Analytics**: Autonomous Database can be used to provide real-time analytics and insights to Oracle Cloud Applications and other services.\n3. **Enhanced Security**: Autonomous Database can be used to provide advanced security features, such as encryption and access control, to Oracle Cloud services.\n4. **Increased Agility**: Autonomous Database can be used to provide rapid provisioning and deployment of databases, enabling faster time-to-market for Oracle Cloud services.\n5. **Better Decision-Making**: Autonomous Database can be used to provide real-time data and insights to Oracle Cloud services, enabling better decision-making and improved business outcomes.\n\nSome of the key use cases for Autonomous Database integration with other Oracle Cloud services include:\n\n1. **Real-time Analytics**: Using Autonomous Database with Oracle Analytics Cloud to provide real-time analytics and insights to Oracle Cloud Applications.\n2. **Data Warehousing**: Using Autonomous Database with Oracle Data Integration to integrate data from multiple sources and load it into a data warehouse.\n3. **Machine Learning**: Using Autonomous Database with Oracle Machine Learning to build, deploy, and manage machine learning models.\n4. **API-First Development**: Using Autonomous Database with Oracle API Gateway to create, manage, and secure APIs for Oracle Cloud services.\n5. **Cloud-Native Applications**: Using Autonomous Database with Oracle Cloud Infrastructure to build cloud-native applications that are scalable, secure, and high-performance.\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"html","title":null,"message":["%md","","#### Use GENERATE for dynamic action selection","","The `generate()` method handles different Select AI actions specified as an argument. Additional parameters like conversation IDs can be passed for context-aware ","conversations. ","","The example below uses the 'chat' action to generate a promotional email from structured prompts."],"enabled":true,"result":{"startTime":1760327986218,"interpreter":"md.low","endTime":1760327986560,"results":[{"message":"<h4 id=\"use-generate-for-dynamic-action-selection\">Use GENERATE for dynamic action selection<\/h4>\n<p>The <code>generate()<\/code> method handles different Select AI actions specified as an argument. Additional parameters like conversation IDs can be passed for context-aware\nconversations.<\/p>\n<p>The example below uses the 'chat' action to generate a promotional email from structured prompts.<\/p>\n","type":"HTML"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":true,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":false,"hideVizConfig":true,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Generate a promotional email using 'chat'","message":["%python","","prompt = \"\"\"Create a promotional email with a catchy subject line and convincing email text. Follow the task rules:","{"," \"task\": \"Draft a promotional message for a new eco-friendly travel mug\","," \"task_rules\": \"1. Highlight its reusable and sustainable features."," 2. Use a friendly and engaging tone."," 3. Suggest a limited-time discount to encourage quick action.,"," 4. Include friendly, uplifting emoticons\","," \"audience\": \"General consumers interested in sustainable living\"","}\"\"\"","","response = profile.generate("," prompt = prompt,"," action = select_ai.Action.CHAT",")","","print(response)"],"enabled":true,"result":{"startTime":1760327986926,"interpreter":"python.low","endTime":1760328001104,"results":[{"message":"Here's a promotional email that meets the task rules:\n\n**Subject: ?? Sip Sustainably with Our New Eco-Friendly Travel Mug! ?**\n\nDear Fellow Eco-Warriors! ?\n\nAre you tired of using disposable coffee cups that harm our planet? ?? We've got the perfect solution for you! Introducing our brand new, eco-friendly travel mug that's not only stylish but also reusable and sustainable! ?\n\nOur travel mug is made from high-quality, BPA-free materials that are designed to last. With its double-walled insulation, your drinks will stay hot or cold for hours, and the leak-proof lid ensures that you can take it on-the-go without any spills. ? Plus, it's dishwasher safe, making it easy to clean and maintain.\n\nBy switching to our eco-friendly travel mug, you'll be reducing your carbon footprint and helping to minimize waste. ? Every small change counts, and we're proud to be a part of the sustainable living movement! ?\n\nTo celebrate the launch of our new travel mug, we're offering a limited-time discount of 15% off your first purchase! ? Just use the code ECO15 at checkout to redeem your discount. Don't miss out on this amazing opportunity to upgrade your daily coffee routine while doing your part for the planet. ?\n\nHurry! This offer is only valid for the next two weeks, so be sure to order your eco-friendly travel mug today and start sipping sustainably! ?\n\n**Get Your Eco-Friendly Travel Mug Now and Join the Sustainable Living Movement! ?**\n\nBest,\nThe [Your Company Name] Team ?\n\nP.S. Don't forget to share your eco-friendly travel mug with your friends and family on social media and tag us! ? We'd love to see how you're using your new mug and living sustainably. ?\n\nThis promotional email meets the task rules by:\n\n1. Highlighting the reusable and sustainable features of the travel mug.\n2. Using a friendly and engaging tone to connect with the audience.\n3. Suggesting a limited-time discount to encourage quick action.\n4. Including friendly, uplifting emoticons to add a touch of personality to the email. ?\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Generate a customer email response about a return policy using 'chat'","message":["%python","","prompt = \"\"\"Respond to a customer query with succinct and clear instructions about the return policy of a company. Follow the task rules:","{"," \"task\": \"Provide a customer-friendly response to a query about the company return policy\","," \"task_rules\": \"1. The return policy allows for returns within 30 days of purchase with the original receipt. "," 2. Products must be in new, unused condition with original packaging. "," 3. The response should be concise, professional, and helpful, aimed at educating the customer about the return process. "," 4. Ensure the response is polite and assures the customer that their concerns are understood and valued.\","," \"audience\": \"Customer support agents\"","}\"\"\"","","response = profile.generate("," prompt = prompt,"," action = select_ai.Action.CHAT",")","","print(response)"],"enabled":true,"result":{"startTime":1760328001475,"interpreter":"python.low","endTime":1760328011173,"results":[{"message":"Dear valued customer,\n\nThank you for reaching out to us about our return policy. We understand that you may have questions or concerns about returning a product, and we're here to help.\n\nTo initiate a return, please note the following guidelines:\n\n* Returns are accepted within 30 days of purchase with the original receipt.\n* Products must be in new, unused condition with original packaging.\n\nIf your return meets these criteria, you can start the process by contacting our customer support team. We'll be happy to guide you through the next steps and provide a return merchandise authorization (RMA) number.\n\nPlease have your order number and reason for return ready when you contact us. We'll do our best to process your return quickly and efficiently.\n\nYour satisfaction is our top priority, and we appreciate your business. If you have any further questions or concerns, please don't hesitate to reach out. We're here to help and value your feedback.\n\nThank you for choosing our company, and we look forward to assisting you with your return.\n\nBest regards,\n[Your Company Name] Customer Support Team\n\nThis response follows the task rules by:\n\n1. Clearly stating the return policy, including the 30-day return window and the requirement for the original receipt.\n2. Specifying the condition of the products that can be returned, including new and unused condition with original packaging.\n3. Providing concise and professional instructions on how to initiate a return.\n4. Being polite and assuring the customer that their concerns are understood and valued, while also educating them about the return process.\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Generate a customized email promoting vacation ideas using 'chat'","message":["%python","","prompt = \"\"\"Generate email using the JSON specification ","{\"task\": \"Pick 5 great things to do at the location\","," \"task_rules\": \"1. Encourage the customer to do these things. Really sell them as to why it would be right for them "," 2. Consider all the information about the customer that's provided, including family and dog situation, whether they have a car and income"," 3. Format the result with emojis and make it fun\","," \"last_name\": \"Mouly\","," \"first_name\": \"Jennine\","," \"location\": \"Paris, ?le-De-France\","," \"age\": 37,"," \"gender\": \"Female\","," \"has_kids\": \"NO\","," \"num_cars\": 2,"," \"income_level\": \"F: Above 110,000\","," \"dog_owner\": \"NO\"}\"\"\"","","response = profile.generate("," prompt = prompt,"," action = select_ai.Action.CHAT",")","","print(response)"],"enabled":true,"result":{"startTime":1760328011547,"interpreter":"python.low","endTime":1760328027627,"results":[{"message":"Subject: ? 5 Amazing Things to Do in Paris, Jennine! ??\n\nDear Jennine Mouly,\n\nBonjour! ?? We're thrilled to share with you the top 5 things to do in the City of Love, Paris! ? As a high-income earner with a love for luxury, we've curated a list of experiences that will make your stay in Paris truly unforgettable. ?\n\n1. **Seine River Cruise** ?\u200d??: Imagine gliding along the Seine, taking in the stunning views of the city's landmarks while sipping champagne. ? With your high income, you can afford to indulge in a luxurious cruise experience that will leave you feeling like royalty. ?\n2. **Visit the Louvre Museum** ?: As a sophisticated traveler, you'll appreciate the world-class art and history that the Louvre has to offer. ? With over 550,000 works of art, you'll be spoiled for choice. Take your time to explore the museum, and don't forget to snap a photo in front of the iconic glass pyramid! ?\n3. **Explore the Champs-?lys?es** ??: This famous avenue is a shopper's paradise, with high-end boutiques and designer flagships. ?\u200d?? With your income level, you can treat yourself to a luxury shopping spree, and enjoy the finer things in life. ??\n4. **Dine at a Michelin-Starred Restaurant** ?: Paris is renowned for its culinary scene, and with your refined taste, you'll appreciate the exquisite cuisine at a Michelin-starred restaurant. ? From foie gras to escargots, you'll be treated to a gastronomic experience that will leave you wanting more. ?\n5. **Take a Day Trip to the Palace of Versailles** ?: With two cars at your disposal, you can easily take a day trip to the stunning Palace of Versailles. ? Explore the opulent halls, gardens, and fountain shows, and experience the grandeur of French history. ?\n\nThese experiences are tailored to your lifestyle, Jennine, and we're confident that you'll have an unforgettable time in Paris. ? With your love of luxury and high income, you deserve to indulge in the best that the city has to offer. ?\n\nBon voyage, and we hope you have a fantastic time in Paris! ??\n\nBest regards,\n[Your Name] ?\u200d??\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Load travel recommendations and customer feedback data sets","message":["%python\r","\r","# hide for demo\r","\r","import oml\r","\r","# Drop tables if they exist\r","try:\r"," oml.drop(table=\"TRAVEL_RECOMMENDATIONS\")\r","except:\r"," pass\r","\r","try:\r"," oml.drop(table=\"CUSTOMER_FEEDBACK\")\r","except:\r"," pass\r","\r","# Create and load travel_recommendations table\r","travel_data = [\r"," (1, 'Pick 5 great things to do at the location', '1. Encourage the customer to do these things. Really sell them as to why it would be right for them 2. Take into account all the information about the customer that''s provided, including family and dog situation, whether they have a car and income 3. Format the result with emojis and make it fun', 'Mouly', 'Jennine', 'Paris, ?le-De-France', 37, 'Female', 'NO', 2, 'F: Above 110,000', 'NO'),\r"," (2, 'Pick 5 great things to do at the location', '1. Encourage the customer to do these things. Really sell them as to why it would be right for them 2. Take into account all the information about the customer that''s provided, including family and dog situation, whether they have a car and income 3. Format the result with emojis and make it fun', 'Kwon', 'Min-Jae', 'Seoul, South Korea', 45, 'Male', 'YES', 1, 'E: 80,000\u2013110,000', 'YES'),\r"," (3, 'Pick 5 great things to do at the location', '1. Encourage the customer to do these things. Really sell them as to why it would be right for them 2. Take into account all the information about the customer that''s provided, including family and dog situation, whether they have a car and income 3. Format the result with emojis and make it fun', 'Nguyen', 'Linh', 'Hoi An, Vietnam', 29, 'Female', 'NO', 0, 'C: 30,000\u201350,000', 'NO'),\r"," (4, 'Pick 5 great things to do at the location', '1. Encourage the customer to do these things. Really sell them as to why it would be right for them 2. Take into account all the information about the customer that''s provided, including family and dog situation, whether they have a car and income 3. Format the result with emojis and make it fun', 'Gonzalez', 'Carlos', 'Barcelona, Spain', 34, 'Male', 'YES', 2, 'D: 50,000\u201380,000', 'YES'),\r"," (5, 'Pick 5 great things to do at the location', '1. Encourage the customer to do these things. Really sell them as to why it would be right for them 2. Take into account all the information about the customer that''s provided, including family and dog situation, whether they have a car and income 3. Format the result with emojis and make it fun', 'Smith', 'Angela', 'New York City, USA', 41, 'Female', 'NO', 1, 'F: Above 110,000', 'NO')\r","]\r","\r","import pandas as pd\r","travel_df = pd.DataFrame(travel_data, columns=['ID', 'TASK', 'TASK_RULES', 'LAST_NAME', 'FIRST_NAME', 'LOCATION', 'AGE', 'GENDER', 'HAS_KIDS', 'NUM_CARS', 'INCOME_LEVEL', 'DOG_OWNER'])\r","oml.create(travel_df, table=\"TRAVEL_RECOMMENDATIONS\")\r","\r","# Create and load customer_feedback table\r","feedback_data = [\r"," (1, 'Morgan', 'Smith', 'Pixel 8', 'Absolutely love this phone! The battery lasts forever and the camera is top-notch.'),\r"," (2, 'Morgan', 'Smith', 'OnePlus 12', 'Incredible value for the price. Exceeded my expectations!'),\r"," (3, 'Reese', 'Martinez', 'Xperia 1 V', 'Best smartphone I have ever used. Highly recommend!'),\r"," (4, 'Jordan', 'Anderson', 'Galaxy S24', 'Absolutely love this phone! The battery lasts forever and the camera is top-notch.'),\r"," (5, 'Taylor', 'Nguyen', 'Pixel 8', 'Absolutely love this phone! The battery lasts forever and the camera is top-notch.')\r","]\r","\r","feedback_df = pd.DataFrame(feedback_data, columns=['ID', 'FIRST_NAME', 'LAST_NAME', 'PRODUCT', 'PRODUCT_FEEDBACK'])\r","oml_df = oml.create(feedback_df, table=\"CUSTOMER_FEEDBACK\")\r","oml_df.head()"],"enabled":true,"result":{"startTime":1760328028006,"interpreter":"python.low","endTime":1760328028605,"results":[{"message":" ID FIRST_NAME ... PRODUCT PRODUCT_FEEDBACK\n0 1 Morgan ... Pixel 8 Absolutely love this phone! The battery lasts ...\n1 2 Morgan ... OnePlus 12 Incredible value for the price. Exceeded my ex...\n2 3 Reese ... Xperia 1 V Best smartphone I have ever used. Highly recom...\n3 4 Jordan ... Galaxy S24 Absolutely love this phone! The battery lasts ...\n4 5 Taylor ... Pixel 8 Absolutely love this phone! The battery lasts ...\n\n[5 rows x 5 columns]\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":true,"width":12,"hideResult":true,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":true,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Identify sentiment of customer product feedback","message":["%python","","import oml","import pandas as pd","","feedback = oml.sync(table=\"CUSTOMER_FEEDBACK\")","df = feedback.pull()","","results = []","for _, row in df.iterrows():"," sentiment = profile.generate("," prompt = \"Return the sentiment of the following text using only the values positive, neutral, or negative, nothing else: \" + row['PRODUCT_FEEDBACK'],"," action = select_ai.Action.CHAT"," )"," results.append({\"id\": row['ID'], \"product\": row['PRODUCT'], \"sentiment\": sentiment.strip()})","","results_df = pd.DataFrame(results)","print(results_df)"],"enabled":true,"result":{"startTime":1760328062467,"interpreter":"python.low","endTime":1760328064731,"results":[{"message":" id product sentiment\n0 1 Pixel 8 Positive\n1 2 OnePlus 12 Positive\n2 3 Xperia 1 V Positive\n3 4 Galaxy S24 Positive\n4 5 Pixel 8 Positive\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Augment the query above to aggregate the counts of the sentiment","message":["%python","","feedback = oml.sync(table=\"CUSTOMER_FEEDBACK\")","df = feedback.pull()","","results = []","for _, row in df.iterrows():"," sentiment = profile.generate("," prompt = \"Return the sentiment of the following text using only the values positive, neutral, or negative, nothing else: \" + row['PRODUCT_FEEDBACK'],"," action = select_ai.Action.CHAT"," )"," results.append({\"product\": row['PRODUCT'], \"sentiment\": sentiment.strip()})","","results_df = pd.DataFrame(results)","sentiment_counts = results_df.groupby([\"product\", \"sentiment\"]).size().reset_index(name=\"count\")","sentiment_counts = sentiment_counts.sort_values([\"sentiment\", \"product\"], ascending=[False, True])","print(sentiment_counts)"],"enabled":true,"result":{"startTime":1760328071838,"interpreter":"python.low","endTime":1760328073897,"results":[{"message":" product sentiment count\n0 Galaxy S24 Positive 1\n1 OnePlus 12 Positive 1\n2 Pixel 8 Positive 2\n3 Xperia 1 V Positive 1\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Filter for product reviews with positive feedback","message":["%python","","feedback = oml.sync(table = \"CUSTOMER_FEEDBACK\")","df = feedback.pull()","","results = []","for _, row in df.iterrows():"," sentiment = profile.generate("," prompt = \"Return the sentiment of the following text using only the values positive, neutral, or negative, nothing else: \" + row['PRODUCT_FEEDBACK'],"," action = select_ai.Action.CHAT"," )"," if sentiment.strip().lower() == \"positive\":"," results.append({\"id\": row['ID'], \"product\": row['PRODUCT']})","","results_df = pd.DataFrame(results)","print(results_df)"],"enabled":true,"result":{"startTime":1760328040260,"interpreter":"python.low","endTime":1760328042824,"results":[{"message":" id product\n0 1 Pixel 8\n1 2 OnePlus 12\n2 3 Xperia 1 V\n3 4 Galaxy S24\n4 5 Pixel 8\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"raw","title":"Summarize feedback grouped by product","message":["%python","","import json","","feedback = oml.sync(table = \"CUSTOMER_FEEDBACK\")","df = feedback.pull()","","product_feedback = {}","for _, row in df.iterrows():"," product = row['PRODUCT']"," feedback_text = row['PRODUCT_FEEDBACK']"," if product not in product_feedback:"," product_feedback[product] = []"," product_feedback[product].append({\"feedback_text\": feedback_text})","","results = []","for product, feedbacks in product_feedback.items():"," all_feedback = json.dumps(feedbacks)"," review_summary = profile.generate("," prompt = all_feedback,"," action = select_ai.Action.CHAT"," )"," results.append({\"product\": product, \"review_summary\": review_summary})","","results_df = pd.DataFrame(results)","results_df['review_summary'] = results_df['review_summary'].str.extract(r'(Positive|Negative)', expand=False)","results_df"],"enabled":true,"result":{"startTime":1760328415640,"interpreter":"python.low","endTime":1760328422918,"results":[{"message":" product review_summary\n0 Pixel 8 Positive\n1 OnePlus 12 Positive\n2 Xperia 1 V Positive\n3 Galaxy S24 Positive\n","type":"TEXT"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":false,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":true,"hideVizConfig":false,"hideGutter":true,"relations":[],"forms":"[]"},{"col":0,"visualizationConfig":null,"hideInIFrame":false,"selectedVisualization":"html","title":null,"message":["%md","## End of Script"],"enabled":true,"result":{"startTime":1760328045444,"interpreter":"md.low","endTime":1760328045762,"results":[{"message":"<h2 id=\"end-of-script\">End of Script<\/h2>\n","type":"HTML"}],"taskStatus":"SUCCESS","forms":"[]","status":"SUCCESS"},"sizeX":0,"hideCode":true,"width":12,"hideResult":false,"dynamicFormParams":"{}","row":0,"hasTitle":false,"hideVizConfig":true,"hideGutter":true,"relations":[],"forms":"[]"}],"version":"7","snapshot":false,"tags":null}]