{"id":439153,"date":"2024-02-27T15:56:00","date_gmt":"2024-02-27T14:56:00","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=dotnet&#038;p=439153"},"modified":"2024-03-19T17:58:52","modified_gmt":"2024-03-19T16:58:52","slug":"critical-thinking-in-an-ai-powered-world","status":"publish","type":"dotnet","link":"https:\/\/blog.jetbrains.com\/pt-br\/dotnet\/2024\/02\/27\/critical-thinking-in-an-ai-powered-world","title":{"rendered":"Critical Thinking in an AI-Powered World"},"content":{"rendered":"\n<p>Last year, we launched JetBrains AI Assistant, and from JetBrains&#8217; perspective, our mission of improving your drive to develop hasn\u2019t changed over the past two decades. As we head into 2024, Artificial Intelligence (AI) will likely be the most talked about topic of the year. Wherever you fall on the spectrum of AI conversation, one thing is clear: we must all equip ourselves with new critical thinking skills.&nbsp;<\/p>\n\n\n\n<p>In this post, we\u2019ll talk about the technology that powers <a href=\"https:\/\/jetbrains.com\/ai\" target=\"_blank\" rel=\"noopener\">JetBrains AI Assistant<\/a>, its strengths and weaknesses, examples of edge cases, and strategies to get better results from the JetBrains AI Assistant.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are LLMs? Strengths and Weaknesses<\/h2>\n\n\n\n<p>Large Language Models (LLMs) are the technology powering many AI services that require natural language processing. These models are typically trained to achieve general-purpose language tasks and have been described as \u201cautocorrect on steroids\u201d by many. LLMs are a complex web of decisions known as a neural network. Most LLMs have settled on a chat interface with a feedback loop designed to refine a particular task set by the user further.<\/p>\n\n\n\n<p>Models typically have three distinguishing factors: Tokens, number of parameters, and training dataset cutoff dates.&nbsp;<\/p>\n\n\n\n<p>The tokens define how much context a user can define in a session. What a token <em>is<\/em> depends on the LLM, as it is a representation of input. A token could be a word, a character, or a meaningful data representation. With access to more tokens, an LLM can have more context to complete a user\u2019s task, although more isn&#8217;t necessarily better in the case of tokens.<\/p>\n\n\n\n<p>Parameters are LLMs&#8217; second distinguishing, and not always public, feature. You can think of parameters as decisions along the neural network. The more parameters, the more significant the number of decisions an LLM model may exercise to produce an answer. Current models have parameters in the <strong>Billions,<\/strong> with future models predicted to be in the <strong>Trillions.<\/strong> Again, more isn\u2019t always necessarily better, as a smaller model trained for a specific use case may outperform a more extensive model on task results and time taken to respond.<\/p>\n\n\n\n<p>Finally, and most important to the user experience, is the training cutoff date. Many of these models use public datasets to train. These cut-off dates become more critical in tasks relating to time-sensitive knowledge, such as current events and cutting-edge programming techniques. Cutoff dates are not a clear indication of quality, as some model providers still keep much of their datasets secret due to the potential use of copyrighted material.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.youtube.com\/playlist?list=PLQ176FUIyIUahl4JYIX-qju1_jSo_3Mep\" target=\"_blank\" rel=\"noopener\">JetBrains developer advocate Jodie Burchell<\/a> is an expert in data science and has broken down the strengths and weaknesses of LLMs.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong>Strengths<\/strong><\/th><th><strong>Weaknesses<\/strong><\/th><\/tr><\/thead><tbody><tr><td>Summarization<\/td><td>Maths<\/td><\/tr><tr><td>Text &amp; Code Generation<\/td><td>Randomness<\/td><\/tr><tr><td>Classification<\/td><td>Timeliness<\/td><\/tr><tr><td><\/td><td>Non-deterministic&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>We\u2019ll explore some of these in the following sections and strategies to counteract them in your attempt to find solutions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Temporal Disconnect<\/h2>\n\n\n\n<p>As a technologist, you likely understand the break-neck speed at which all ecosystems are currently moving. Whether you stay current with the latest trends is a personal choice, but if you\u2019re an early adopter, you may have noticed AI-generated code samples can sometimes feel \u201cdated\u201d.<\/p>\n\n\n\n<p>For example, at the time of writing, <a href=\"https:\/\/platform.openai.com\/docs\/models\/gpt-4-and-gpt-4-turbo\" target=\"_blank\" rel=\"noopener\">ChatGPT has a training dataset up to September 2021<\/a>. The cutoff date means the embedded information in the ChatGPT model is unaware of any Java version after 16 and is undoubtedly unaware of the latest C# 12 features in .NET.<\/p>\n\n\n\n<p>Let\u2019s take a look at a .NET example specifically regarding testing dates.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[Fact]\npublic void Ladies_An_Gentlemen_The_Weekend()\n{\n      var now = DateTime.UtcNow.DayOfWeek;\n            \n      Assert.Contains(now, \n          [DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday]\n      );\n}<\/pre>\n\n\n\n<p>Regardless of your technology stack, you likely notice an immediate issue. This test will pass intermittently based on the current date and time. There are multiple ways to solve this issue, but let\u2019s ask the JetBrains AI Assistant first.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Suggest a way to refactor the variable `now` so that I can control the value without depending on `DateTime.UtcNow`<\/pre>\n\n\n\n<p>The response provides a custom <code>IDateProvider<\/code> implementation. The proposed functionality is a correct solution, but a developer with expertise in the ecosystem might question whether it\u2019s the only solution.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"639\" height=\"574\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/01\/image-68.png\" alt=\"\" class=\"wp-image-439155\"\/><\/figure>\n\n\n\n<p>.NET 8 recently added a <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.timeprovider?view=net-8.0\" target=\"_blank\" rel=\"noopener\"><code>TimeProvider<\/code><\/a> class, so let\u2019s ask JetBrains AI Assistant to refactor to use the mechanisms built into the SDK.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"618\" height=\"239\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/01\/image-69.png\" alt=\"\" class=\"wp-image-439166\"\/><\/figure>\n\n\n\n<p>The unexpected result can be a frustrating experience for those who know a feature exists but can\u2019t seem to get the JetBrains AI Assistant to generate the expected code. Let\u2019s write the <code>TimeProvider<\/code> code ourselves.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">private readonly FakeTimeProvider timeProvider = new();\n\n[Fact]\npublic void Ladies_An_Gentlemen_The_Weekend()\n{\n     timeProvider.SetUtcNow(new DateTime(2021, 1, 8)); \/\/ Friday\n     var now = timeProvider.GetUtcNow().DayOfWeek;\n     Assert.Contains(now, \n       [DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday]\n     );\n}<\/pre>\n\n\n\n<p>While the chat may not yield the initial expected results, as we begin to write another test, the JetBrains AI Assistant becomes aware of usages and patterns around how we may want to write some of our subsequent tests.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"650\" height=\"255\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/01\/image-70.png\" alt=\"\" class=\"wp-image-439177\"\/><\/figure>\n\n\n\n<p>Remember, LLMs are excellent at predicting text, and while newer knowledge of language features may not exist within the model, most newer language features behave similarly to older ones. The patterns in languages can aid JetBrains AI Assistant, and your code can help your sessions be productive by providing additional context.<\/p>\n\n\n\n<p>If you find a temporal piece of information commonly missing from your sessions, you can create a new prompt to describe your expected behavior. Remember, LLMs are excellent at predicting future text from the previous examples.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"634\" height=\"348\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/01\/image-71.png\" alt=\"\" class=\"wp-image-439188\"\/><\/figure>\n\n\n\n<p>Custom prompts can be a great way to overcome the limitations of any model until providers have updated the training data and contain newer embedded information.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Strategies for Better JetBrains AI Assistant Responses<\/h2>\n\n\n\n<p>Like most things, the more effort you put into JetBrains AI Assistant sessions, the better your results. Previously, we had mentioned LLMs aren\u2019t particularly strong with math.<\/p>\n\n\n\n<p>Let\u2019s work with JetBrains AI Assistant to generate a method that calculates the time it takes for an object to fall from a certain height in meters using the gravitational constant of Earth\u2019s gravity. We\u2019ll use the following code and let code completion fill out the rest.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using System;\n\n\/\/ Method `CalculateFallTimeAndVelocity` calculates\n\/\/ the time in seconds an object takes\n\/\/ to fall to the ground based on its height\n\/\/ in meters returns time and velocity as a Tuple\n(double time, double velocity) CalculateFallTimeAndVelocity(double meters)\n{\n    \n}\n\nvar (time, velocity) = CalculateFallTimeAndVelocity(100);\nConsole.WriteLine($\"time: {time}, velocity: {velocity} m\/s\");\n<\/pre>\n\n\n\n<p>In the method&#8217;s body, JetBrains AI Assistant recommends implementing known formulas.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"873\" height=\"295\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/01\/image-72.png\" alt=\"\" class=\"wp-image-439199\"\/><\/figure>\n\n\n\n<p>This solution is good, but you should immediately become skeptical whenever you see numbers in a response.<\/p>\n\n\n\n<p>Ask yourself the following questions:<\/p>\n\n\n\n<ul>\n<li>Do I understand what the mathematics are doing?<\/li>\n\n\n\n<li>Are the values correct or precise enough for my use case?<\/li>\n<\/ul>\n\n\n\n<p>An intelligent approach to answering these questions is to use JetBrains AI Assistant to clarify the code completion suggestion. Yes, you can use JetBrains AI Assistant to check its responses. Start with a <strong>New AI Chat<\/strong> session containing the prompt \u201cmove all constants to descriptive variables.&#8221; The resulting response will result in the following refactored code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">(double time, double velocity) CalculateFallTimeAndVelocity(double meters)\n {\n     const double Gravity = 9.8;\n     const double Factor = 2;\n \n     double time = Math.Sqrt(Factor * meters \/ Gravity);\n     double velocity = time * Gravity;\n \n     return (time, velocity);\n }<\/pre>\n\n\n\n<p>Next, you\u2019ll notice that the value of <code>9.8<\/code> is not that precise. Let\u2019s continue our chat session with the prompt: <em>\u201cSet the value of Gravity to Earth&#8217;s gravity up to four decimal places of precision\u201d<\/em>.&nbsp;<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">(double time, double velocity) CalculateFallTimeAndVelocity(double meters)\n{\n    const double Gravity = 9.8067;\n    const double Factor = 2.0000;\n\n    double time = Math.Sqrt(Factor * meters \/ Gravity);\n    double velocity = time * Gravity;\n\n    return (time, velocity);\n}\n<\/pre>\n\n\n\n<p>And I confirm with <a href=\"https:\/\/en.wikipedia.org\/wiki\/Gravity_of_Earth\" target=\"_blank\" rel=\"noopener\">other sources that Earth\u2019s gravitational constant<\/a> is indeed <strong>9.8067<\/strong>.<\/p>\n\n\n\n<p>I\u2019m not a physicist and would like additional comments on each line describing the steps occurring throughout the implementation. I use the prompt: <em>\u201cComment each line with valuable information that explains what&#8217;s happening\u201d<\/em>. It makes a detailed description easier for a layman like me to follow.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Function to calculate the fall time and velocity of an object falling from a certain height\n(double time, double velocity) CalculateFallTimeAndVelocity(double meters)\n{\n    \/\/ Earth's gravity constant in meters per second squared, up to four decimal places\n    const double Gravity = 9.8067;\n\n    \/\/ Factor used in the time calculation formula\n    const double Factor = 2.0000;\n\n    \/\/ Calculate the time of fall using the formula sqrt(2 * meters \/ Gravity)\n    double time = Math.Sqrt(Factor * meters \/ Gravity);\n\n    \/\/ Calculate the velocity at the end of the fall using the formula Gravity * time\n    double velocity = time * Gravity;\n\n    \/\/ Return the calculated time and velocity\n    return (time, velocity);\n}\n<\/pre>\n\n\n\n<p>I may omit some or all of the comments from my final codebase, but I can make a better decision when seeing all of them in place.<\/p>\n\n\n\n<p>As a final step, I may ask JetBrains AI Assistant to review the code block for potential issues using the <strong>Find Potential Issues<\/strong> prompt.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"778\" height=\"782\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/02\/image-88.png\" alt=\"\" class=\"wp-image-449148\"\/><\/figure>\n\n\n\n<p>Oh, right, there\u2019s a potential issue with negative heights. Let\u2019s be sure to handle that with an appropriate conditional block. We can now end our chat session and declare success.<\/p>\n\n\n\n<p>I hope you take a few things from this example:<\/p>\n\n\n\n<ul>\n<li>Writing <strong>clear and concise instructions <\/strong>for the first time is challenging. You\u2019ll likely have to iterate in a session to find an acceptable solution.<\/li>\n\n\n\n<li>You should <strong>always be skeptical about numbers<\/strong>. Values could need more precision or be wrong.<\/li>\n\n\n\n<li><strong>Refactor any or all constants into variables with meaningful names<\/strong> for a clearer understanding of the code.<\/li>\n\n\n\n<li><strong>Make sure mathematical equations are accurate.<\/strong> You can check this using other sources and the JetBrains AI Assistant to find problems.<\/li>\n\n\n\n<li>Asking the AI Assistant to <strong>comment on lines within complex methods<\/strong> can help you better understand the steps in a method.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.jetbrains.com\/ai\/\" data-type=\"link\" data-id=\"https:\/\/www.jetbrains.com\/ai\/\" target=\"_blank\" rel=\"noopener\">AI Assistant<\/a> can help you solve a new fascinating set of problems but does not claim to be infallible. Since AI Assistant uses models trained on human data, it can sometimes be wrong. That\u2019s why you should think critically about responses and always take steps to understand and verify the results of any LLM-based product. <\/p>\n\n\n\n<p>For <a href=\"https:\/\/www.jetbrains.com\/ides\/\" data-type=\"link\" data-id=\"https:\/\/www.jetbrains.com\/ides\/\" target=\"_blank\" rel=\"noopener\">JetBrains IDE<\/a> users, we benefit from products mixed with new and evolving Artificial Intelligence with the tried and tested \u201cReal Intelligence\u201d of industry experts and leading tool builders. We don\u2019t see these two modes in conflict with each other. Instead, they are a combination designed to improve the most essential part of software development: you, the developer.<\/p>\n\n\n\n<p>We hope you enjoyed this blog post, and if you have any questions or comments, please feel free to comment.<\/p>\n\n\n\n<p><sub><em>image credit: <a href=\"https:\/\/unsplash.com\/@fakurian\" target=\"_blank\" rel=\"noopener\">Milad Fakurian<\/a><\/em><\/sub><\/p>\n","protected":false},"author":1079,"featured_media":458369,"comment_status":"closed","ping_status":"closed","template":"","categories":[4992,1401,8397],"tags":[8168,211],"cross-post-tag":[8396],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/dotnet\/439153"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/dotnet"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/types\/dotnet"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/users\/1079"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/comments?post=439153"}],"version-history":[{"count":9,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/dotnet\/439153\/revisions"}],"predecessor-version":[{"id":458393,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/dotnet\/439153\/revisions\/458393"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media\/458369"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=439153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=439153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=439153"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=439153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}