Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

How-To Tutorials - ChatGPT

113 Articles
article-image-summarizing-data-with-openai-chatgpt
Greg Beaumont
02 Jun 2023
4 min read
Save for later

Summarizing Data with OpenAI ChatGPT

Greg Beaumont
02 Jun 2023
4 min read
This article is an excerpt from the book, Machine Learning with Microsoft Power BI, by Greg Beaumont. This book is designed for data scientists and BI professionals seeking to improve their existing solutions and workloads using AI. In the ever-expanding landscape of data analysis, the ability to summarize vast amounts of information concisely and accurately is invaluable. Enter ChatGPT, an advanced AI language model developed by OpenAI. In this article, we delve into the realm of data summarization with ChatGPT, exploring how this powerful tool can revolutionize the process of distilling complex datasets into concise and informative summaries.Numerous databases feature free text fields that comprise entries from a diverse array of sources, including survey results, physician notes, feedback forms, and comments regarding incident reports for the FAA Wildlife Strike database that we have used in this book. These text entry fields represent a wide range of content, from structured data to unstructured data, making it challenging to extract meaning from them without the assistance of sophisticated natural language processing tools. The Remarks field of the FAA Wildlife Strike database contains text that was presumably entered by people involved in filling out the incident form about an aircraft striking wildlife. A few examples of the remarks for recent entries are shown in Power BI in the following screenshot: Figure 1 – Examples of Remarks from the FAA Wildlife Strike Database You will notice that the remarks have a great deal of variability in the format of the content, the length of the content, and the acronyms that were used. Testing one of the entries by simply adding a statement at the beginning to “Summarize the following:” yields the following result: Figure 2 – Summarizing the remarks for a single incident using ChatGPT Summarizing data for a less detailed Remarks field yields the following results: Figure 3 – Summarization of a sparsely populated results field In order to obtain uniform summaries from the FAA Wildlife Strike data's Remarks field, one must consider entries that vary in robustness, sparsity, completeness of sentences, and the presence of acronyms and quick notes. The workshop accompanying this technical book is your chance to experiment with various data fields and explore diverse outcomes. Both the book and the Packt GitHub site will utilize a standardized format as input to a GPT model that can incorporate event data and produce a consistent summary for each row. An example of the format is as follows:  Summarize the following in three sentences: A [Operator] [Aircraft] struck a [Species]. Remarks on the FAA report were: [Remarks]. Using data from an FAA Wildlife Strike Database event to test this approach in OpenAI ChatGPT is shown in the following screenshot: Figure 4 – OpenAI ChatGPT testing a summarization of the remarks field Next, you test another scenario that had more robust text in the Remarks field: Figure 5 – Another scenario with robust remarks tested using OpenAI ChatGPT SummaryThis article explores how ChatGPT can revolutionize the process of condensing complex datasets into concise and informative summaries. By leveraging its powerful language generation capabilities, ChatGPT enables researchers, analysts, and decision-makers to quickly extract key insights and make informed decisions. Dive into the world of data summarization with ChatGPT and unlock new possibilities for efficient data analysis and knowledge extraction. Author Bio:Greg Beaumont is a Data Architect at Microsoft; Greg is an expert in solving complex problems and creating value for customers. With a focus on the healthcare industry, Greg works closely with customers to plan enterprise analytics strategies, evaluate new tools and products, conduct training sessions and hackathons, and architect solutions that improve the quality of care and reduce costs. With years of experience in data architecture and a passion for innovation, Greg has a unique ability to identify and solve complex challenges. He is a trusted advisor to his customers and is always seeking new ways to drive progress and help organizations thrive. For more than 15 years, Greg has worked with healthcare customers who strive to improve patient outcomes and find opportunities for efficiencies. He is a veteran of the Microsoft data speaker network and has worked with hundreds of customers on their data management and analytics strategies.You can follow Greg on LinkedIn
Read more
  • 0
  • 0
  • 17333

article-image-chatgpt-for-data-engineering
Rohan Chikorde
25 Sep 2023
12 min read
Save for later

ChatGPT for Data Engineering

Rohan Chikorde
25 Sep 2023
12 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights and books. Don't miss out – sign up today!Introduction Data engineering is a critical aspect of the modern data-driven world. With the increasing need for efficient and scalable data processing, storage, and analysis, data engineers must constantly adapt to new technologies and tools. One such groundbreaking technology is ChatGPT, an AI-powered language model developed by OpenAI. In this blog post, we will explore how ChatGPT can be utilized in data engineering tasks, providing code examples, tips, and tricks to help you leverage this powerful tool for your data engineering needs.How ChatGPT can Benefit Data EngineersData engineers can utilize ChatGPT for various tasks, such as:1. Data validation and quality controlChatGPT can be used to generate data validation rules or scripts by understanding the data structure and business requirements. These rules can then be applied to ensure data consistency and quality. ChatGPT can generate code in a variety of programming languages, including Python, Scala, and SQL. This can save data engineers a significant amount of time and effort, especially when they need to write code for complex data pipelines.Prompt:Hey, I have a customer database with the following fields: -        Customer ID (integer, primary key) -        Name (string, required) -        Phone (string, maximum length 10) -        Address (string, required) -        City (string, required) -        State (string, maximum length 2) -        Zipcode (string, required, must be 5 digits) -        Date of Birth (date, optional) -        Date of Last Purchase (date, optional but if provided must be in the past) I need data validation rules to ensure: -        Required fields are not empty -        Phone numbers are 10 digits -        State field is max 2 characters -        Zipcode is 5 digits -        Dates are in proper format if provided -        Last purchase date is in the past if provided Can you please generate sample Python/SQL code snippets to validate this customer data based on the above requirements? The code should: -        Check for empty/null required fields -        Validate phone, state and zipcode formats -        Validate date formats and last purchase date Let me know if any part of the requirements need clarification. I would appreciate sample validation code to help ensure data quality for this customer database.Here is a sample of Python and SQL code generated by ChatGPT. Please note that only a small section of the code is shown in the screenshot below due to its length. 2. Improving data qualityChatGPT can be used to identify and correct errors in data. This can help to improve the quality of data and make it more reliable for analysis.Prompt:ChatGPT, I have a customer dataset that contains some errors that need to be cleaned up before analysis. Could you take a look and suggest ways to improve data quality? The table structure is: -        Table: customers -        Columns: id, name, address, city, state, zip, phone A sample of 50 records is: [paste sample data here with some known errors like invalid phone numbers, misspelled cities, incorrect zip codes etc.] Some specific data quality issues I know exist: -        Invalid phone numbers -        Misspelled city names -        Zip codes that don't match stated cities/states Can you take a look at the sample data and: -        Identify any other potential errors -        Suggest ways to validate/correct things like phone numbers, city names, zip codes -        Provide example Python code to validate the data quality This will help me better understand the scope of data cleaning needed. Your input on how to programmatically improve reliability would be greatly appreciated.Sample Generated Output by ChatGPT (again only a small section of the code is shown in the screenshot below due to its length.)3. Automating documentationWith ChatGPT's ability to generate human-like text, data engineers can automate the creation of data dictionaries, data lineage, and other documentation.Prompt:Hey, I'm looking to automate the documentation of our data warehouse datasets. Could you help generate samples based on metadata descriptions? For example, here are the details of a customers table: Table Name: customers Description: This table contains customer profile data collected from various sources. Columns: -        id (integer, primary key) -        name (varchar 100) -        address (varchar 200) -        city (varchar 50) -        state (varchar 30) -        zip (varchar 10) -        phone (varchar 20) -        email (varchar 100) Data Sources: -        Name, address, city, state, zip collected from CRM -        Phone, email collected from marketing database Refresh Frequency: -        Incrementally updated daily from source systems Usage: -        Provides centralized customer profile for analysis -        Joined with orders table for purchase history insights Can you generate: -        A Markdown data dictionary entry for this table -        A paragraph on the data lineage and refresh process It would be helpful to have templates I can reuse for documenting other datasets consistently. Your assistance in automating this documentation creation will save valuable time. Sample generated output by ChatGPT (again only a small section of the code is shown in the screenshot below due to its length.): Here are additional examples of how ChatGPT can be used by data engineers: 4. Data Transformation and ETL (Extract, Transform, Load) ProcessesData engineers can use ChatGPT to generate code for data transformation tasks within ETL pipelines. For example, it can help automate tasks such as data cleansing, normalization, and aggregation. ChatGPT can generate SQL, Python, or other scripting languages to perform these transformations efficiently.5. Data Pipeline Orchestration and Workflow AutomationData engineers can leverage ChatGPT to generate code or configuration files for orchestrating data pipelines. This includes setting up workflow scheduling, dependencies, and error handling. ChatGPT can provide code templates for tools like Apache Airflow or Kubernetes-based pipeline orchestrators.6. Data Integration and Schema MappingChatGPT can assist in generating code for data integration tasks, where data from various sources needs to be merged and mapped to a unified schema. It can help automate the creation of mapping rules, data type conversions, and schema reconciliation scripts.7. Data Security and Privacy ComplianceChatGPT can assist in generating code or documentation related to data security and privacy compliance. This includes implementing data masking, encryption, and access control measures in data pipelines and databases. 8. Data Warehouse Design and OptimizationData engineers can use ChatGPT to generate SQL queries for designing and optimizing data warehouse schemas. It can help generate star or snowflake schema designs, create indexes, and suggest query optimization techniques. 9. Data Monitoring and AlertingChatGPT can help data engineers create scripts for data monitoring and alerting systems. It can generate code for tracking data quality metrics, setting up alerts for anomalies, and sending notifications when issues are detected.10.  Data Archiving and PurgingData engineers can automate data archiving and purging processes with ChatGPT-generated scripts. This includes moving historical data to archival storage, setting retention policies, and ensuring compliance with data retention regulations.These examples highlight various areas where ChatGPT can assist data engineers in automating tasks and improving efficiency.OpenAI API to interact with ChatGPTWe can also use the OpenAI API to interact with ChatGPT and generate a data validation rule for a sample dataset. We will provide ChatGPT with a prompt describing the dataset and the validation rule we require.PrerequisitesTo use the OpenAI API, you will need an API key. You can sign up for a free trial or a subscription plan on the OpenAI website - https://platform.openai.com/.InstallationAfter getting API key, install the OpenAI Python package:pip install openaiCode Example:import openai # Set up the API key and API client api_key = "your_openai_api_key" openai.api_key = api_key # Define the dataset and validation rule requirement prompt = ''' We have a dataset of user information with the following columns: - user_id: integer (unique) - first_name: string - last_name: string - email: string - age: integer Generate a data validation rule to ensure that the email column contains valid email addresses. ''' # Make a request to the OpenAI API response = openai.Completion.create(    engine="text-davinci-002",    prompt=prompt,    max_tokens=100,    n=1,    stop=None,    temperature=0.7, ) # Extract the generated validation rule generated_rule = response.choices[0].text.strip() print(generated_rule)This code is using the OpenAI API to generate a data validation rule:It imports the openai library and sets the API key for authentication.It defines a prompt describing the dataset and validation requirements.It makes a request to the OpenAI Completion API using the prompt, and extracts the generated validation rule from the response.It leverages a large language model via the OpenAI API to automatically generate a data validation logic based on a natural language description of needs.Tips and TricksFine-tune ChatGPTFine-tuning the base ChatGPT model on domain-specific data can yield better results. Collect and curate a dataset of data engineering-related discussions and use it to fine-tune the model using OpenAI's fine-tuning techniques. By doing so, you can align ChatGPT's responses more closely with the specific challenges and requirements of data engineering.Use Contextual PromptsProvide ChatGPT with relevant context and background information to improve the accuracy and relevance of its responses. Including details such as the data source, tools being used, and specific challenges faced will help generate more precise suggestions. For example, instead of asking a generic question like"How can I optimize a data pipeline?", provide more context like, "I'm using Apache Kafka as my data source and want to optimize the ingestion process. What strategies or tools can I use?"Experiment with Temperature and Max TokensAdjusting the temperature and max tokens parameters can influence the diversity and length of responses. Experiment with different values to strike a balance between generating creative responses and ensuring coherence. Lower temperature values (e.g., 0.2) produce more focused and deterministic responses, while higher values (e.g., 0.8) result in more diverse and creative but potentially less coherent answers. Similarly, adjusting the max tokens parameter allows you to control the length of the generated response. Engage in Iterative ConversationsUse the output generated by ChatGPT as a starting point and engage in iterative conversations to seek clarification or refine the suggestions provided. This interactive process allows you to leverage the model's capabilities fully. You can ask follow-up questions, provide additional context, or ask for alternative solutions to explore different possibilities.Experiment with different prompt stylesChatGPT's performance may vary based on the prompt's clarity and specificity. Experiment with different prompt styles to get the desired output.Use the right modelDifferent models in the GPT-3 family have varying performance capabilities. Experiment with different models to find the one that works best for your data engineering tasks.ConclusionChatGPT is a versatile and powerful tool that can be applied to a wide range of data engineering tasks. Its ability to understand and generate human-like text makes it ideal for generating data validation rules, transformation scripts, documentation, and more. By leveraging ChatGPT's capabilities, data engineers can automate various aspects of their work, improve efficiency, and focus on more complex tasks.Remember to experiment with different prompts, parameters, and models to optimize the results for your specific use case. With the right approach, ChatGPT can become a valuable asset in your data engineering toolkit.As the field of AI and natural language processing continues to advance, we can expect even more powerful tools and applications for data engineering in the future. Keep an eye on emerging technologies and stay up to date with the latest advancements to ensure you're always leveraging the best tools for your data engineering needs.Author BioRohan Chikorde is an accomplished AI Architect professional with a post-graduate in Machine Learning and Artificial Intelligence. With almost a decade of experience, he has successfully developed deep learning and machine learning models for various business applications. Rohan's expertise spans multiple domains, and he excels in programming languages such as R and Python, as well as analytics techniques like regression analysis and data mining. In addition to his technical prowess, he is an effective communicator, mentor, and team leader. Rohan's passion lies in machine learning, deep learning, and computer vision.LinkedIn
Read more
  • 0
  • 0
  • 17099

article-image-build-virtual-personal-assistants-using-chatgpt
Sangita Mahala
13 Nov 2023
6 min read
Save for later

Build Virtual Personal Assistants Using ChatGPT

Sangita Mahala
13 Nov 2023
6 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionVirtual Personal Assistants are emerging as an important aspect of the rapidly developing Artificial Intelligence landscape. These intelligent, Artificial Intelligence assistants are capable of carrying out a wide range of tasks such as answering questions and providing advice on how to make process more efficient.You're more easily getting your personal assistant built using the ChatGPT service from OpenAI. We'll explore the creation of virtual personal assistants using ChatGPT, complete with hands-on code examples and projected outputs in this advanced guide. Use ChatGPT, the world's most advanced language model created by OpenAI to create a virtual assistant that you can use.Prerequisites before we startThere are certain prerequisites that need to be met before we embark on this journey:OpenAI API Key: You must have an API key from OpenAI if you want to use ChatGPT. You'll be able to get one if you sign up at OpenAI.Python and Jupyter Notebooks: To provide more interactive learning of the development process, it is recommended that you install Python on your machine.OpenAI Python Library: To use ChatGPT, you will first need to download the OpenAI Python library. Using pip, you can install the following:pip install openaiGoogle Cloud Services (optional): If you plan to integrate with voice recognition and text-to-speech services, such as Google Cloud Speech-to-Text and Text-to-Speech, you'll need access to Google Cloud services.Building a Virtual Personal AssistantLet's have a look at the following steps for creating a Virtual Personal Assistant with ChatGPT1. Set up the environmentTo begin, we shall import the required libraries and set up an API key.import openai openai.api_key = "YOUR_OPENAI_API_KEY"2. Basic Text-Based InteractionWe're going to build an easy interaction based on text with our assistant. We will ask ChatGPT a question, and we shall receive an answer.Input code:def chat_with_gpt(prompt):    response = openai.Completion.create(        engine="davinci-codex",        prompt=prompt,        max_tokens=50  # Adjust as needed    )    return response.choices[0].text # Interact with the assistant user_input = input("You: ") response = chat_with_gpt(f"You: {user_input}\nAssistant:") print(f"Assistant: {response}")Output:You: What's the weather like today? Assistant: The weather today is sunny with a high of 25°C and a low of 15°C.We used ‘chat_with_gpt’, for interacting with ChatGPT to generate responses from user input. Users can input questions or comments and the function will send a request to ChatGPT. In the output, the assistant's answer is shown in a conversational format.Example 1: Language TranslationBy making it a language translation tool, we can improve the assistant's abilities. Users can type a word in one language and an assistant will translate it to another.Input Code:def translate_text(input_text, target_language="fr"):    response = chat_with_gpt(f"Translate the following text from English to {target_language}: {input_text}")    return response # Interact with the translation feature user_input = input("Enter the text to translate: ") target_language = input("Translate to (e.g., 'fr' for French): ") translation = translate_text(user_input, target_language) print(f"Translation: {translation}")Output:Enter the text to translate: Hello, how are you? Translate to (e.g., 'fr' for French): fr Translation: Bonjour, comment ça va?To translate English text to the target language using ChatGPT, we are defining a function, ‘translate_text’. Users input text and the target language, which is returned in translation by this function. It uses the ability of ChatGPT to process natural languages in order to carry out accurate translation.Example 2: Code GenerationThe creation of code fragments may also be assisted by our virtual assistant. It is especially useful for developers and programmers who want to quickly solve code problems.Input Code:def generate_code(question):    response = chat_with_gpt(f"Generate Python code to: {question}")    return response # Interact with the code generation feature user_input = input("You: ") generated_code = generate_code(user_input) print("Generated Python Code:") print(generated_code)Output:You: Create a function to calculate the factorial of a number. Generated Python Code: def calculate_factorial(n):    if n == 0:        return 1    else:        return n * calculate_factorial(n - 1)The user provides a question and the function sends a request to ChatGPT to generate code to answer it. In the output, a Python code is displayed.Example 3: Setting RemindersIt's even possible to make use of our Virtual Assistant as an organizer. A reminder of tasks or events can be set by users, which will be handled by an assistant.Input code:def set_reminder(task, time):    response = chat_with_gpt(f"Set a reminder: {task} at {time}.")    return response # Interact with the reminder feature task = input("Task: ") time = input("Time (e.g., 3:00 PM): ") reminder_response = set_reminder(task, time) print(f"Assistant: {reminder_response}")Output:Task: Meeting with the client Time (e.g., 3:00 PM): 2:30 PM Assistant: Reminder set: Meeting with the client at 2:30 PM.The code defines a function, ‘set_reminder’, which can be used to generate reminders based on the task and time. Users input their tasks and time, and the function requests a reminder to be sent to ChatGPT. The output will be printed with the assistant's answer and confirmation of this reminder.ConclusionIn conclusion, we got to know the evolution of Virtual Personal Assistant using ChatGPT throughout this advanced guide. We've started with a basic text-based interaction, followed by three advanced examples: language translation, code generation, and setting reminders. There is no limit to the potential of Virtual Personal Assistants.Integrating your assistant into various APIs, enhancing the ability to understand languages and making it useful for a variety of tasks will allow you to further expand its capabilities. Creating a tailored virtual assistant is now even easier to create and adapted to your individual needs, given the advancement of AI technologies.Author BioSangita Mahala is a passionate IT professional with an outstanding track record, having an impressive array of certifications, including 12x Microsoft, 11x GCP, 2x Oracle, and LinkedIn Marketing Insider Certified. She is a Google Crowdsource Influencer and IBM champion learner gold. She also possesses extensive experience as a technical content writer and accomplished book blogger. She is always Committed to staying with emerging trends and technologies in the IT sector.
Read more
  • 0
  • 0
  • 17019

article-image-data-cleaning-made-easy-with-chatgpt
Sagar Lad
02 Jun 2023
5 min read
Save for later

Data Cleaning Made Easy with ChatGPT

Sagar Lad
02 Jun 2023
5 min read
Identifying inconsistencies and inaccuracies in the data is a vital part of the data analysis process. ChatGPT is a natural language processing tool powered by AI that enables users to have human-like conversations and helps them complete tasks quickly. In this article, we'll focus on how chatGPT can make the process of data cleansing and cleaning more efficient. Data Cleansing/Cleaning with ChatGPT Given the volume, velocity, and variety of data we deal with nowadays, manually carrying out the data cleansing task is a very time-consuming process. Data cleansing, the removal of duplicate data, data validity, uniqueness, consistency, and correctness are all steps taken to increase the quality of the data. Better business insights and the ability for business users to make wise decisions are provided by cleansed data. Data cleansing activities go via a series of steps, starting with gathering the data and ending with integrating, producing, and normalizing the data, as shown in the image below: Image 1: Data cleansing cycle  The majority of corporate organizations carry out the following tasks as part of the exploratory data analysis's data cleansing procedure: Identify and clean up Duplicate Values Fill Null Values with a default valueRectify and Correct inconsistent dataStandardising date formats Standardising  name or addressArea codes out of phone numbersFlattening nested data structuresErasing incomplete dataDetecting conflicts in the database The strength of ChatGPT allows us to perform time-consuming and extremely boring tasks like data purification with ease. Let's use the example of employee details for the banking industry to better comprehend it which has columns: Employee ID, Employee Name, Department Name, and Joining Date. While reviewing the data, we discovered a number of data quality concerns that must be resolved before we can truly use this data for analytics. Example: Employee Name is inconsistent - some instances use lowercase while others use uppercase letters. The data format is not uniform for the joining date column. Traditional Way of Working To clean up this data in Excel, we must manually construct the formulas and apply functions like TRIM, UPPER, or LOWER before using it for analytics. It calls for development work, and upkeep of Excel logic without version control, history, etc. Sounds extremely tedious, isn’t it? Working with ChatGPT We can utilize ChatGPT to automate the aforementioned data purification operation by implementing some Python code. In this example, we'll use the ChatGPT Python code to demonstrate how to standardize the name for the employee's name and the date format for the joining date.ChatGPT prompt:Here is the prompt that we can provide in the text format, in case you plan to copy and paste:             Employee ID | Employee Name | Department Name | Joining Date            214                   john Root                  HR                             1-06-2003            435                   STEVE Smith             Retail                          21-Feb-05            654                   Sachin WALA            OPSI                           25-July-1999 Above is the employee data source which should be cleaned. Employee names are not consistent, and the joining date is not in a uniform date format. Generate a Python code to create accurate data. Image 2: Input to the ChatGPTWe pass a dataset and a description of how and for which columns we want to clean the data as seen in the image above. Output from ChatGPTChatGPT automatically creates Python code with a variety of generic functions to clean the specified column in accordance with our specifications. The ChatGPT tool's output Python code is shown below.      Image 3: Output Python code from ChatGPT After running the Python code generated by ChatGPT on the stated data, ChatGPT also displays a sample result on the data here. It is clear that employee names are now uniform, and the joining date is likewise shown using a common date format.             Image 4 : Sample output from ChatGPT This Python code can be used to clean any data source in the future when we need to do so, not just the employee dataset. Therefore, using ChatGPT's capabilities, we can develop a fully automated data cleaning process that is precise, effective, and totally automated.There are also tools on the market like RATH, which has an integration with ChatGPT, to simplify the data analysis workflow and increase your productivity without putting in a lot of manual work if you are having trouble with a large volume of data and need to spend a lot of time performing the data cleaning activity ConclusionThis article gave you a fundamental grasp of the data cleaning/cleansing procedure, which will enable you to use the data to make more trustworthy decisions. The most effective method for using ChatGPT to clean your data simply and effectively for any data quantities. Author Bio:Sagar Lad is a Cloud Data Solution Architect with a leading organisation and has deep expertise in designing and building Enterprise-grade Intelligent Azure Data and Analytics Solutions. He is a published author, content writer, Microsoft Certified Trainer, and C# Corner MVP.You can follow Sagar on - Medium, Amazon, LinkedIn
Read more
  • 0
  • 0
  • 16723

article-image-configuring-openai-and-azure-openai-in-power-bi
Greg Beaumont
16 Oct 2023
9 min read
Save for later

Configuring OpenAI and Azure OpenAI in Power BI

Greg Beaumont
16 Oct 2023
9 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!This article is an excerpt from the book, Power BI Machine Learning and OpenAI, by Greg Beaumont. Master core data architecture design concepts and Azure Data & AI services to gain a cloud data and AI architect’s perspective to developing end-to-end solutions IntroductionIn this article, we delve into the exciting world of Power BI integration with OpenAI and Azure OpenAI. Data-driven decision-making is at the core of modern business, and harnessing the capabilities of AI models for generating text adds an invaluable dimension to your insights. Whether you're new to OpenAI or exploring the power of Azure OpenAI, we'll guide you through the technical requirements, API key setup, resource management, and dataflow optimization to seamlessly infuse AI-generated content into your Power BI projects. Let's embark on a journey to supercharge your data analytics capabilities and stay ahead in the ever-evolving world of data science.Technical requirementsFor this article, you’ll need the following:An account with the original open source OpenAI: https://openai.com/. • Optional – Azure OpenAI as part of your Azure subscription: https://azure.microsoft. com/en-us/products/cognitive-services/openai-service. The book is written so this is optional since it is not available to everyone at the time of publication.FAA Wildlife Strike data files from either the FAA website or the Packt GitHub site.• A Power BI Pro license.• One of the following Power BI licensing options for access to Power BI dataflows:Power BI PremiumPower BI Premium Per UserConfiguring OpenAI and Azure OpenAI for use in your Power BI solutionPrior to proceeding with the configuration of OpenAI and Azure OpenAI, it is important to note that OpenAI is still a nascent technology at the time of writing this book. In the future, the integration of OpenAI with Power BI may become less technical, as advancements in the technology continue to be made. However, the use cases that will be demonstrated in this chapter will remain applicable.As such, the instructions provided in this chapter will showcase how this integration can be used to enhance your data analytics capabilities in the context of Power BI.Configuring OpenAIYou can create an account in OpenAI (if you do not have one already) from this link: https:// chat.openai.com/auth/login. At the time of writing, new accounts are granted trial credits to begin using OpenAI. If you run out of trial credits, or if the trial is no longer offered after this book has been written, you may need to pay for the use of OpenAI. Pricing details can be found at this link: https://openai.com/pricing.Once you have an OpenAI account, you will need to create an API key that will be used to authenticate your API calls. An API key can be easily created at this link: https://platform.openai.com/ account/api-keys. Clicking on Create new secret key will allow you to create a new key for API calls that you make later in this chapter. This book will use abc123xyz as an example key for the sample code. Be sure to use the actual Key from OpenAI, and not the Key Name.Once you have an account and an API key, you are ready to go with OpenAI for this book!Configuring Microsoft Azure OpenAIOpenAI is also available as a service in Microsoft Azure. By using the Microsoft Azure OpenAI Service, users can leverage large-scale AI models with the benefits of Azure, such as role-based access security, private networks, and comprehensive security tools that integrate with other Microsoft tools in Azure. Billing and governance can be centralized for large organizations to help ensure the responsible use of AI.For the purposes of this book, Azure OpenAI is optional as an alternative to the original OpenAI. Azure OpenAI may not be available to everyone since it is a new technology with high demand. All of the content for the workshop can be done with either OpenAI or Azure OpenAI.Instructions for setting up Azure OpenAI can be found at this link: https://learn.microsoft. com/en-us/azure/cognitive-services/openai/how-to/create-resource/.Once you’ve created a resource, you can also deploy a model per the instructions at that link. As noted in Chapter 12, you will be using the text-davinci-003 model for the workshop associated with this chapter. OpenAI is evolving rapidly, and you may be able to choose different models at the time you are reading this book. Take note of the following values when walking through these steps; they will be needed later in this chapter:Resource name: Note the name of your Azure OpenAI resource in your subscription. This book will use PBI_OpenAI_project for the examples in this chapter.Deployment name: This is the name of the resource for the text-davinci-003 model deployment. This book will use davinci-PBIML for names of deployments in examples of code.Next, you’ll need to create a key for your Azure OpenAI API calls. From your Azure OpenAI resource, named PBI_OpenAI_project for this book, go to Resource management | Keys and endpoint, and your keys will be on that page. This book will use abc123xyz as an example key for the sample code.Once you have either OpenAI or Azure OpenAI set up and ready to go, you can add some new generative text capabilities to your project using FAA Wildlife Strike data!Preparing a Power BI dataflow for OpenAI and Azure OpenAIIn Chapter 12, you decided to use OpenAI for two use cases with your FAA Wildlife Strike database project:Generating descriptions of airplane models and the operator of the aircraft, for each incidentSummarizing the free text remarks provided in the report for each incidentSince OpenAI is still new at the time of writing this book, Power BI does not yet have connectors built into the product. But you can still call OpenAI and Azure OpenAI APIs from both Power Query and Power BI dataflows using custom M scripts. Let’s get started!First, you will create a new dataflow for use with OpenAI and Cognitive Services in Power BI:1. From your Power BI workspace, on the ribbon, select New | Dataflow.2. Select Define new tables | Link tables from other dataflows.3. Sign in and click Next.4. Expand your workspace.5. Expand the Strike Reports dataflow and check Strike Reports Curated New.6. Click Transform Data.7. Create a group named Sources and move Strike Reports Curated New into that group.8. Right-click Strike Reports Curated New and unselect Enable load.Next, you will create a version of the query that will be used with OpenAI and Cognitive Services:1. Right-click on Strike Reports Curated New and select Reference.2. Rename the new query Strike Reports Curated New OpenAI.3. Create a group named OpenAI and move Strike Reports Curated New OpenAI into the group.In Chapter 12, you decided to use the FAA Wildlife Strike Operator, Aircraft, Species, and Remarks database columns as part of your OpenAI prompts. Filtering out blank and unknown values from Strike Reports Curated New OpenAI will help produce better results for your testing. Note that you may need to select Load more... if the values all come up empty or UNKNOWN:1. For the Operator column, filter out the UNKNOWN, UNKNOWN COMMERCIAL, BUSINESS, and PRIVATELY OWNED values.2. For the Aircraft column, filter out UNKNOWN.3. For the Species column, filter out Unknown bird, Unknown bird – large, Unknown bird – medium, Unknown bird – small, and Unknown bird or bat.For the Remarks column, filter out (blank).Finally – this step is optional – you can filter the number of rows for testing purposes. Both OpenAI and Azure OpenAI can run up a bill, so limiting the number of calls for this workshop makes sense. For the example in this book, the Strike Reports Curated New OpenAI table will be filtered to events happening in or after December 2022, which can be filtered using the Incident Date column.Now you are ready to add OpenAI and Cognitive Services content to your data!ConclusionIn conclusion, configuring OpenAI and Azure OpenAI for integration with Power BI offers valuable enhancements to your data analytics capabilities. While OpenAI is still an evolving technology, the instructions provided in this article remain relevant and applicable. Whether you choose OpenAI or Azure OpenAI, both options empower you to leverage AI models effectively within Power BI.Setting up these services involves creating API keys, resources, and deployments, as outlined in the article. Additionally, preparing your Power BI dataflow for OpenAI and Azure OpenAI is a crucial step. You can filter and optimize your data to improve the quality of AI-generated content.As AI continues to advance, the potential for enhancing data analytics with OpenAI grows, and these configurations provide a strong foundation for leveraging generative text capabilities in your projects.Author BioGreg Beaumont is a Data Architect at Microsoft; Greg is an expert in solving complex problems and creating value for customers. With a focus on the healthcare industry, Greg works closely with customers to plan enterprise analytics strategies, evaluate new tools and products, conduct training sessions and hackathons, and architect solutions that improve the quality of care and reduce costs. With years of experience in data architecture and a passion for innovation, Greg has a unique ability to identify and solve complex challenges. He is a trusted advisor to his customers and is always seeking new ways to drive progress and help organizations thrive. For more than 15 years, Greg has worked with healthcare customers who strive to improve patient outcomes and find opportunities for efficiencies. He is a veteran of the Microsoft data speaker network and has worked with hundreds of customers on their data management and analytics strategies.
Read more
  • 0
  • 0
  • 16425

article-image-getting-started-with-chatgpt-advanced-data-analysis-part-2
Joshua Arvin Lat
08 Nov 2023
10 min read
Save for later

Getting Started with ChatGPT Advanced Data Analysis- Part 2

Joshua Arvin Lat
08 Nov 2023
10 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionChatGPT Advanced Data Analysis is an invaluable tool that significantly speeds up the analysis and processing of our data and our files. In the first part of this post, we showcased how to use this feature to generate a CSV file containing randomly generated values. In addition to this, we demonstrated how to utilize different prompts in order to process data stored in files and generate visualizations. In this second part, we’ll build on top of what we learned already and work on more complex examples and scenarios.If you’re looking for the link to the first part, here it is: Getting Started with ChatGPT Advanced Data Analysis- Part 1That said, we will tackle the Example 03, Example 04, and Current Limitations sections in this post:Example 01 — Generating a CSV file (discussed in Part 1)Example 02 — Analyzing an uploaded CSV file, transforming the data, and generating charts  (discussed in Part 1)Example 03 — Processing and analyzing an iPython notebook fileExample 04 — Processing and analyzing the contents of a ZIP fileCurrent LimitationsWhile working on the hands-on examples in this post, you’ll be surprised that ChatGPT Advanced Data Analysis is able to process and analyze various types of files such as Jupyter Notebook (.ipynb) and even ZIP files containing multiple files. As you dive into the features of ChatGPT Advanced Data Analysis, you'll discover that it serves as a valuable addition to your data analysis toolkit. This will help you unlock various ways to optimize your workflow and significantly accelerate data-driven decision-making.Without further ado, let’s begin!Example 03: Processing and analyzing an iPython notebook fileIn this third example, we will process and analyze an iPython notebook file containing blocks of code for deploying machine learning models. Here, we’ll use an existing iPython notebook file I prepared while writing my 1st book “Machine Learning with Amazon SageMaker Cookbook”. If you're wondering what an iPython notebook file is, it's essentially a document produced by the Jupyter Notebook app, which contains both computer code (like Python) and rich text elements (paragraphs, equations, figures, links, etc.). These notebooks are both human-readable documents containing the analysis description and the results (like visualizations) as well as executable code that can be run to perform data analysis. It’s popular among data scientists and researchers for creating and sharing documents that contain live code, equations, visualizations, and narrative text.Now that we have a better idea of what iPython notebook (.ipynb) files are, let’s proceed with our 3rd example:STEP # 01: Open a new browser tab. Navigate to the following link and Download the .ipynb file to your local machine by clicking Download raw file:https://github.com/PacktPublishing/Machine-Learning-with-Amazon-SageMaker-Cookbook/blob/master/Chapter09/03%20-%20Hosting%20multiple%20models%20with%20multi-model%20endpoints.ipynbImage 17 — Downloading the IPython Notebook .ipynb fileTo download the file, simply click the download button highlighted in Image 17. This should download the .ipynb file to your local machine.STEP # 02: Navigate back to the browser tab where you have your ChatGPT session open and create a new chat session by clicking + New Chat. Make sure to select Advanced Data Analysis under the list of options available under GPT-4:Image 18 — Using Advanced Data AnalysisSTEP # 03: Upload the .ipynb file from your local machine to the new chat session and then run the following prompt:What's the ML instance type used in the example?This should yield the following response:Image 19 — Analyzing the uploaded file and identifying what ML instance type is used in the exampleIf you’re wondering what a machine learning (ML) instance is, you can think of it as a server or computer running specific machine learning workloads (such as training and serving machine learning models). Given that running these ML instances could be expensive, it’s best if we estimate the cost of running these instances!STEP # 04: Next, run the following prompt to locate the block of code where the ML instance type is mentioned or used:Print the code block(s) where this ML instance type is usedImage 20 — Locating the block of code where the ML instance type is usedCool, right? Here, we can see that ChatGPT can help us identify blocks of code using the right set of prompts. Make sure to verify the results and files produced by ChatGPT as you might find discrepancies or errors.STEP # 05: Run the following prompt to update the ML instance used in the previous block of code:Update the code block and use an ml.g5.2xlarge instead.Image 21 — Using ChatGPT to perform code modification instructionsHere, we can see that ChatGPT can easily perform code modification instructions as well. Note that ChatGPT is not limited to simply replacing certain portions of code blocks. It is also capable of generating code from scratch! In addition to this, it is capable of reading blocks of code as well.STEP # 06: Run the following prompt to generate a chart comparing the estimated cost per month when running ml.t2.medium and ml.g5.2xlarge inference endpoint instances:Generate a chart comparing the estimated cost per month when running an ml.t2.medium vs an ml.g5.2xlarge SageMaker inference endpoint instanceImage 22 — Estimated monthly cost comparison of running an ml.t2.medium instance vs ml.g5.2xlarge instanceMake sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.Now, let’s proceed with our final example.Example 04: Processing and analyzing the contents of a ZIP fileIn this final example, we will compare the estimated cost per month of running the ML instances in each of the chapters of my book “Machine Learning with Amazon SageMaker Cookbook”. Of course, the assumption in this example is that we’ll be running the ML instances for an entire month. In reality, we’ll only be running these examples for a few seconds (to at most a few minutes).STEP # 01: Navigate to the following link:https://github.com/PacktPublishing/Machine-Learning-with-Amazon-SageMaker-CookbookSTEP # 02:Click Code and then click Download ZIP.Image 23 — Downloading the ZIP file containing the files of the repositoryThis will download a ZIP file containing all the files inside the repository to your local machine.STEP # 03: Create a new chat session by clicking + New Chat. Make sure to select Advanced Data Analysis under the list of options available under GPT-4:Image 24 — Choosing Advanced Data AnalysisSTEP # 04: Upload the downloaded Zip file from an earlier step to the new chat session (using the + button). Enter the following prompt to compare the estimated cost per month associated with running each of the examples per chapter:Analyze the contents of the ZIP file and perform the following: - for each of the directories, identify the ML instance types used - compare the estimated cost per month associated to running the ML instance types in the examples stored in each directory - group the estimated cost per month per chapter directoryThis should process the contents of the ZIP file we uploaded and yield the following response:Image 25 — Comparing the estimated cost per month per chapterWow, that seems expensive! Of course, we will NOT be running these resources for an entire month! In my first book “Machine Learning with Amazon SageMaker Cookbook”, the resources in each of the examples and recipes are only run for a few seconds to at most a few minutes and deleted almost right away. Since we only pay for what we use in Amazon Web Services (AWS), it should only cost a few dollars to complete all the examples in the book.Note that this example can be further improved by utilizing and uploading a spreadsheet with the actual price per hour of each of these instances. In addition to this, it is important to note that there are other cost factors not taken into account in this example as only the cost of running the instances are included. That said, we should also take into account the cost associated with the storage costs associated with the storage volumes attached to the instances, as well as the estimated charges for using other cloud services and resources in the account.STEP # 05: Finally, run the following prompt to compare the estimated monthly cost per chapter when running the examples of the book:Generate a bar chart comparing the estimated monthly cost per chapterThis should yield the following response:Image 26 — Bar chart comparing the estimated monthly cost for running the ML instance types per chapterCool, right? Here, we can see a bar chart that helps us compare the estimated monthly cost of running the examples in each chapter. Again, this is just for demonstration purposes as we will only be running the ML instances for a few seconds to at most a few minutes. This would mean that the actual cost would only be a tiny fraction of the overall monthly cost. In addition to this, it is important to note that there are other cost factors not taken into account in this example as only the cost of running the instances are included. Given that we’re just demonstrating the power of ChatGPT Advanced Data Analysis in this post, this simplified example should do the trick! Finally, make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.Current LimitationsBefore we end this tutorial, it is essential that we mention some of the current limitations (as of writing) when using ChatGPT Advanced Data Analysis. First, there is a file size limitation which restricts users to only uploading files up to a maximum size of 500 MB per file. This could affect those trying to analyze large datasets since they’ll be forced to divide larger files into smaller portions. In addition to this, ChatGPT retains uploaded files only during the active conversation and for an additional three hours after the conversation has been paused. Files are automatically deleted which would require users to re-upload the files to continue the analysis. Finally, we need to be aware that the execution of the instructions is done inside a sandboxed environment. This means that we are currently unable to have external integrations and perform real-time searches. Given that ChatGPT Advanced Data Analysis is still an experimental feature (that is, in Beta mode), there may still be a few limitations and issues being resolved behind the scenes. Of course, by the time you read this post, it may no longer be in Beta!That’s pretty much it. At this point, you should have a great idea on what you can accomplish using ChatGPT Advanced Data Analysis. Feel free to try different prompts and experiment with various scenarios to help you discover innovative ways to visualize and interpret your data for better decision-making.Author BioJoshua Arvin Lat is the Chief Technology Officer (CTO) of NuWorks Interactive Labs, Inc. He previously served as the CTO of 3 Australian-owned companies and also served as the Director for Software Development and Engineering for multiple e-commerce startups in the past. Years ago, he and his team won 1st place in a global cybersecurity competition with their published research paper. He is also an AWS Machine Learning Hero and he has been sharing his knowledge in several international conferences to discuss practical strategies on machine learning, engineering, security, and management. He is also the author of the books "Machine Learning with Amazon SageMaker Cookbook", "Machine Learning Engineering on AWS", and "Building and Automating Penetration Testing Labs in the Cloud". Due to his proven track record in leading digital transformation within organizations, he has been recognized as one of the prestigious Orange Boomerang: Digital Leader of the Year 2023 award winners.
Read more
  • 0
  • 0
  • 16362
Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime
article-image-chatgpt-for-everyday-use
M.T. White
22 Aug 2023
14 min read
Save for later

ChatGPT for Everyday Use

M.T. White
22 Aug 2023
14 min read
IntroductionChatGPT is a revolutionary new technology that is making a large impact on society.  The full impact of ChatGPT cannot be fully known at the time of writing this article because of how novel the technology is.  However, what can be said is that since its introduction many industries have been trying to leverage it and increase productivity.  Simultaneously, everyday people are trying to learn to leverage it as well.  Overall, ChatGPT and similar systems are very new and the full impact of how to leverage them will take some more time to fully manifest.  This article is going to explore how ChatGPT can be used for everyday life by exploring a few use cases.What is ChatGPT?       Before we begin, it is important to understand what ChatGPT is and what it isn’t.  To begin ChatGPT is in a lay sense a super advanced chatbot.  More specifically, ChatGPT is known as a generative AI that uses Natural Language Processing (NLP) to create a dialog between a user and itself.  ChatGPT and similar systems are what are known as Large Language Models (LLMs).  In short, for AI models to work they have to be trained using data.  To train LLMs engineers use vast amounts such as books, articles, journals, and so on.  The result is a system like ChatGPT that has a vast knowledge base on many different subjects.  Before we can explore how to use ChatGPT for everyday life we need to explore how NOT to use ChatGPT. How not to use ChatGPT?ChatGPT is very powerful and can be used for many different things; however, is important to understand that ChatGPT is not a sage nor infallible.  Remember ChatGPT only knows about what it was trained on.  This means if the information it was taught was wrong or outdated so too will be the response it provides.  This means that as of writing this article ChatGPT cannot and should not be used as a replacement for humans.  Even with the answer ChatGPT gives, a decent level of domain knowledge is still required properly format and use its response.  As such, it is important to take suggestions with a certain amount of skepticism.  The best way to think of ChatGPT is as an extremely smart friend with a wide range of knowledge.  Though that friend may be very knowledgeable they can and will be wrong from time to time.  With that how does one use ChatGPT?How to use ChatGPT for everyday life?Using ChatGPT starts with what is called a prompt.  A prompt can be thought of as a query that the user feeds into ChatGPT.  This prompt is kind of like a Google search.  It will be a statement that asks ChatGPT a question or to perform a certain task.  Since ChatGPT used NLP, the prompt does not have to be formatted a certain way nor does it require a specific syntax.  In other words, a prompt can be entered the same way a user would pose the instruction to another person.  However, it is good to provide ChatGPT will enough information to adequately describe the problem.  An example, of a prompt is as follows:How can ChatGPT be used for everyday life?Once the prompt is run ChatGPT will produce text with suggestions, answers, programming software, or whatever was asked for.  That output that is produced is called a response which will have the answer to the request/question. There are a lot of ways ChatGPT can be used for everyday life.  In terms of professional life, ChatGPT can make an excellent assistant.  For most “text-based” jobs, that is jobs that don’t require design such as drawing diagrams, ChatGPT can be an excellent assistant.  For example, suppose a programmer needs a small piece of software for a project, assume they need a SQL query that can pull all the rows between two dates.  The user could use a prompt like the following:Write a SQL query that will pull all rows between January 3 and March 31.This prompt will produce the following response:To pull all rows between January 3 and March 31 from a table, you'll need to use the WHERE clause to filter the results based on the date column. Assuming you have a date column named "date_column" in your table, here's the SQL query: sqlCopy code SELECT * FROM your_table WHERE date_column >= '2023-01-03' AND date_column <= '2023-03-31'; Replace "your_table" with the actual name of your table, and "date_column" with the name of the column that contains the dates you want to filter. The query will select all rows where the "date_column" is on or after January 3, 2023, and on or before March 31, 2023.For those that are not familiar with SQL, the prompt produced a simple query with generic placeholders that will pull the correct data out of a database. Not everyone is a programmer, so how could a non-programmer use ChatGPT as an assistant?  One area in which ChatGPT can be used is by composing emails.  Suppose a salesperson needs to inform Tom, their boss, that a $1 million deal was closed today via email.  They could use a prompt like the following:Write Tom an email saying that the deal with Company X went through, and we made $1 million.The response would be something along the lines of:Subject: Successful Deal with Company X - $1 Million Revenue Achieved Hi Tom, I hope this email finds you well. I am thrilled to share some exciting news with you! The deal with Company X has successfully gone through, and I am delighted to inform you that we have made an astounding $1 million in revenue from this collaboration. This achievement wouldn't have been possible without the hard work and dedication of our entire team. It reflects the trust and confidence our partners have in our capabilities, and I believe it marks a significant milestone for our company's growth and success. I want to express my gratitude to you for your valuable contributions and expertise that played a crucial role in making this deal a reality. Your efforts have been commendable, and I am truly grateful for your commitment to the success of this venture. Let's take a moment to celebrate this triumph together. Your exceptional skills and commitment to excellence have made this accomplishment possible, and I am genuinely proud to have you as part of our team. Looking forward to even more prosperous ventures in the future. Once again, congratulations to you and the entire team! Best regards, [Your Name] [Your Title/Position] [Company Name] [Email] [Phone Number]In this case, all the users would have to do is proofread the email, copy it, and send it.  Now, for applications such as this proofreading is very important.  As stated before, ChatGPT is not a mind reader nor a sage, as such it may produce emails with wrong information, illogical wording, or anything else.  So, it’ll pay to read the message before sending it. Learning ToolA very powerful use of ChatGPT is as a learning tool.  For example, students can use this tool to help them master a new subject, generate practice problems, and even check answers to an extent.  Assume the user needs a few extra practice problems for their English homework, they could enter a prompt like the following:Generate some grammar practice problems for a 1st year English classWhich would yield the following output:Of course! Here are some grammar practice problems suitable for a 1st-year English class: 1. Subject-Verb Agreement: Choose the correct verb form that agrees with the subject in each sentence: a) The cat (purr/purrs) when it is happy. b) My friend and I (is/are) going to the movies tonight. c) Neither the students nor the teacher (understands/understand) the assignment. 2. Pronoun Usage: Select the appropriate pronoun to complete each sentence: a) She invited Sarah and (I/me) to the party. b) My sister and (her/she) are going shopping. c) The book is for (he/him) and his brother. 3. Articles (a/an/the): Insert the correct article (a, an, the, or no article) in each sentence: a) Can you pass me (a/an) apple, please? b) I need to buy (the) new shoes for the dance. c) My friend has (no article) car. 4. Prepositions: Choose the correct preposition to complete each sentence: a) We arrived (in/on/at) the airport fifteen minutes early. b) The cat is sleeping (under/below/above) the table. c) She's going to the store (by/with/for) her mom. 5. Verb Tenses: Identify the correct verb tense used in each sentence: a) They (will be/was) studying for the exam all night. b) By the time we arrived, the party (had started/has started). c) I (am/was) watching a movie right now. 6. Adjective vs. Adverb: Decide whether the word in parentheses should be an adjective or adverb in the sentence: a) She sings (beautiful/beautifully). b) The (happy/happily) children played in the park. c) The (quick/quickly) fox jumped over the fence. 7. Negation: Add the necessary negative word to each sentence: a) I have (no/not) seen him today. b) She does (not/none) like coffee. c) We will (not/none) be attending the party. 8. Passive Voice: Rewrite the following sentences in the passive voice: a) The chef cooked the meal. b) The teacher is explaining the lesson. c) The storm destroyed the old building. 9. Comparative and Superlative Forms: Complete each sentence with the correct comparative or superlative form of the adjective: a) This book is (interesting/more interesting/most interesting) than the last one. b) She is (tall/taller/tallest) than her sister. c) It was the (big/biggest/bigger) cake at the party. 10. Reported Speech: Rewrite the following sentences using reported speech: a) Mary said, "I am going to the store." b) "I will call you later," said John. c) "They have arrived," she said. These grammar practice problems aim to reinforce essential grammar rules and concepts, helping 1st-year English students develop their language skills and proficiency.As can be seen, ChatGPT generated a number of questions that one would usually find in an English 101 class.  Now, if the user wanted a more specific answer that could reword the prompt to accommodate. ChatGPT is also a great teaching tool as well.  Teachers can also use this tool to generate lesson plans, write intros for learning modules, generate problems, and more.  Overall, ChatGPT can be used as an excellent tool for academia in general.Now, it is important to remember that ChatGPT is not all-knowing.  It can only generate responses based on the data that it was trained on.  This means if the user is asking questions about a subject where there is little or no publicly available data the response probably isn’t going to be of the highest quality.  For example, if someone askedHow do I build a working time machine?They’re going to get the following:Building a working time machine, as depicted in science fiction, is currently beyond our technological capabilities and goes against the known laws of physics. Time travel, as popularly imagined, involves traveling backward or forward in time, similar to how we move through space. As of my last update in September 2021, time travel remains a concept explored mainly in theoretical physics, and no practical time machine has been built or proven to be possible. Several theories, such as the theory of relativity, suggest that time travel could be theoretically feasible under certain conditions, but these ideas are still purely theoretical and have not been put into practice. It's important to remember that building a time machine would present enormous scientific, technological, and ethical challenges. It could raise paradoxes, such as the "grandfather paradox," where a time traveler could potentially alter past events and create inconsistencies in history. As of now, time travel remains a fascinating topic in science fiction and theoretical physics, but it is not something that can be practically accomplished with our current understanding and technology. The scientific community continues to explore the nature of time and the universe, but building a working time machine as portrayed in movies and books is not yet a reality.ChatGPT gave some general information on time travel but unfortunately, it didn’t generate any schematics.  Again, this goes back to ChatGPT not being a sage as it only knows what it was “taught”.  Since there is no data on how to build a working time machine ChatGPT could not fully answer the prompt. Now, If one looks at the English question prompt above, one will notice that practice questions were quite broad.  It is common to have to “dig” with ChatGPT.  In other words, a person may have to refine the queriers to get what they need.  To get some practice try re-wording the prompt to generate practice questions for only passive writing.  SummaryChatGPT is a tool, and like any other tool, what it’s used for is up to the user.  As was seen in this article, ChatGPT is an excellent tool for helping a person through their day by generating software, emails, and so on.  ChatGPT can also be used as a great learning or teaching device to help students and teachers generate practice problems, create lesson plans, and so much more.  However, as was stated so many numerous times.  Unless ChatGPT has been trained on something it does not know about it.  This means that asking it things like how to build a time machine or domain specific concepts aren’t going to return quality responses.  Also, even if ChatGPT has been trained on the prompt, it may not always generate a quality response.  No matter the use case, the response should be vetted for accuracy.  This may mean doing a little extra research with the response given, testing the output, or whatever needs to be done to verify the response. Overall, ChatGPT at the time of writing this article is less than a year old.  This means that the full implication of using ChatGPT are not fully understood.  Also, how to fully leverage ChatGPT is not understood yet either.  What can be said is that ChatGPT and similar LLM systems will probably be the next Google.  In terms of everyday use, the only true inhibitors are the user's imagination and the data that was used to train ChatGPT.Author BioM.T. White has been programming since the age of 12. His fascination with robotics flourished when he was a child programming microcontrollers such as Arduino. M.T. currently holds an undergraduate degree in mathematics, and a master's degree in software engineering, and is currently working on an MBA in IT project management. M.T. is currently working as a software developer for a major US defense contractor and is an adjunct CIS instructor at ECPI University. His background mostly stems from the automation industry where he programmed PLCs and HMIs for many different types of applications. M.T. has programmed many different brands of PLCs over the years and has developed HMIs using many different tools.Author of the book: Mastering PLC Programming
Read more
  • 0
  • 0
  • 16351

article-image-openai-and-chatgpt-for-enterprises
Valentina Alto
14 Sep 2023
9 min read
Save for later

OpenAI and ChatGPT for Enterprises

Valentina Alto
14 Sep 2023
9 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!This article is an excerpt from the book, Modern Generative AI with ChatGPT and OpenAI Models, by Valentina Alto. Harness the power of AI with innovative, real-world applications, and unprecedented productivity boosts, powered by the latest advancements in AI technology like ChatGPT and OpenAIIntroductionIn this article, we’ll focus on the enterprise-level applications of OpenAI models and introduce the partnership between OpenAI and Microsoft and Azure OpenAI (AOAI) Service. We will go through the milestones and developments of Microsoft in the field of artificial intelligence (AI), highlighting the journey that brought the Azure cloud into the game of OpenAI, and why this is a game-changer for large organizations. Finally, we will consider the topic of responsible AI and how to make sure your AI system complies with ethical standards.In this article, we will discuss the following topics:The history of the partnership between Microsoft and OpenAI and the introduction of AOAI ServiceThe role of the public cloud in the context of OpenAI models Responsible AITechnical requirementsThe following are the technical requirements for this article: An Azure subscription, which you can create for free here: https://azure.microsoft. com/free/cognitive-services.Access granted to Azure OpenAI in the desired Azure subscription. At the time of writing, access to this service is granted only by application. You can apply for access to Azure OpenAI by completing the form at https://aka.ms/oai/accessAzure OpenAI ServiceAOAI Service is a product of Microsoft that provides REST API access to OpenAI’s powerful language models such as GPT-3.5, Codex, and DALL-E. You can use these models for the very same tasks as OpenAI models, such as content generation, summarization, semantic search, natural language, and code translation.In the context of the Microsoft Azure AI portfolio, AOAI Service is collocated among the following Cognitive Services offerings:Figure - AOAI Service General Availability (GA)As with any other Cognitive Services offering, AOAI offers models that have already been trained and are ready to be consumed.To create your AOAI resource, follow these instructions:1.      Navigate to the Azure portal at https://ms.portal.azure.com.2.      Click on Create a resource.3.      Type azure openai and click on Create.4.      Fill in the required information and click on Review + create.This is shown in the following screenshot:Figure  – Steps to create an AOAI resourceThis process might take a few minutes. Once it is ready, you can directly jump to its user-friendly interface, AOAI Playground, to test your models before deploying them:Figure  – AOAI UI and PlaygroundNote that AOAI Playground looks almost identical to the OpenAI Playground version we saw in Chapter 2. The difference here is that, to use AOAI models, you have to initiate a deployment, which is a serverless compute instance you can attach to a model. You can do so either in Playground or on the resource backend page in the Azure portal:Figure – Creating a new AOAI deployment via Playground (A) or in the Azure portal (B)For example, I created a deployment called text-davinci-003 with an associated textdavinci-003 model:Figure 9.7 – An active deployment of AOAIIn OpenAI Playground, we can test those models either directly via the user interface or by embedding their APIs into our applications. In the next section, we are going to explore how to interact with Playground and try different models’ configurations. In Chapter 10, we will learn how to integrate AOAI’s Models API into enterprise applications.Exploring PlaygroundAOAI Playground is the easiest way to get familiar with the underlying models and start planning which model’s version is the most suitable for your projects. The user interface presents different tabs and workspaces, as shown in the following screenshot:Figure - Overview of AOAI PlaygroundLet’s explore each of them:Playground | Chat: The Chat workspace is designed to be only used with conversational models such as GPT-3.5-turbo (the model behind ChatGPT):Figure – AOAI Chat workspaceIt offers a similar experience to ChatGPT itself, with the possibility to configure your model with additional parameters (as we saw in Chapter 2 with OpenAI Playground). Furthermore, there is an additional feature that makes the Chat workspace very interesting, known as System message:         Figure – Example of System messageSystem message is the set of instructions we give the model to tell it how to behave and interact with us. As for the prompt, System message represents a key component of a model’s configuration since it massively affects model performance.For example, let’s instruct our model to behave as a JSON formatter assistant:Figure – Example of a model acting as a JSON formatter assistantAs you can see from the previous screenshot, the model was able to suggest a JSON file through some simple data, such as name and age, without the need to specify any labels.Playground | Completions: Different from the previous workspace, the Completions workspace offers a sort of white paper where you can interact with your models. While GPT-3.5-turbo is designed for conversational tasks (which means it can be consumed via a chatbot-like interface), the GPT-3 series contains more general-purpose models and can be used for a wide range of language tasks, such as content generation, summarization, and so on.For example, we could ask our model to generate a quiz by giving it a description of the topic and a one-shot example, as shown here:Figure – Example of a GPT model generating a quizFinally, as per the Chat workspace, with Completions, you can configure parameters such as the maximum number of tokens or the temperature (refer to Chapter 2 for a comprehensive list of those parameters and their meanings).Management | Deployments: Within the Deployments tab, you can create and manage new deployments to be associated with AOAI models. They are depicted here:Figure – List of AOAI deploymentsEach deployment can host only one model. You can edit or delete your deployments at any time. As we mentioned previously, a model deployment is the enabler step for using either the Completions or Chat workspace within AOAI Service.Management | Models: Within this tab, you can quickly assess the models that are available within AOAI Service and, among them, those that can be deployed (that is, a model that hasn’t been deployed yet). For example, let’s consider the following screenshot:Figure – List of AOAI modelsHere, we have text-similarity-curie-001. It doesn’t have an associated deployment, so it can be deployed (as the Deployable column shows). On the other hand, text-similarityada-002 already has a deployment, so it is not available anymore. Within this tab, you can also create a custom model by following a procedure called fine-tuning.We explored this in Chapter 2:Figure – Example of model fine-tuningStarting from this guided widget, you can upload your training and validation data to produce a customized model, starting from a base model (namely, text-davinci-002), which will be hosted on a dedicated deployment.NoteIn Chapter 2, we saw that the training dataset should align with a specific format of the following type (called JSONL):{"prompt": "<prompt text>", "completion": "<ideal generated text>"}{"prompt": "<prompt text>", "completion": "<ideal generated text>"}{"prompt": "<prompt text>", "completion": "<ideal generated text>"}...To facilitate this formatting, OpenAI has developed a tool that can format your data into this specific format ready for fine-tuning. It can also provide suggestions on how to modify data so that the tool can be used for fine-tuning. Plus, it accepts various data formats as inputs, including CSV, TXT, and JSON.To use this tool, you can initialize the OpenAI command-line interface (CLI) by running the following command: pip install --upgrade openaiOnce initialized, you can run the tool, as follows:openai tools fine_tunes.prepare_data -f <LOCAL_FILE>Management | File Management: Finally, within the File Management tab, you can govern and upload your training and test data directly from the user interface, as shown here:Figure – Example of uploading a file within AOAI ServiceYou can decide to upload files by selecting Local file or Azure blob or other shared web locations. Once you’ve uploaded your files, you will be able to select them while creating customized models, via the Models tab.Finally, as mentioned in the previous section, each model comes with a REST API that can be consumed in your applications.ConclusionIn this article, we saw how the partnership between OpenAI and Microsoft has brought about a powerful and innovative AI solution for enterprise-level organizations: AOAI. This service combines OpenAI’s cutting-edge technology with Microsoft’s extensive cloud infrastructure to provide businesses with a scalable and customizable platform for building and deploying advanced AI applications.We also dwelled on Microsoft’s strong focus on responsible AI practices and ethics, and how AOAI Service reflects this commitment to responsible AI, with features such as a content filter built into the platform.As AI continues to transform industries and shape our future, the collaboration between OpenAI and Microsoft marks an important milestone in the development of enterprise-level AI solutions. AOAI empowers businesses to harness the power of AI to drive growth and innovation while ensuring ethical and responsible practices.Author BioValentina Alto graduated in 2021 in data science. Since 2020, she has been working at Microsoft as an Azure solution specialist, and since 2022, she has been focusing on data and AI workloads within the manufacturing and pharmaceutical industry. She has been working closely with system integrators on customer projects to deploy cloud architecture with a focus on modern data platforms, data mesh frameworks, IoT and real-time analytics, Azure Machine Learning, Azure Cognitive Services (including Azure OpenAI Service), and Power BI for dashboarding. Since commencing her academic journey, she has been writing tech articles on statistics, machine learning, deep learning, and AI in various publications and has authored a book on the fundamentals of machine learning with Python.
Read more
  • 0
  • 0
  • 15861

article-image-getting-started-with-chatgpt-advanced-data-analysis-part-1
Joshua Arvin Lat
08 Nov 2023
10 min read
Save for later

Getting Started with ChatGPT Advanced Data Analysis- Part 1

Joshua Arvin Lat
08 Nov 2023
10 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionImagine having a spreadsheet containing the certification exam scores of various members of the organization. In the past, we had to spend some time writing code that generates charts from existing comma-separated values (CSV) files and Excel spreadsheets. Instead of writing code, we could also generate charts directly in Google Spreadsheets or Microsoft Excel. We might even be tempted to utilize business intelligence tools for this type of requirement. Now, it is possible to generate charts immediately using the right set of prompts with ChatGPT Advanced Data Analysis!In this two-part post, we will showcase a few examples of what we can do using the ChatGPT Advanced Data Analysis feature. You would be surprised how powerful this capability is for solving various types of requirements and tasks. While the general audience might think of ChatGPT as being limited only to text-based conversations, its advanced data analysis capabilities go beyond just textual interactions. With its ability to understand and process various types of datasets and files, it can produce useful visualizations and perform data analysis and data transformation tasks.To demonstrate what we can do with this feature, we’ll have the following sections in this post:Example 01 — Generating a CSV fileExample 02 — Analyzing an uploaded CSV file, transforming the data, and generating chartsExample 03 — Processing and analyzing an iPython notebook file (discussed in Part 2)Example 04 — Processing and analyzing the contents of a ZIP file (discussed in Part 2)Current Limitations  (discussed in Part 2)Whether you're a student working on a project or an analyst trying to save time on manual data analysis and processing tasks, ChatGPT's Advanced Data Analysis feature can be a game-changer for your data processing needs. That said, let's dive into some of its powerful features and see what we can accomplish using this amazing feature!Example 01: Generating a CSV fileIn this first example, we will (1) enable Advanced data analysis, (2) generate a comma separated values (CSV) file containing random values, and (3) download the CSV file to our local machine. We will use this generated CSV file in the succeeding examples and steps.STEP # 01: Let’s start by signing in to your ChatGPT account. Open a new web browser tab and navigate to https://chat.openai.com/auth/login.Image 01 — Signing in to your OpenAI accountClick Log in and sign in using your registered email address and password. If you don’t have an account yet, make sure to sign up first. Since we will be using the Advanced Data Analysis feature, we need to upgrade our plan to ChatGPT Plus so that we have access to GPT-4 along with other features only available to ChatGPT Plus users.STEP # 02: Make sure that Advanced data analysis is enabled before proceeding.Image 02 — Enabling the Advanced data analysis featureSTEP # 03: Create a new chat session by clicking + New Chat. Make sure to select Advanced Data Analysis under the list of options available under GPT-4:Image 03 — Using Advanced Data AnalysisSTEP # 04: In the chat box with the placeholder text “Send a message”, enter the following prompt to generate a CSV file containing 4 columns with randomly generated values:Generate a downloadable CSV spreadsheet file with 4 columns: - UUID - Name - Team - Score Perform the following: - For the UUID column, generate random UUID values - For the Name column, generate random full names - For the Team column, make sure to select only from the following teams: Technology, Business Development, Operations, Human Resources - For the Score column, generate random whole numbers between 1 to 10 - Have a total of 20 rowsAfter a few seconds, ChatGPT will give us a response similar to what we have in Image 04.Image 04 — ChatGPT generating a CSV fileHere, we can see that ChatGPT was able to successfully generate a CSV file. Awesome, right?STEP # 05: Click download it here to download the generated CSV file to your local machine. Feel free to inspect the downloaded file and verify if the instructions were implemented correctly. Make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.STEP # 06: Now, click Show work.Image 05 — Code used to generate the CSV fileThis should display the code or script used to perform the operations instructed by the user. You should be able to copy the code, modify it, and run it separately in your local machine or a cloud server.Wasn’t that easy? Now, let’s proceed to our second example.Example 02: Analyzing an uploaded CSV file, transforming the data, and generating chartsIn this second example, we will upload the generated CSV file from the previous example and perform various types of data transformations and analysis.STEP # 01: Create a new chat session by clicking + New Chat. Make sure to select Advanced Data Analysis under the list of options available under GPT-4:Image 06 — Creating a new chat session using Advanced Data AnalysisSTEP # 02: Click the + button and upload the downloaded file from the earlier example. In addition to this, enter the following prompt:Analyze the uploaded CSV file and perform the following: - Group the records by Team - Sort the records from highest to lowest (per team) Display the table and generate a downloadable CSV file containing the final outputThis should yield a response similar to what we have in the following image:Image 07 — Using ChatGPT to analyze the uploaded CSV fileGiven that the data is randomly generated, you will get a different set of results. What’s important is that there are 4 columns: UUID (Universal Unique Identifier), Name, Team, and Score in the generated CSV file and in what is displayed in the table.STEP # 03: Click the Show work button:Image 08 — Code used to read and process the uploaded CSV fileHere, we can see that ChatGPT used Pandas DataFrames to process the data behind the scenes.STEP # 04: Locate and click the download the grouped and sorted CSV file here button. Feel free to inspect the downloaded file. Make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.STEP # 05: Next, enter the following prompt to generate a bar chart to compare the average scores per team:Generate a bar chart to compare the average scores per teamThis should yield the following response:Image 09 — Generating a bar chartCool, right? Here, we were able to generate a bar chart in ChatGPT. Imagine the different variations, scenarios, and possibilities of what we can do with this feature! Now, let’s check what’s happening behind the scenes in the next step.STEP # 06: Click Show workImage 10 — Code used to generate a bar chartThis should display a block of code similar to what is shown in Image 10. Here, we can see that matplotlib was used to generate the bar chart in the previous step. If you have not used matplotlib before, it’s a popular library for creating static and interactive visualizations in Python. Instead of coding this ourselves, all we need now is the right prompt!STEP # 07: Now, let’s run the following prompt to compare the maximum scores achieved by the members of each team:Generate a bar chart to compare the max scores per teamThis should yield the following response:Image 11 — Generating a bar chart to compare the max scores per teamHere, we see a bar chart comparing the maximum score achieved by the members of each team. Given that the data used was randomly generated in an earlier step, you might get a slightly different chart with different maximum score values per team. Make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors. STEP # 08: Enter the following prompt to group the records per team and generate a CSV file for each team:Divide the original uploaded CSV file and generate separate downloadable CSV files grouped per teamAfter a few seconds, ChatGPT will give us the following response:Image 12 — Dividing the original uploaded CSV file and generating multiple CSV files per teamFeel free to download the CSV files generated to your local machine.STEP # 09: Click Show workImage 13 — Code used to generate CSV files per teamSTEP # 10: Use the following prompt to generate a ZIP file containing the CSV files from the previous step:Generate a downloadable ZIP file containing the CSV files generated in the previous answerChatGPT should give us the following response:Image 14 — Generating a downloadable ZIP fileHere, we should be able to download the ZIP file to our local machine/laptop. Feel to verify if the CSV files are inside the ZIP file by extracting the contents and reviewing each file extracted.STEP # 11: Run the following prompt to convert the CSV files to XLSX (which is a well-known format for Microsoft Excel documents):Convert each file inside the ZIP file to XLSX and generate a new ZIP containing the XLSX filesChatGPT should give us the following response:Image 15 — ChatGPT generating a ZIP file for usAmazing, right? While we’ve been using CSV files in our examples, it does not mean that we’re limited to these types of files only. Here, we can see that we can work with XLSX files as well.STEP # 12: Download the ZIP file and open it on your local machine/laptop.STEP # 13: Run the following prompt to generate a ZIP file with all the charts generated in the current chat thread:Generate a ZIP file containing all the charts and images generated in this chat threadThis should yield the following response:Image 16 — Generating a ZIP file containing all the charts and images generated in the chat threadAmazing, right? Now, all we need to do is download the ZIP file using the link provided by ChatGPT.STEP # 14: Download the ZIP file and open it on your local machine/laptop. Make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.ConclusionThat wraps up the first part of this post. At this point, you should have a good idea of what you can accomplish using ChatGPT Advanced Data Analysis. However, there’s more in store for us in the second part as we’ll build on top of what we learned already and work on more complex examples and scenarios!If you’re looking for the link to the second part, here it is: Getting Started with ChatGPT Advanced Data Analysis- Part 2.Author BioJoshua Arvin Lat is the Chief Technology Officer (CTO) of NuWorks Interactive Labs, Inc. He previously served as the CTO of 3 Australian-owned companies and also served as the Director for Software Development and Engineering for multiple e-commerce startups in the past. Years ago, he and his team won 1st place in a global cybersecurity competition with their published research paper. He is also an AWS Machine Learning Hero and he has been sharing his knowledge in several international conferences to discuss practical strategies on machine learning, engineering, security, and management. He is also the author of the books "Machine Learning with Amazon SageMaker Cookbook", "Machine Learning Engineering on AWS", and "Building and Automating Penetration Testing Labs in the Cloud". Due to his proven track record in leading digital transformation within organizations, he has been recognized as one of the prestigious Orange Boomerang: Digital Leader of the Year 2023 award winners.
Read more
  • 0
  • 0
  • 15798

article-image-intelligent-content-curation-with-chatgpt
Sangita Mahala
01 Nov 2023
8 min read
Save for later

Intelligent Content Curation with ChatGPT

Sangita Mahala
01 Nov 2023
8 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionContent curation is a crucial aspect of giving your audience the right information, in an appropriate and timely manner. This involves selecting, organising and displaying content from a variety of sources. You can enhance your content curation process through ChatGPT, which is based on the advanced language model of OpenAI.In this hands-on guide, you'll learn how to use the ChatGPT for intelligent content curation, with step-by-step examples and accompanied by expected output.Why Intelligent Content Curation?Intelligent content curation is important for a number of reasons, it is important that content be curated in an efficient manner. In particular, it may provide you with a means of saving time and resources. You will be able to focus on other tasks such as developing new content or interacting with your viewers by using an automation of the content curation process.Second, you may be able to enhance the quality of your content with Intelligent Content Curation. From a range of sources, such as academia, industry publications, and social media, ChatGPT is able to identify appropriate content. It means you can be certain that your content is based on the most recent information and research.Lastly, you might benefit from intelligent content curation in reaching out to a wider audience. You can take advantage of the ChatGPT service to determine which content is most relevant for your target audience and how it should be spread across a number of channels. That way, you'll be able to increase traffic on your website, engage and your social media following.How ChatGPT Can Be Used for Intelligent Content Curation?ChatGPT is a sophisticated AI language model that can be used to perform any number of functions, e.g. in the intelligent curation of articles. The following may be used with ChatGPT:Generate search queries: ChatGPT can be used to generate search queries that are relevant to a specific topic and audience. This can be done by providing ChatGPT with a brief description of the topic and the audience.Identify relevant content: The identification of relevant content from a range of sources can be carried out using ChatGPT. If this is the case, you may provide your ChatGPT with a list of URLs or access to an online content database.Select the best content: In the case of selecting content, ChatGPT will be able to organize it into an understandable and interactive format. To do that, you can send a template to ChatGPT or give instructions on how the content should be organized.Organize the content: To organize the collected content in a logical and interesting format, it is possible to use ChatGPT. This is possible by providing ChatGPT with a template, which will give instructions on how to organize the content.Prerequisites and Setting Up the EnvironmentLet's provide you with the essential prerequisites before we start to work on Intelligent Content curation in ChatGPT:Access to the ChatGPT API.A Python environment is installed on your system.Required Python libraries: openai, requests.You must install the basic libraries and create an environment in order to get started. To access the ChatGPT API, you're going to have to use an ‘openai’ library. Install it using pip:pip install openai requestsThen, in the code examples, replace "YOUR_API_key" with your actual key to obtain a ChatGPT API key.Hands-on Examples1. Basic Content CurationExample 1: Curating News HeadlinesIn this first task, we're going to focus on content curation and sorting out news headlines that relate to a specific topic. We'll request a list of news stories based on this theme to be generated by ChatGPT.Input code:import openai api_key = "YOUR_API_KEY" # Function to curate news headlines def curate_news_headlines(topic):    openai.api_key = api_key    response = openai.Completion.create(        engine="davinci",        prompt=f"Curate news headlines about {topic}:\n- ",        max_tokens=100    )    return response.choices[0].text.strip() # Test news headline curation topic = "artificial intelligence" curated_headlines = curate_news_headlines(topic) print(curated_headlines) Output:Example 2: Curating Product DescriptionsLet's examine content curation when describing a product with this example. For an e-shop platform, you can use the ChatGPT tool to draw up attractive product descriptions.Input code:# Function to curate product descriptions def curate_product_descriptions(products):    openai.api_key = api_key    response = openai.Completion.create(        engine="davinci",        prompt=f"Create product descriptions for the following products:\n1. {products[0]}\n2. {products[1]}\n3. {products[2]}\n\n",        max_tokens=200    )    return response.choices[0].text.strip() # Test product description curation products = ["Smartphone", "Laptop", "Smartwatch"] product_descriptions = curate_product_descriptions(products) print(product_descriptions)Output:2. Enhancing Content Curation with ChatGPTExample 1: Generating Blog Post IdeasThe curation process does not exclusively focus on the selection of current content; it can also include developing ideas to produce new ones. We're going to ask ChatGPT to come up with blog posts for a specific niche in this example.Input code:# Function to generate blog post ideas def generate_blog_post_ideas(niche):    openai.api_key = api_key    response = openai.Completion.create(        engine="davinci",        prompt=f"Generate blog post ideas for the {niche} niche:\n- ",        max_tokens=150    )    return response.choices[0].text.strip() # Test blog post idea generation niche = "digital marketing" blog_post_ideas = generate_blog_post_ideas(niche) print(blog_post_ideas)Output:Example 2: Automated Content SummarizationA summary of lengthy articles or reports is often part of the advanced content curation process. In order to speed up content summarization, ChatGPT can be used.Input code:# Function for automated content summarization def automate_content_summarization(article):    openai.api_key = api_key    response = openai.Completion.create(        engine="davinci",        prompt=f"Summarize the following article:\n{article}\n\nSummary:",        max_tokens=150    )    return response.choices[0].text.strip() # Test automated content summarization article = "In a recent study, researchers have made significant progress in understanding the effects of climate change on polar bear populations. The study, conducted over five years, involved tracking bear movements and monitoring ice floe patterns." summary = automate_content_summarization(article) print(summary)Output:"In a recent study, researchers have made significant progress in understanding the effects of climate change on polar bear populations. The study, conducted over five years, involved tracking bear movements and monitoring ice floe patterns. Summary: The study's findings shed light on the impact of climate change on polar bear populations and their habitats, providing valuable insights into their conservation."Example 3: Customized Content GenerationCustomized content generation, such as the creation of personalized newsletters, may be required for advanced content curation. The ChatGPT service can assist with the creation of custom content.Input Code:# Function for generating a customized newsletter def generate_customized_newsletter(user_interests):    openai.api_key = api_key    response = openai.Completion.create(        engine="davinci",        prompt=f"Create a customized newsletter for a user interested in {', '.join(user_interests)}:\n\n",        max_tokens=500    )    return response.choices[0].text.strip() # Test customized newsletter generation user_interests = ["technology", "AI", "blockchain"] customized_newsletter = generate_customized_newsletter(user_interests) print(customized_newsletter)Output:ConclusionIn conclusion, ChatGPT can be a useful tool for intelligent curation of content. It showed how the ChatGPT could help with tasks such as the generation of query queries, identification of pertinent content, selection of best content, and collection of collected information through examples and insight. If you have the right setup and prompt, it can be a powerful resource for content creators and marketing agents who want to provide audiences with more relevant and enjoyable content, making ChatGPT an efficient way of streamlining their content curation process. Make sure you adapt the code and examples for your content curation needs, and continue experimenting to further improve your Content Curation Strategy.Author BioSangita Mahala is a passionate IT professional with an outstanding track record, having an impressive array of certifications, including 12x Microsoft, 11x GCP, 2x Oracle, and LinkedIn Marketing Insider Certified. She is a Google Crowdsource Influencer and IBM champion learner gold. She also possesses extensive experience as a technical content writer and accomplished book blogger. She is always Committed to staying with emerging trends and technologies in the IT sector.
Read more
  • 0
  • 0
  • 15707
article-image-ai-distilled-25-openais-gpt-store-and-gpt-4-turbo-xais-grok-stability-ais-3d-model-generator-microsofts-phi-15-gen-ai-powered-vector-search-apps
Merlyn Shelley
10 Nov 2023
12 min read
Save for later

AI_Distilled #25: OpenAI’s GPT Store and GPT-4 Turbo, xAI’s Grok, Stability AI’s 3D Model Generator, Microsoft’s Phi 1.5, Gen AI-Powered Vector Search Apps

Merlyn Shelley
10 Nov 2023
12 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!The AI Product Manager's Handbook ($35.99 Value) FREE for a limited time! Gain expertise as an AI product manager to effectively oversee the design, development and deployment of AI products. Master the skills needed to bring tangible value to your organization through successful AI implementation.Seize this exclusive opportunity and grab your copy now before it slips away on November 16th!  👋 Hello ,Step into another edition of AI_Distilled, brimming with updates in AI/ML, LLMs, NLP, GPT, and Gen AI. Our aim is to help you enhance your AI skills and stay abreast of the ever-evolving trends in this domain. Let’s get started with our news and analysis with an industry expert’s opinion. “Unfortunately, we have biases that live in our data, and if we don’t acknowledge that and if we don’t take specific actions to address it then we’re just going to continue to perpetuate them or even make them worse.” - Kathy Baxter, Responsible AI Architect, Salesforce. Baxter made an important point, for data underlies ML models, and errors will simply result in a domino effect that can have drastic consequences. Equally important is how AI handles data privacy, especially when you consider how apps like ChatGPT have now crossed 100 million weekly users. The Apple CEO recently hinted at major investments in responsible AI, which will likely transform smart handheld devices in 2024 with major AI upgrades. In this issue, we’ll talk about OpenAI unveiling major upgrades and features including GPT-4 Turbo model and DALL-E 3 API, Microsoft’s new breakthrough with smaller AI model, Elon Musk unveiling xAI’s "Grok" competing with GPT, and OpenAI launching the GPT Store for user-created custom AI models. We’ve also got you your fresh dose of AI secret knowledge and tutorials on unlocking zero-shot adaptive prompting for LLMs, creating a Python chat web app with OpenAI's API and Reflex, and 9 open source tools to boost your AI app. 📥 Feedback on the Weekly EditionWhat do you think of this issue and our newsletter?Please consider taking the short survey below to share your thoughts and you will get a free PDF of the “The Applied Artificial Intelligence Workshop” eBook upon completion. Complete the Survey. Get a Packt eBook for Free!Writer’s Credit: Special shout-out to Vidhu Jain for their valuable contribution to this week’s newsletter content!  Cheers,  Merlyn Shelley  Editor-in-Chief, Packt  Ready to level up your coding game?  🚀 Dive into the Software Supply Chain Security Survey and let's talk vulnerabilities, security practices, and all things code!  🤓 Share your insights and stand a chance to snag some epic prizes, including the coveted MX Master 3S, Raspberry Pi 4 Model B 4GB, $5 Udemy gift credits, and more!  🌟 Your code-savvy opinions could be your ticket to tech greatness.  Don't miss out—join the conversation now! 👩‍💻  Interested? Tell us what you think! SignUp | Advertise | Archives⚡ TechWave: AI/GPT News & Analysis🔹 OpenAI Unveils Major Upgrades and Features Including GPT-4 Turbo Model, DALL-E 3 API, Crosses 100 million Weekly Users: At its DevDay event, OpenAI announced significant new capabilities and lower pricing for its AI platform. This includes a more advanced GPT-4 Turbo model with 128K context size and multimodal abilities. OpenAI also released new developer products like the Assistants API and DALL-E 3 integration. Additional updates include upgraded models, customization options, expanded rate limits, and the Copyright Shield protection. Together these represent major progress in features, accessibility and affordability. ChatGPT also achieved 100 million weekly users and over two million developers, marking a significant milestone in its growth.  🔹 Stability AI Launches AI-Powered 3D Model Generator: Stability AI debuts Stable 3D, empowering non-experts to craft 3D models through simple descriptions or image uploads. The tool generates editable .obj files, marking the company's entry into the AI-driven 3D modeling landscape. Questions about training data origin and prior copyright controversies arise, highlighting a strategic move amid financial struggles. 🔹 Apple CEO Hints at Generative AI Plans: Apple CEO Tim Cook hinted at significant investments in generative AI during the recent earnings call. While specifics were not disclosed, Cook emphasized responsible deployment over time. Apple's existing AI in iOS and Apple Watch showcases its commitment, with rumors suggesting major AI updates in 2024, solidifying Apple's leadership in the space. 🔹 Microsoft Unveils Breakthrough with Smaller AI Model: Microsoft researchers revealed a major new capability added to their small AI model Phi 1.5. It can now interpret images, a skill previously limited to much larger models like OpenAI's ChatGPT. Phi 1.5 has only 1.3 billion parameters compared to GPT-4's 1.7 trillion, making it exponentially more efficient. This shows less expensive AI can mimic bigger models. Smaller models need less computing power, saving costs and emissions. Microsoft sees small and large models as complementary, optimizing tasks between them. The breakthrough signals wider access to advanced AI as smaller models spread.🔹 OpenAI Unveils GPT Store for User-Created Custom AI Models: OpenAI introduces GPTs, allowing users to build custom versions of ChatGPT for specific purposes with no coding experience required, opening up the AI marketplace. These GPTs can range from simple tasks like recipe assistance to complex ones such as coding or answering specific questions. The GPT Store will soon host these creations, enabling users to publish and potentially monetize them, mirroring the App Store model's success. OpenAI aims to pay creators based on their GPTs' usage, encouraging innovation. However, this move may create challenges in dealing with industry giants like Apple and Microsoft, who have their app models and platforms. 🔹 Elon Musk Drops xAI's Game-Changer: Meet Grok, the LLM with Real-Time Data, Efficiency, and a Dash of Humor! Named after the slang term for "understanding," Grok is intended to compete with AI models like OpenAI's GPT. It's currently available to a limited number of users in the United States through a waitlist on xAI's website. Grok is designed with impressive efficiency, utilizing half the training resources of comparable models. It brings humor and wit to AI interactions, aligning with Musk's goal of creating a "maximum truth-seeking AI." ***************************************************************************************************************************************************************🔮 Expert Insights from Packt Community Machine Learning with PyTorch and Scikit-Learn - By Sebastian Raschka, Yuxi (Hayden) Liu, Vahid Mirjalili Solving interactive problems with reinforcement learning Another type of machine learning is reinforcement learning. In reinforcement learning, the goal is to develop a system (agent) that improves its performance based on interactions with the environment. Since the information about the current state of the environment typically also includes a so-called reward signal, we can think of reinforcement learning as a field related to supervised learning. However, in reinforcement learning, this feedback is not the correct ground truth label or value, but a measure of how well the action was measured by a reward function. Through its interaction with the environment, an agent can then use reinforcement learning to learn a series of actions that maximizes this reward via an exploratory trial-and-error approach or deliberative planning. Discovering hidden structures with unsupervised learning In supervised learning, we know the right answer (the label or target variable) beforehand when we train a model, and in reinforcement learning, we define a measure of reward for particular actions carried out by the agent. In unsupervised learning, however, we are dealing with unlabeled data or data of an unknown structure. Using unsupervised learning techniques, we are able to explore the structure of our data to extract meaningful information without the guidance of a known outcome variable or reward function. Finding subgroups with clustering Clustering is an exploratory data analysis or pattern discovery technique that allows us to organize a pile of information into meaningful subgroups (clusters) without having any prior knowledge of their group memberships. Each cluster that arises during the analysis defines a group of objects that share a certain degree of similarity but are more dissimilar to objects in other clusters, which is why clustering is also sometimes called unsupervised classification. Clustering is a great technique for structuring information and deriving meaningful relationships from data. For example, it allows marketers to discover customer groups based on their interests, in order to develop distinct marketing programs. Dimensionality reduction for data compression Another subfield of unsupervised learning is dimensionality reduction. Often, we are working with data of high dimensionality—each observation comes with a high number of measurements—that can present a challenge for limited storage space and the computational performance of machine learning algorithms. Unsupervised dimensionality reduction is a commonly used approach in feature preprocessing to remove noise from data, which can degrade the predictive performance of certain algorithms. Dimensionality reduction compresses the data onto a smaller dimensional subspace while retaining most of the relevant information. This content is from the book “Machine Learning with PyTorch and Scikit-Learn” writtern by Sebastian Raschka, Yuxi (Hayden) Liu, Vahid Mirjalili (Feb 2022). Start reading a free chapter or access the entire Packt digital library free for 7 days by signing up now. To learn more, click on the button below. Read through the Chapter 1 unlocked here...  🌟 Secret Knowledge: AI/LLM Resources💡 Enhancing User Experiences with AI-PWAs in Web Development: This article explores the integration of AI and Progressive Web Applications (PWAs) to revolutionize website development. Learn how AI chatbots and generative AI, such as OpenAI's GPT-3, can personalize content and streamline coding. Discover the benefits of combining AI technology with PWAs, including improved user engagement, streamlined content generation, and enhanced scalability.  💡 Boosting Your AI App with 9 Open Source Tools: From LLM queries to chatbots and AI app quality, explore projects like LLMonitor for cost analytics and user tracking, Guidance for complex agent flows, LiteLLM for easy integration of various LLM APIs, Zep for chat history management, LangChain for building powerful AI apps, DeepEval for LLM application testing, pgVector for embedding storage and similarity search, promptfoo for testing prompts and models, and Model Fusion, a TypeScript library for AI applications. These tools can help you optimize and streamline your AI projects, improving user experiences and productivity. 💡 Creating Gen AI-Powered Vector Search Applications with Vertex AI Search: Learn how to harness the power of generative AI and vector embeddings to build user experiences and applications. Vector embeddings are a way to represent various types of data in a semantic space, enabling developers to create applications such as finding relevant information in documents, personalized product recommendations, and more. The article introduces vector search, a service within the Vertex AI Search platform, which helps developers find relevant embeddings quickly. It offers scalability, adaptability to changing data, security features, and easy integration with other AI tools.  🔛 Masterclass: AI/LLM Tutorials🔑 Integrating Amazon MSK with CockroachDB for Real-Time Data Streams: This guide offers a comprehensive step-by-step process for integrating Amazon Managed Streaming for Apache Kafka (Amazon MSK) with CockroachDB, creating a robust and scalable pipeline for real-time data processing. The integration enables various use cases, such as real-time analytics, event-driven microservices, and audit logging, enhancing businesses' ability to provide immediate, personalized experiences for customers. 🔑 Understanding GPU Workload Monitoring on Amazon EKS with AWS Managed Services: As the demand for GPU-accelerated ML workloads grows, this post offers valuable insights into monitoring GPU utilization on Amazon Elastic Kubernetes Service (EKS) using AWS managed open-source services. Amazon EC2 instances with NVIDIA GPUs are crucial for efficient ML training. The article explains how GPU metrics can provide essential information for optimizing resource allocation, identifying anomalies, and enhancing system performance.  🔑 Unlocking Zero-Shot Adaptive Prompting for LLMs: This study explores LLMs, emphasizing their prowess in solving problems in both few-shot and zero-shot scenarios. It introduces "Consistency-Based Self-Adaptive Prompting (COSP)" and "Universal Self-Adaptive Prompting (USP)" to generate robust prompts for diverse tasks in natural language understanding and generation. 🔑 Exploring Interactive AI Applications with OpenAI's GPT Assistants and Streamlit: This post unveils a cutting-edge Streamlit app integrating OpenAI's GPT models for interactive Wardley Mapping instruction. It details development, emphasizing GPT-4-1106-preview, covering setup, session management, UI configuration, user input, and real-time content generation, showcasing Streamlit's synergy with OpenAI for dynamic applications.  🔑 Utilizing GPT-4 Code Interpreter API for CSV Analysis: A Step-by-Step Guide: Learn to analyze CSV files with OpenAI's GPT-4 Code Interpreter API. The guide covers step-by-step processes, from uploading files via Postman to creating an Assistant, forming a thread, and executing a run. Gain insights for efficient CSV analysis, unlocking data-driven insights and automation power. 🔑 Creating a Python Chat Web App with OpenAI's API and Reflex: In this tutorial, you'll learn how to develop a chat web application in pure Python, utilizing OpenAI's API for intelligent responses. The guide explains how to use the Reflex open-source framework to build both the backend and frontend entirely in Python. The tutorial also covers styling and handling user input, making it easy for those without JavaScript experience to create a chat application with an AI-driven chatbot. By the end, you'll have a functional AI chatbot web app built in Python.  🚀 HackHub: Trending AI Tools📐tigerlab-ai/tiger: Build customized AI models and language applications, bridging the gap between general LLMs and domain-specific knowledge. 📐 langchain-ai/langchain/tree/master/templates: Reference architectures for various LLM use cases, enabling developers to quickly build production-ready LLM applications. 📐 ggerganov/whisper.cpp/tree/master/examples/talk-llama: Uses the SDL2 library to capture audio from the microphone and combines Whisper and LLaMA models for real-time interactions. 📐 explosion/thinc: Lightweight deep learning library for model composition, offering type-checked, functional-programming APIs, and support for PyTorch, TensorFlow, and MXNet. 
Read more
  • 0
  • 0
  • 15491

article-image-chatgpt-for-customer-service
Amita Kapoor
25 Sep 2023
10 min read
Save for later

ChatGPT for Customer Service

Amita Kapoor
25 Sep 2023
10 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights and books. Don't miss out – sign up today!IntroductionCustomer service bots of old can often feel robotic, rigid, and painfully predictable. But enter ChatGPT: the fresher, more dynamic contender in the bot arena.ChatGPT isn't just another bot. It's been meticulously trained on a vast sea of text and code, equipping it to grapple with questions that would stump its predecessors. And it's not limited to just customer queries; this versatile bot can craft a range of text formats, from poems to programming snippets.But the standout feature? ChatGPT's touch of humour. It's not just about answering questions; it's about engaging in a way that's both informative and entertaining. So if you're in search of a customer service experience that's more captivating than the norm, it might be time to chat with ChatGPT. Onboarding ChatGPT: A Quick and Easy GuideReady to set sail with ChatGPT? Here's your easy guide to make sure you're all set and ready to roll:1. Obtain the API Key: First, you'll need to get an API key from OpenAI. This is like your secret password to the world of ChatGPT. To get an API key, head to the OpenAI platform and sign up. Once you're signed in, go to the API section and click on "Create New Key."2. Integrate ChatGPT with Your System: Once you have your API key, you can integrate ChatGPT with your system. This is like introducing ChatGPT to your system and making sure they're friends, ready to work together smoothly. To integrate ChatGPT, you'll need to add your API key into your system's code. The specific steps involved will vary depending on your system, but there are many resources available online to help you. Here is an example of how you can do it in Python:import openai import os # Initialize OpenAI API Client api_key = os.environ.get("OPENAI_API_KEY") # Retrieve the API key from environment variables openai.api_key = api_key # Set the API key # API parameters model = "gpt-3.5-turbo"  # Choose the appropriate engine max_tokens = 150  # Limit the response length3. Fine-Tune ChatGPT (Optional): ChatGPT is super smart, but sometimes you might need it to learn some specific stuff about your company. That's where fine-tuning comes in. To fine-tune ChatGPT, you can provide it with training data that is specific to your company. This could include product information, customer service FAQs, or even just examples of the types of conversations that you want ChatGPT to be able to handle. Fine-tuning is not required, but it can help to improve the performance of ChatGPT on your specific tasks. [https://www.packtpub.com/article-hub/fine-tuning-gpt-35-and-4].And that's it! With these three steps, ChatGPT will be all set to jump in and take your customer service to the next level. Ready, set, ChatGPT!Utilise ChatGPT for Seamless Question AnsweringIn the ever-evolving world of customer service, stand out by integrating ChatGPT into your service channels, making real-time, accurate response a seamless experience for your customers.  Let’s delve into an example to understand the process better.Example: EdTech Site with Online K-12 CoursesImagine operating a customer service bot for an EdTech site with online courses for K-12. You want to ensure that the bot provides answers only on relevant questions, enhancing the user experience and ensuring the accuracy and efficiency of responses. Here's how you can achieve this:1. Pre-defined Context:Initiate the conversation with a system message that sets the context for the bot’s role.role_gpt = "You are a customer service assistant for an EdTech site that offers online K-12 courses. Provide information and assistance regarding the courses, enrollment, and related queries." This directive helps guide the model's responses, ensuring they align with the expected topics.2. Keyword Filtering:Implement keyword filtering to review user’s queries for relevance to topics the bot handles. If the query includes keywords related to courses, enrollment, etc., the bot answers; otherwise, it informs the user about the limitation. Here's a basic example of a keyword filtering function in Python. This function is_relevant_query checks if the query contains certain keywords related to the services offered by the EdTech site.def is_relevant_query(query, keywords): """ Check if the query contains any of the specified keywords. :param query: str, the user's query :param keywords: list of str, keywords to check for :return: bool, True if query contains any keyword, False otherwise """ query = query.lower() return any(keyword in query for keyword in keywords) # Usage example: keywords = ['enrollment', 'courses', 'k-12', 'online learning'] query = "Tell me about the enrollment process." is_relevant = is_relevant_query(query, keywords)Next, we combine the bot role and user query to build the complete messagemessages = [ {    "role": "system",    "content": f"{role_gpt}" }, {"role": "user", "content": f"{query}"} ]We now make the openAI API can only when the question is relevant:is_relevant = is_relevant_query(query, keywords) if is_relevant: # Process the query with ChatGPT     # Make API call response = openai.ChatCompletion.create( model=model, messages=messages ) # Extract and print chatbot's reply chatbot_reply = response['choices'][0]['message']['content' print("ChatGPT: ", chatbot_reply) else: print("I'm sorry, I can only answer questions related to enrollment, courses, and online learning for K-12.")To elevate the user experience, prompt your customers to use specific questions. This subtle guidance helps funnel their queries, ensuring they stay on-topic and receive the most relevant information quickly. Continuous observation of user interactions and consistent collection of their feedback is paramount. This valuable insight allows you to refine your bot, making it more intuitive and adept at handling various questions. Further enhancing the bot's efficiency, enable a feature where it can politely ask for clarification on vague or ambiguous inquiries. This ensures your bot continues to provide precise and relevant answers, solidifying its role as an invaluable resource for your customers.Utilise ChatGPT to tackle Frequently Asked QuestionsAmidst the myriad of queries in customer service, frequently asked questions (FAQs) create a pattern. With ChatGPT, transform the typical, monotonous FAQ experience into an engaging and efficient one.Example: A Hospital ChatbotConsider the scenario of a hospital chatbot. Patients might have numerous questions before and after appointments. They might be inquiring about the hospital’s visitor policies, appointment scheduling, post-consultation care, or the availability of specialists. A well-implemented ChatGPT can swiftly and accurately tackle these questions, giving relief to both the hospital staff and the patients.  Here is a tentative role setting for such a bot:role_gpt = "You are a friendly assistant for a hospital, guiding users with appointment scheduling, hospital policies, and post-consultation care."This orientation anchors the bot within the healthcare context, offering relevant and timely patient information. For optimal results, a finely tuned ChatGPT model for this use case is ideal. This enhancement allows for precise, context-aware processing of healthcare-related queries, ensuring your chatbot stands as a trustworthy, efficient resource for patient inquiries.The approach outlined above can be seamlessly adapted to various other sectors. Imagine a travel agency, where customers frequently inquire about trip details, booking procedures, and cancellation policies. Or consider a retail setting, where questions about product availability, return policies, and shipping details abound. Universities can employ ChatGPT to assist students and parents with admission queries, course details, and campus information. Even local government offices can utilize ChatGPT to provide citizens with instant information about public services, documentation procedures, and local regulations. In each scenario, a tailored ChatGPT, possibly fine-tuned for the specific industry, can provide swift, clear, and accurate responses, elevating the customer experience and allowing human staff to focus on more complex tasks. The possibilities are boundless, underscoring the transformative potential of integrating ChatGPT in customer service across diverse sectors. Adventures in AI Land🐙 Octopus Energy: Hailing from the UK's bustling lanes, Octopus Energy unleashed ChatGPT into the wild world of customer inquiries. Lo and behold, handling nearly half of all questions, ChatGPT isn’t just holding the fort – it’s conquering, earning accolades and outshining its human allies in ratings!📘 Chegg: Fear not, night-owl students! The world of academia isn’t left behind in the AI revolution. Chegg, armed with the mighty ChatGPT (aka Cheggmate), stands as the valiant knight ready to battle those brain-teasing queries when the world sleeps at 2 AM. Say goodbye to the midnight oil blues!🥤 PepsiCo: Oh, the fizz and dazzle! The giants aren’t just watching from the sidelines. PepsiCo, joining forces with Bain & Company, bestowed upon ChatGPT the quill to script their advertisements. Now every pop and fizz of their beverages echo with the whispers of AI, making each gulp a symphony of allure and refreshment.Ethical Considerations for Customer Service ChatGPTIn the journey of enhancing customer service with ChatGPT, companies should hold the compass of ethical considerations steadfast. Navigate through the AI world with a responsible map that ensures not just efficiency and innovation but also the upholding of ethical standards. Below are the vital checkpoints to ensure the ethical use of ChatGPT in customer service:Transparency: Uphold honesty by ensuring customers know they are interacting with a machine learning model. This clarity builds a foundation of trust and sets the right expectations.Data Privacy: Safeguard customer data with robust security measures, ensuring protection against unauthorized access and adherence to relevant data protection regulations. For further analysis or training, use anonymized data, safeguarding customer identity and sensitive information.Accountability: Keep a watchful eye on AI interactions, ensuring the responses are accurate, relevant, and appropriate. Establish a system for accountability and continuous improvement.Legal Compliance: Keep the use of AI in customer service within the bounds of relevant laws and regulations, ensuring compliance with AI, data protection, and customer rights laws.User Autonomy: Ensure customers have the choice to switch to a human representative, maintaining their comfort and ensuring their queries are comprehensively addressed.TConclusionTo Wrap it Up (with a Bow), if you're all about leveling up your customer service game, ChatGPT's your partner-in-crime. But like any good tool, it's all about how you wield it. So, gear up, fine-tune, and dive into this AI adventure!Author BioAmita Kapoor is an accomplished AI consultant and educator with over 25 years of experience. She has received international recognition for her work, including the DAAD fellowship and the Intel Developer Mesh AI Innovator Award. She is a highly respected scholar with over 100 research papers and several best-selling books on deep learning and AI. After teaching for 25 years at the University of Delhi, Amita retired early and turned her focus to democratizing AI education. She currently serves as a member of the Board of Directors for the non-profit Neuromatch Academy, fostering greater accessibility to knowledge and resources in the field. After her retirement, Amita founded NePeur, a company providing data analytics and AI consultancy services. In addition, she shares her expertise with a global audience by teaching online classes on data science and AI at the University of Oxford. 
Read more
  • 0
  • 0
  • 15320

article-image-tapping-into-financial-data-via-gpt-4
Anshul Saxena
20 Sep 2023
15 min read
Save for later

Tapping into Financial Data via GPT-4

Anshul Saxena
20 Sep 2023
15 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights and books. Don't miss out – sign up today!IntroductionFor anyone new to the world of stocks, looking at the charts and numbers can feel a bit like trying to read a foreign language. But with the right tools and a step-by-step approach, understanding these numbers becomes a whole lot easier. This guide aims to walk beginners through a basic analysis of APPLE's stock data. Here's what will be covered:Step 1. Descriptive Statistics: The first step is to look at APPLE's stock prices. This means seeing the high points, the low points, and understanding how often they change.Step 2. Time Series Analysis: This is all about checking the price of the stock over time. It helps to see if the price is going up, going down, or staying about the same.Step 3. Volatility Analysis: This part helps to see how quickly and by how much the price changes. It's a way to see if the stock is calm or if it has a lot of ups and downs. Step 4. Technical Indicators: These are simple tools that help guess what might happen next with the stock price. It's like trying to guess the end of a story by looking at what happened in the middle. Step 5. Volume Analysis: This is about seeing how many times the stock was bought or sold. It gives a clue about how many people are interested in this stock. With these five easy steps aided by prompts and Python codes, anyone can start to understand the basics of APPLE's stock data. It's a straightforward way to see the story behind the numbers. You can access the data here (Link)Step 1: Descriptive StatisticsUsing descriptive statistics, we assess the stock's central tendencies and dispersion by calculating the mean, median, and standard deviation of prices and volume, and pinpointing the highest and lowest values over the specified period.Prompt 1: As a stock analyst, you are tasked with understanding the nuances of a given stock dataset. Start by loading the dataset that encompasses stock prices, specifically the Open, High, Low, and Close values, alongside trading volume. Compute fundamental descriptive statistics like the mean, median, standard deviation, as well as the maximum and minimum values for each mentioned category. Once done, provide a succinct summary detailing the key findings, highlighting any discernible trends or potential outliers that could be of significance to investors.Response: We'll start by generating basic descriptive statistics for the stock prices (Open, High, Low, Close) and the trading volume.The descriptive statistics for the stock prices and volume are as follows:  The next step is to visualize the dataset as a time seriesStep 2: Time Series AnalysisThrough time series analysis, we visualize stock price trends by plotting Open, High, Low, and Close values, while also examining seasonality, identifying prevailing trends, and detecting any anomalies or outliers in prices or volume.Prompt 2: As a stock analyst, begin by loading the dataset and ensure it includes Date, Open, High, Low, and Close prices. Standardize the "Date" column format and set it as the index. Plot these stock prices against dates, making each distinct. Analyze the graph for evident trends, significant peaks, or troughs, and ponder potential influencing factors.Response: It appears that the dataset contains the columns "Date", "Close/Last", "Volume", "Open", "High", and "Low". The "Date" column has inconsistent formats, so we'll need to standardize it. Additionally, the prices are represented as strings with dollar signs; we'll need to convert them to float values for analysis.I'll begin by:1.      Standardizing the "Date" column format.2.      Converting the price columns to float values.3.      Setting the "Date" column as the index. import pandas as pd # Load the dataset data = pd.read_excel("/mnt/data/HistoricalData_1Yr.xlsx") # Display the first few rows of the dataset data.head() The dataset has been appropriately formatted. The next step is to plot the stock prices (Open, High, Low, and Close/Last) against their respective dates. Each price will be represented with a distinct line for clarity.import matplotlib.pyplot as plt # Plotting the stock prices plt.figure(figsize=(15, 7)) for col in price_columns:    plt.plot(data.index, data[col], label=col) plt.title("Stock Prices Over Time") plt.xlabel("Date") plt.ylabel("Price ($)") plt.legend() plt.grid(True) plt.tight_layout() plt.show()Interpretation: When looking at a stock chart, I first noticed its overall upward movement. Yet, near the end, it seemed to stabilize or maybe even decline a bit. Two clear points caught my attention: a high point in the middle and a low point at the start. Stock prices can change due to company news or broader events, and sometimes, high trading volumes can make prices shift dramatically. It's also important to remember that the general mood of investors can set the direction for a stock's movement. Now let’s look at the volatility to check if the share is tradable or notStep 3: Volatility AnalysisBy calculating daily returns and computing the rolling standard deviation, we can effectively analyze and track the volatility of a financial instrument over time.Prompt 3: As a stock analyst, it's imperative to grasp the volatility of a stock, a crucial aspect for investors. To achieve this, compute the stock's daily returns by measuring the percentage change in the closing price from one day to the subsequent one. Once computed, proceed to plot these daily returns, which will visually represent the stock's volatility throughout the chosen time frame. Your plot, reflecting the daily returns over time, will offer invaluable insights into the stock's stability or fluctuations, helping stakeholders make informed decisions.Response: To grasp the volatility of the stock:We'll compute the stock's daily returns. This is achieved by measuring the percentage change in the closing price from one day to the subsequent one.We'll plot these daily returns over time, which will offer a visual representation of the stock's volatility throughout the chosen time frame.# Compute the daily returns data['Daily Returns'] = data['Close/Last'].pct_change() # Display the first few rows of the daily returns data['Daily Returns'].head()The daily returns have been successfully computed. As expected, the first entry is NaN since there's no previous day to calculate the percentage change from.Now, let's plot these daily returns over time to visually assess the stock's volatility.# Plotting the daily returns plt.figure(figsize=(15, 7)) plt.plot(data.index, data['Daily Returns'], label='Daily Returns', color='blue') plt.axhline(0, color='red', linestyle='--')  # Adding a horizontal line at y=0 for reference plt.title("Daily Returns Over Time") plt.xlabel("Date") plt.ylabel("Daily Return") plt.legend() plt.grid(True) plt.tight_layout() plt.show()Interpretation: When I look at the stock's daily returns, I see its ups and downs around the red zero line, showing its riskiness. Close-to-zero movements mean the stock is steady, while bigger jumps indicate more unpredictability. Different events, like company news or global happenings, can cause these shifts. So, when choosing stocks, it's crucial to know whether you prefer a calm ride or a roller coaster of returns.Since we know every information is inbuilt price data itself let’s analyze it to decode that informationStep 4: Forming Technical IndicatorsThrough the calculation of moving averages, such as the 50-day and 200-day, and the identification of golden or death crosses, coupled with the computation of the RSI, we can gauge market momentum and discern overbought or oversold conditions.Prompt 4: As a seasoned stock analyst, you recognize the importance of technical indicators like moving averages to gauge the potential direction of a stock's momentum. For this analysis, focus on two primary moving averages: the 50-day and the 200-day. By calculating these, you can ascertain pivotal trend indications. Notably, watch for the "Golden Cross," a bullish signal that arises when the 50-day moving average surpasses the 200-day moving average. Conversely, be wary of the "Death Cross," which is a bearish sign indicating potential downtrends when the 50-day moving average drops below the 200-day one. These cross points can serve as critical markers for investors, helping them strategize their market positions.Response: The 50-day and 200-day moving averages are among the most observed technical indicators in stock analysis. These moving averages help to smooth out price data to create a single flowing line, making it easier to identify the direction of the trend.Let's proceed with the following steps:Calculate the 50-day moving average for the closing price.Calculate the 200-day moving average for the closing price.Plot both moving averages alongside the stock's closing price.Identify and annotate potential "Golden Cross" and "Death Cross" points on the plot.Let's begin by calculating the two moving averages.# Calculate the 50-day and 200-day moving averages data['50-day MA'] = data['Close/Last'].rolling(window=50).mean() data['200-day MA'] = data['Close/Last'].rolling(window=200).mean() # Display the first few rows of the moving averages data[['Close/Last', '50-day MA', '200-day MA']].tail() The 50-day and 200-day moving averages have been calculated successfully. To better understand their implications:We'll plot the stock's closing price alongside the two moving averages.We'll highlight and annotate any "Golden Cross" and "Death Cross" occurrences on the chart. Let's visualize the data. # Plotting the closing price and moving averages plt.figure(figsize=(15, 7)) plt.plot(data.index, data['Close/Last'], label='Close Price', color='black', alpha=0.5) plt.plot(data.index, data['50-day MA'], label='50-day MA', color='blue') plt.plot(data.index, data['200-day MA'], label='200-day MA', color='red') # Identifying the Golden Cross and Death Cross golden_cross = data[(data['50-day MA'] > data['200-day MA']) & (data['50-day MA'].shift(1) <= data['200-day MA'].shift(1))] death_cross = data[(data['50-day MA'] < data['200-day MA']) & (data['50-day MA'].shift(1) >= data['200-day MA'].shift(1))] # Annotating the Golden Cross and Death Cross on the plot for date in golden_cross.index:    plt.annotate('Golden Cross', xy=(date, data['200-day MA'].loc[date]),                 xytext=(date, data['200-day MA'].loc[date] + 10),                 arrowprops=dict(facecolor='green', arrowstyle='->'), color='green')   for date in death_cross.index:    plt.annotate('Death Cross', xy=(date, data['200-day MA'].loc[date]),                 xytext=(date, data['200-day MA'].loc[date] - 10),                 arrowprops=dict(facecolor='red', arrowstyle='->'), color='red') # Other plot settings plt.title("Stock Price with 50-day and 200-day Moving Averages") plt.xlabel("Date") plt.ylabel("Price ($)") plt.legend() plt.grid(True) plt.tight_layout() plt.show() Interpretation: The chart shows the stock's closing price with two different line averages: a 50-day (blue) and a 200-day (red). When the 50-day line goes above the 200-day line, marked by green arrows, it usually suggests the stock might go up. On the other hand, red arrows where the 50-day line dips below indicate the stock might drop. These crossing points, known as the "Golden" and "Death" Cross, can help investors gauge the stock's potential direction. Simply put, these averages provide hints on whether the stock is on an upward or downward path. Let’s have a look at the volume of the APPLE stock.Step 5: Volume AnalysisBy analyzing volume spikes in relation to stock price movements and plotting volume over time, we can discern potential patterns and their impact on market dynamics.Prompt 5: In your role as a stock analyst, understanding trading volume's nuances is equally as vital as tracking price movements. Now, turn your attention to plotting the trading volume against time. This visualization can reveal patterns or substantial spikes in trading volume, which might correlate with notable price shifts. Such correlations can often indicate key market events or investor sentiment shifts. The graph you produce, illustrating the trading volume over the period, will provide a clearer picture of the stock's liquidity and the market's interest in it. This, in turn, will guide investment decisions and strategies.Response: Trading volume is a critical metric for stock analysts. It provides insights into the stock's liquidity and the market's interest in it. High trading volumes can indicate strong interest in a stock, and when paired with price movements, can reveal significant market events or shifts in investor sentiment.Let's proceed with the following steps:1. Plot the trading volume against time.2. Highlight and annotate any substantial spikes in trading volume.3. Overlay the stock's closing price to see if there's any correlation between trading volume spikes and significant price shifts.# Plotting the trading volume against time fig, ax1 = plt.subplots(figsize=(15, 7)) # Twin the axes for two different y-axes ax2 = ax1.twinx() # Plotting trading volume on ax1 ax1.bar(data.index, data['Volume'], color='gray', alpha=0.5, label='Volume') ax1.set_xlabel('Date') ax1.set_ylabel('Trading Volume', color='gray') ax1.tick_params(axis='y', labelcolor='gray') ax1.set_title("Trading Volume and Stock Price Over Time") # Plotting closing price on ax2 ax2.plot(data.index, data['Close/Last'], color='blue', label='Close Price') ax2.set_ylabel('Close Price ($)', color='blue') ax2.tick_params(axis='y', labelcolor='blue') # Highlighting and annotating substantial volume spikes average_volume = data['Volume'].mean() high_volume_dates = data[data['Volume'] > 1.5 * average_volume] for date in high_volume_dates.index:    ax1.annotate('High Volume', xy=(date, high_volume_dates['Volume'].loc[date]),                 xytext=(date, high_volume_dates['Volume'].loc[date] + 5e6),                 arrowprops=dict(facecolor='red', arrowstyle='->'), color='red') plt.grid(True) plt.tight_layout() plt.show() Let's begin by visualizing the trading volume against time.Interpretation: The chart displays both the stock's closing price (blue line) and how often it was traded (gray bars). Larger gray bars show days when the stock was traded more frequently. Some days, highlighted with red arrows, even saw an unusually high trading activity. Looking at these spikes alongside the blue line, we can guess if positive or negative news affected the stock. Generally, when a stock is traded often, it's easier to buy or sell without greatly changing its price. This chart helps investors gauge interest in the stock and its stability, supporting smarter investment choices.ConclusionIn conclusion, while the world of stocks might initially seem like an intricate puzzle, it truly isn't as daunting as it first appears. By systematically breaking down APPLE's stock data through the aforementioned steps, even a beginner can gain valuable insights into the dynamics of the stock market. Think of it as assembling the pieces of a story – from setting the scene with descriptive statistics to reaching the climax with volume analysis. And with the added advantage of specific prompts and Python code to guide the way, understanding the ebb and flow of stocks becomes a clear and attainable goal. So, here's to turning those charts and numbers from intimidating to intriguing, and uncovering the fascinating story they hold within. Author BioDr. Anshul Saxena is an author, corporate consultant, inventor, and educator who assists clients in finding financial solutions using quantum computing and generative AI. He has filed over three Indian patents and has been granted an Australian Innovation Patent. Anshul is the author of two best-selling books in the realm of HR Analytics and Quantum Computing (Packt Publications). He has been instrumental in setting up new-age specializations like decision sciences and business analytics in multiple business schools across India. Currently, he is working as Assistant Professor and Coordinator – Center for Emerging Business Technologies at CHRIST (Deemed to be University), Pune Lavasa Campus. Dr. Anshul has also worked with reputed companies like IBM as a curriculum designer and trainer and has been instrumental in training 1000+ academicians and working professionals from universities and corporate houses like UPES, CRMIT, and NITTE Mangalore, Vishwakarma University, Pune & Kaziranga University, and KPMG, IBM, Altran, TCS, Metro CASH & Carry, HPCL & IOC. With a work experience of 5 years in the domain of financial risk analytics with TCS and Northern Trust, Dr. Anshul has guided master's students in creating projects on emerging business technologies, which have resulted in 8+ Scopus-indexed papers. Dr. Anshul holds a PhD in Applied AI (Management), an MBA in Finance, and a BSc in Chemistry. He possesses multiple certificates in the field of Generative AI and Quantum Computing from organizations like SAS, IBM, IISC, Harvard, and BIMTECH.Author of the book: Financial Modeling Using Quantum Computing
Read more
  • 0
  • 0
  • 15036
article-image-chatgpt-as-a-documentation-tool
M.T. White
22 Aug 2023
14 min read
Save for later

ChatGPT as a Documentation Tool

M.T. White
22 Aug 2023
14 min read
It comes as no surprise that most developers do not like writing documentation.  As a result, documentation is often pushed to the side and, more often than not, haphazardly put together.  This is a serious problem since written documentation is the primary way developers communicate how a software system should work and be utilized.  As such, a poorly documented system can render it useless and confine it to the cyber trash heap long before its time.  However, with the rise of new tools like ChatGPT, poor documentation may no longer be a problem.  This article is going to explore how ChatGPT can be leveraged as a code documentation tool and examine the results to see just how well it can document code.What is quality documentation?If you ask five developers what they consider to be good documentation, you’re probably going to get five different answers.  What’s considered good documentation will vary among languages, IDEs, organizational coding standards, and preferences.  As such, for this article, “good” documentation is going to have the following parameters:1.     The documentation will provide context on how a block of code works or how to utilize it. 2.     The documentation will be logical and consistent.  This means that the documentation will be formatted and worded logically to provide context across all code blocks that ChatGPT documents.3.     The autogenerated code documentation will not clutter the code or distract the reader from the task at hand.Again, it is important to remember that there are many different opinions on what quality documentation looks like, and the points above are just high-level metrics to hit.    What is the documentation?Documentation is a very broad term that can mean a lot of things.  It can mean simply the documentation that comes packaged with the codebases like JavaDocs, or it could be a whole ecosystem that ranges from low-level code comments to YouTube videos and Wikipedia articles.  In short, documentation can be anything that helps relay information from one developer to another.  As such, for this article, the term documentation is going to be limited to code comments and high-level documentation like JavaDocs.  Also, most languages have their own best practices for documentation, so for this article, ChatGPT will generate documentation for Java.  Though Java will be the example language, there should only be minor tweaks, if any, to generate documentation for any other language. JavaDocsJavaDocs should provide high-level documentation to relay information about how to use a piece of code to a developer that does not have access to the codebase.  This means that key features like what the methods do, arguments, and return types should be noted.  With that in mind, let’s generate some JavaDocs for the following method,public static void add(int a, int b) {      System.out.println(a + b); }We’re going to generate the JavaDocs for this method using the following prompt:Generate some javadocs for this method public static void add(int a, int b) { System.out.println(a + b); }When the prompt is executed, it will produce the following output:/** * Calculates the sum of two integers and prints the result. * * @param a The first integer operand. * @param b The second integer operand. */ public static void add(int a, int b) {    System.out.println(a + b); }In this case, ChatGPT clearly defined what the arguments are, the datatypes of the arguments, and what the method is meant to do with straightforward prompts.  It is important to note that this method is straightforward, so the next thing to explore is a more complex method.The next method to try to automatically document will be the following:public static double divide(int a, int b) { double div = 0;      if (a > b) {            div = a / b ;      }else {            div = b / a;      }      return div; }For this method, the following prompt will be run. Write only JavaDocs for this method public static double divide(int a, int b) { double div = 0; if (a > b) { div = a / b ; }else { div = b / a; } return div; }After the prompt is run, we should be met with something similar to the following:/** * Calculates the division of two numbers. * * @param a The numerator. * @param b The denominator. * @return The division result. */These JavaDocs look very similar to the JavaDocs for the simple method.  They provide the arguments, return type, and the purpose of the method.   The one thing that was kind of ambiguous is that ChatGPT attempted to identify the variables as always the numerator or denominator.  From the code, we can see that this isn’t always true; however, if a developer is checking, they should be able to correct it fairly easily. Now, at first glance, this will appear as more trouble than it is worth.  A codebase of significant size is going to have many classes that are comprised of many different methods.  As such, copying and pasting methods one by one is going to be a herculean task.  However, ChatGPT can still be leveraged to speed up high-level code documentation.  Consider the following prompt:Write JavaDocs for these methods public static void add(int a, int b) { System.out.println(a + b); } public static double divide(int a, int b) { double div = 0; if (a > b) { div = a / b ; }else { div = b / a; } return div; }This prompt will produce the following results:/** * Adds two numbers and prints the result. * * @param a The first number. * @param b The second number. */ /** * Calculates the division of two numbers and returns the result. * * @param a The numerator. * @param b The denominator. * @return The division result. */Again, even with multiple methods, ChatGPT returned JavaDocs that are quality and provided enough information for a developer to use, with the exception of the same hiccup for the division method that was previously explored.  In all, ChatGPT did a decent job with writing JavaDocs.Used in this manner, ChatGPT can greatly enhance the speed and quality of development.  When using ChatGPT, multiple methods can be pasted into ChatGPT, and all the necessary JavaDocs are created.  As anyone who has ever had to write this type of documentation knows, it can be very time-consuming and mistake-prone.  However, with ChatGPT, all one has to do is input the code and let the AI system do the rest.  Ultimately ChatGPT will free up developers for more pressing tasks, and the AI will produce quality JavaDocs without making rudimentary errors like forgetting to include a parameter or return type.  With that, another question is how well ChatGPT can be used to write code comments. Code CommentsIn many cases, it is difficult for a 3rd party to write effective code comments.  To provide the most context to the code, the entity that is writing the code should also write the comments.  As such, the first thing that needs to be explored is how ChatGPT writes code comments.  To do this, consider the following code snippet:public static void add(int a, int b) {      System.out.println(a + b); }This code is very basic; however, in a quality codebase, even a method this simple should be documented.  This method would probably take as much time to document as it would be to write; this means it is a perfect candidate for ChatGPT.  To have ChatGPT document the code snippet runs the following prompt:Write a few comments to provide context for the following method public static void add(int a, int b) { System.out.println(a + b); }After running this prompt, ChatGPT will produce the following:public static void add(int a, int b) {    // This method takes two integer parameters, 'a' and 'b'.    // It adds the values of 'a' and 'b' together and prints the result.    System.out.println(a + b);    // The sum of 'a' and 'b' is calculated and printed to the console using System.out.println().    // This method does not return any value (void). }At first glance, one may notice that ChatGPT generated several comments.  This can be a pro as much as it can be a con since it can bloat the codebase.  With that, one may notice that the output from ChatGPT does have a couple of unnecessary comments that can bloat the code.  For example, there is a comment that says that the method takes in two integers, and another says that the method returns void.  For code comments, those comments are not necessary as they don’t contribute to the overall context of the code.  However, if the prompt is modified to,Write a comment that describes what this method does public static void add(int a, int b) { System.out.println(a + b); }It will produce the following:public static void add(int a, int b) {    // This method calculates the sum of two integers, 'a' and 'b',    // and displays the result by printing it to the console. }This prompt produced two comments that, when combined, form one complete sentence that describes what the method does. Now, this was for a relatively simple method.  As any programmer knows, a method will probably be larger and more complex than the add method.  As such, let’s consider the division method again:public static double divide(int a, int b) {      double div = 0;      if (a > b) {            div = a / b ;      }else {            div = b / a;      }      return div; }This method is a little more complex than the add method.  In this case, this method will return the quotient of a and b if a is greater than b or the quotient of b and a if b is greater than a.  With that, if the following prompt is inputted,Write comments to add context to this method public static double divide(int a, int b) { double div = 0; if (a > b) { div = a / b ; }else { div = b / a; } return div; }it will produce the following,public static double divide(int a, int b) {    // This method calculates the division of two integers and returns the result.    double div = 0;    // Variable to store the division result.    if (a > b) {        div = a / b;        // If 'a' is greater than 'b', divide 'a' by 'b' and assign the result to 'div'.    } else {        div = b / a;        // If 'b' is greater than or equal to 'a', divide 'b' by 'a' and assign the result to 'div'.    }    return div;    // Return the division result. }In short, ChatGPT will document every line of code again.  The comments do provide code context, but the comments don’t provide anything that can’t simply be read in the code.  Also, if this prompt is modified, ChatGPT, at the time of writing this article, will still produce relatively useless comments.Finally, if a prompt like the following is used:Write only the necessary comments for a developer to use public static double divide(int a, int b) { double div = 0; if (a > b) { div = a / b ; }else { div = b / a; } return div; }it will yield:// Calculates the division of two numbers and returns the result. // Parameters: //   a: The numerator. //   b: The denominator. // Returns: //   The division result.Of all the queries explored thus far, this one arguably yielded the best results.  In this case, the comments are what was generated in the last queries, but the format is much cleaner and easier to modify.  This block could be easily pasted into the codebase, and the unnecessary lines deleted. In all, it took a very specific prompt to produce marginally acceptable code comments.  At best, the code comments that were produced didn’t provide any extra context that could not be deduced from reading the code.  It can also be said that the code comments that were produced bloated the code and, to some, may have made it more confusing.  As such, for code comments, ChatGPT probably isn’t the best tool to use.  At best, a developer will have to remove unnecessary lines of comments and probably have to re-write many of them as well. There is also the issue of having to produce a prompt that is specific enough to generate proper comments. In all, whether a person should use ChatGPT as a code comment generator is up to them.  In theory, the comment produced could be leveraged in places like education, where code examples need to be heavily commented on to provide context to those who may not have a background in the language.  However, in terms of production code, though it will ultimately depend on the organization’s coding standard, ChatGPT will not produce code comments that would be mergeable in many places. Keytake Aways  In terms of codebase comments, ChatGPT is hit-and-miss.  As was seen, the code comments that ChatGPT produced were reminiscent of a college-level developer.  That is, ChatGPT commented on every line of code and only stated the obvious.  Since ChatGPT commented on every line of code, it can be argued that it bloated the codebase to a degree.  However, when a very specific prompt was run, it produced comments similar to what would be found in JavaDocs and what is expected by many organizations.  However, in terms of JavaDocs, ChatGPT shined.  The JavaDocs that ChatGPT produced were all very well written and provided the correct amount of information for a developer to easily digest and apply. As such, a few things can be summarized with what was explored.1.     Queries have to be very specific when it comes to code comments.2.     ChatGPT tends to produce unnecessary code comments that can bloat the codebase. 3.     Depending on the type/quality of code comments, ChatGPT may not be the ideal tool for automatic code documentation.4.     ChatGPT produces documentation akin to JavaDocs better than comments in the codebase.SummaryIn summary, what constitutes quality code documentation is often up to a team.  However, by many standards, ChatGPT tends to produce unnecessary code comments that don’t add much context and can easily bloat the codebase.  However, for higher-level documentation like JavaDocs, ChatGPT is an excellent tool that provides the proper amount of information.  In all, it probably isn’t the best idea to use ChatGPT as a means to generate comments for software written by a human, but it can be used to quickly produce higher-level documentation such as JavaDocs. As was seen, multiple methods can easily be documented in a matter of seconds using ChatGPT.  As such, in terms of productivity, when it comes to higher-level documentation, ChatGPT can be a great productivity tool that could help speed up development. Author BioM.T. White has been programming since the age of 12. His fascination with robotics flourished when he was a child programming microcontrollers such as Arduino. M.T. currently holds an undergraduate degree in mathematics, and a master's degree in software engineering, and is currently working on an MBA in IT project management. M.T. is currently working as a software developer for a major US defense contractor and is an adjunct CIS instructor at ECPI University. His background mostly stems from the automation industry where he programmed PLCs and HMIs for many different types of applications. M.T. has programmed many different brands of PLCs over the years and has developed HMIs using many different tools.Author of the book: Mastering PLC Programming 
Read more
  • 0
  • 0
  • 14624

article-image-demystifying-and-getting-started-with-github-copilot
Rod Anami
13 Jun 2023
6 min read
Save for later

Demystifying and Getting Started with GitHub Copilot

Rod Anami
13 Jun 2023
6 min read
Suddenly, in a blink of an eye, we all started to talk about AI, with particular attention to Generative AI, which produces assets, including code. Not long ago, OpenAI released ChatGPT, which received the spotlight from the media and even interest from people outside IT because of its capacity to sustain a dialog with a human and bring very specialized knowledge to answer questions. Before we continue, as a disclaimer, AI did not generate this very article. In my previous post, I discussed that site reliability engineers (SREs) and other professionals used AI capabilities long before ChatGPT. Today I want to talk about an exciting application of AI to aid software engineers, developers, and SREs in coding with AI-powered pair programming. GitHub Copilot is one notorious example and is sold as an "AI pair programmer." It generates code based on the comments around the code's intention, and it's been gaining traction among the developer's ranks. By the end of this post, you will understand what's Copilot and how to start using it.Does it mean I don't need any development skills anymore?The short answer is not really. Unless the problem you're trying to resolve with code is simple enough to require a few functionalities, you must have solid software development abilities to complete the work, even with Copilot in the game. Copilot is an emerging coding productivity tool, not a no-code or low-code solution. Also, would you sell software that you wouldn't be able to explain how it works? Worse, would you buy software that no one knows how it works?How does it work?GitHub Copilot utilizes OpenAI Codex under the hood. Like ChatGPT, Codex is a descendant of the GPT-3 (third-generation Generative Pre-trained Transformer), a neural network machine learning model trained with data from the Internet and capable of generating any natural language text. On top of that, they used billions of code lines from public repositories to teach Codex. In essence, it can read natural language and forge lines of code in many languages, including "JavaScript, Go, Perl, PHP, Ruby, Swift and TypeScript, and even Shell," but it has more proficiency in Python.Codex possesses four proven coding capacities:Generation: it generates lines of code based on a description in natural languageTranspiration: transforms code written in one language to another one that has a similar level of abstractionExplanation: explains what a block of code does in detailRefactoring: improves the efficiency of a code block without modifying its original intentWith Copilot, it's possible to generate a new block of code by inserting a programming language comment with the description of the code logic. For example, if I type this comment in a JavaScript file:// A function that takes in a string and returns a string with the first letter capitalizedIt may suggest the following code snippet:function capitalizeFirstLetter(string) {        return string.charAt(0).toUpperCase() + string.slice(1);}Another usage is through code recommendations. For instance, it may suggest lines of code to complete an unfinished function or procedure.Will it spy on me?Not at all. According to the GitHub's privacy statement, "neither your Prompts nor Suggestions will be shared or used as suggested code for other users of GitHub Copilot." Of course, publishing your code and the comments used to generate code through Copilot on a public repository may defeat this data privacy.Will it generate the perfect code?No, it will construct a reasonable with minimum accuracy solution, but it does not necessarily mean the generated code perfectly fits your project requirements. You will need to validate if the Copilot recommendations make sense in the context of your project. Also, there's no guarantee the code suggestions are flawless or follow strict security and quality policies.Now that you have a basic understanding of Copilot let's enable it on your laptop. You will need a GitHub account and an integrated development environment (IDE) tool installed on your machine.Enable Copilot for your GitHub personal accountYou can sign up for free at this link if you don't have a GitHub personal account. I'm assuming you have one ready for the rest of the below instructions.Image 1: Copilot pageThe first task is enabling the Copilot feature for your GitHub account; you can do that by selecting one of the pricing plans here. When I wrote this article, there was a free trial option. Next, you need to indicate whether or not you want the code suggestions coming from public code and if Copilot can use your snippets to improve the model (re-train it).Install the Copilot module on your preferred IDEAfter you enable it for your GitHub account, the second task is to install Copilot into your preferred IDE. I'm using Microsoft Visual Studio Code (VS Code), but they provide a package for many other IDEs; you can see the list and specific installation procedure here. Also, if you want, you can download and install VS Code from this official website.Image 2: Copilot extensionFor the VS Code tool, the installation process is straightforward: Open VS Code and click on Extensions in the left navigation panel.Look for the "copilot" term and select the GitHub Copilot extensionUse your GitHub credentials if you don't have any VS Code extension for GitHub yetInstall it and make sure it's enabled globally.Start to experiment with Copilot for realAfter you have the Copilot extension, it's time to test it. Just open a project folder or create a new one.Then create a new file; you can name it after copilot-test.js. If you don't have the JavaScript extension, it will prompt you to install it. Let's craft a comment that will trigger Copilot to generate code. Enter the following statement:// A function that reads a JSON file and returns the number of fields in the JSON objectThen, hit the CTRL+Enter to see possible solutions in a separate window. By the way, you can see all the keyboard shortcuts in this document for VS Code. It can bring up to 10 possible recommendations. Check the one that matches your style and click on the "Accept Solution" link at the end of the section.ConclusionAlthough it may not be the full-fledged AI-fueled programmer we see in the movies, GitHub Copilot helps developers with the initial algorithms and basic coding patterns. It might benefit individual developers and entire companies if seen as a software development productivity tool instead of a mythic autonomous programmer bot.I hope you enjoyed this blog post, and if you liked it, please connect to me on LinkedIn or follow me on Twitter @ranami. Also, my book Becoming a Rockstar SRE is out.
Read more
  • 0
  • 0
  • 14284
Modal Close icon
Modal Close icon