• Use Open AI to write code for you?

    Home » Forums » Outside the box » Learn to code » Use Open AI to write code for you?

    Author
    Topic
    #2506015

    I saw a story on Life Hacker about the Free Open AI and thought I’d give it a try and see if I could cause it problems, but much to my suprise!

    I asked: Write a Powershell program to change a userid

    It responded:

    To change a userid in Powershell, you can use the Set-LocalUser cmdlet. This cmdlet allows you to modify the properties of a local user account, including the userid.
    
    Here is an example of how to use this cmdlet to change a user's userid:
    

    OpenAI1

    This code first gets the user account with the name "username" and then uses the Set-LocalUser cmdlet to change the userid of that account to "newusername".
    
    Remember to replace "username" and "newusername" with the actual userid and the new userid that you want to use.
    
    You can also use the Get-LocalUser cmdlet to verify that the userid has been successfully changed by running the following command:
    

    OpenAI2

    This command will return the user account with the userid "newusername", which should now have the new userid that you specified.
    

    Notice how the code segments even provide you with a COPY Code Link!

    Now that’s darned IMPRESSIVE if you ask me!

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!
    Computer Specs

    • This topic was modified 3 months, 2 weeks ago by RetiredGeek.
    8 users thanked author for this post.
    Viewing 11 reply threads
    Author
    Replies
    • #2506169

      Many thanks for the post, RG… which I find quite scary.

      Do you have a LifeHacker link? (I couldn’t find one… searches on LifeHacker for ‘Open AI’ or ‘OpenAI’ return zero results.)

      I’m still – several years on – still dipping my toes into PowerShell (which I find overly convoluted in comparison to other scripting solutions yet very often more powerful… hence why I tend to use it more often).

    • #2506199

      Now that’s darned IMPRESSIVE if you ask me!

      Why is it impressive ? Some programmer wrote the code for the “AI”. It is not like a super computer with awareness wrote it.

      • #2506292

        Alex,

        I think it’s impressive beacuse:

        1. The AI parsed the text correctly.
        2. It was smart enough to find the exactly correct answer.
        3. It not only found the correct answer but explained exactly what it was doing in easy to understand text.
        4. It knew it was code so it placed it in a copyable code block w/link

        Maybe I’m just easily impressed but having used and discarded many code generators in the past I’m a bit jaded.

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

        4 users thanked author for this post.
        • #2506314

          The AI parsed the text correctly.

          There is no such thing as AI. Its a hoax just like crypto currency, blockchain, NFT, Metaverse…and it is NOT a IT.
          It is just software.

        • #2506324

          Apologies in advance for contradicting, but this isn’t what ChatGPT does. It is not a search engine and it does not copy and paste what someone wrote for it. It is an AI that has been trained via various types of machine learning, and thus it creates brand new results based on the patterns it has learned during its learning phase. Its creators have not gone and created an if statement saying that this is the answer that should be given if someone asks RetiredGeek’s question – it has learnt this itself by recognising patterns, in a similar way to how a human would learn something.

          AI is very much ‘a thing’, and, unlike crypto and NFTs, will completely revolutionise the world as we know it. Is an AI with human-level intelligence 10 or 20 years away? No. But if you’re looking for an impact, within 50 years AI will have completely transformed the economy, replacing huge numbers of low-skilled and high-skilled technical jobs with AI workers. I’ve already heard of programmers who have spent the past week doing their jobs by asking ChatGPT to create code and simply copy and pasting it (it can do a lot more complex code than Powershell commands).

    • #2506328

      trained via various types of machine learning,

      Machines don’t learn. They are programmed.

      • #2506335

        Machine learning and programming are two entirely different things. The whole point of machine learning is to solve tasks without explicit programming. Saying that machines can’t learn because they have code is like saying that humans can’t learn because they have brains – the code and the brains are only there as a platform upon which the learning takes place.

        Source: I have studied Artificial Intelligence (including machine learning) at university level. Appeals to authority are always unsatisfying, though, so you don’t have to take my word for it – there are many good resources out there on the subject, which I would encourage anyone with an interest in the future of technology to investigate.

      • #2506372

        Machines don’t learn. They are programmed.

        Yes, up until the point where they can program themselves, then watch out.

        Experience is that marvelous thing that enables you recognize a mistake as soon as you make it again.

        • #2507152

          Yes, up until the point where they can program themselves, then watch out.

          And then you have Sky Net.
          😁
          Sorry for that Sky.

          🍻

          Just because you don't know where you are going doesn't mean any road will get you there.
          1 user thanked author for this post.
          Sky
    • #2506490

      Machines don’t learn. They are programmed.

      Yes, up until the point where they can program themselves, then watch out.

      That point isn’t yet and its far away if ever.

      • #2507196

        …if ever.

        I’m not so sure you can say that with the utmost of certainty. As shown on the OpenAI page for the ChatGPT experiment, tremendous strides are currently being made in this field.

        1 user thanked author for this post.
        Sky
    • #2507199

      What a great concept! They also have an area that has four demonstrations on the page linked to above by @Sky .

      Now, along the lines of lighter things, how long until someone’s kids start using ChatGPT to do their homework for them??

      Seriously, the possibilities seem endless at this point!

      1 user thanked author for this post.
      Sky
      • #2515143

        you mean how soon DID it happen.

        🍻

        Just because you don't know where you are going doesn't mean any road will get you there.
    • #2507221

      In terms of a computer programming itself, one could argue that we are already in a black box scenario, in the sense that if you asked the people who have created ChatGPT how it arrives at its answers they wouldn’t be able to tell you, because it has adjusted its models itself with so much data that it is far too complex for a human to understand.

      As mentioned earlier, this isn’t really ‘programming’, though, as ChatGPT has not adjusted its ‘brain’, but rather it’s adjusted its ‘mind’ through learning.

      There really are tremendous strides being made, though, as Bob99 says. It is notable, though, that even ChatGPT doesn’t use unsupervised learning, which many people see as needed to emulate human intelligence completely, while others think that quantum computing will be required to full replicate the complexity of biological brains, something which is a long long way away, partly due to incredible energy requirements.

      Personally, despite wavy’s joke, I see the near future of AI as more of a huge economic disruptor rather than sentience.

       

      • #2507293

        10 Dangerous Things that the Internet’s Favorite ChatGPT is Capable of Doing

        ..As every coin has two sides, there are many dangerous things that the Internet’s favorite ChatGPT can do. Many Twitter users have come to realize that ChatGPT could potentially be used for both good and evil.

        ChatGPT Lack Morals

        ChatGPT Can Write Phishing Emails Without Typos

        It Can Write Software and Malware

        It’s Capable of Being Sexist, Racist

        It’s ‘Harmful’ to StackOverflow’s Business Model

        ChatGPT: ‘Selfish’ Humans ‘Deserve to be Wiped Out

        Revolutionize the Workplace

        It Could Redefine Supply, Demand, and Economy

        It Can’t Please Everyone on Sensitive Matters

        It’s Convincing Even When It’s Wrong..

        ChatGPT is a bullshit generator. But it can still be amazingly useful

        The philosopher Harry Frankfurt defined bullshit as speech that is intended to persuade without regard for the truth. By this measure, OpenAI’s new chatbot ChatGPT is the greatest bullshitter ever.
        Large Language Models (LLMs) are trained to produce plausible text, not true statements. ChatGPT is shockingly good at sounding convincing on any conceivable topic. But OpenAI is clear that there is no source of truth during training…

        Yet, there are three kinds of tasks for which ChatGPT and other LLMs can be extremely useful, despite their inability to discern truth in general:

        Tasks where it’s easy for the user to check if the bot’s answer is correct, such as debugging help.

        Tasks where truth is irrelevant, such as writing fiction.

        Tasks for which there does in fact exist a subset of the training data that acts as a source of truth, such as language translation…

        1 user thanked author for this post.
        Sky
    • #2514872

      Microsoft and OpenAI Working on ChatGPT-Powered Bing in Challenge to Google

      Microsoft could soon get a return on its $1 billion investment in OpenAI, creator of the ChatGPT chatbot, which gives humanlike text answers to questions.
      Microsoft is preparing to launch a version of its Bing search engine that uses the artificial intelligence behind ChatGPT to answer some search queries rather than just showing a list of links, according to two people with direct knowledge of the plans. Microsoft hopes the new feature, which could launch before the end of March, will help it outflank Google, its much bigger search rival…

      • #2514878

        NYC education department blocks ChatGPT on school devices, networks

        New York City students and teachers can no longer access ChatGPT — the new artificial intelligence-powered chatbot that generates stunningly cogent and lifelike writing — on education department devices or internet networks, agency officials confirmed Tuesday.

        The education department blocked access to the program, citing “negative impacts on student learning, and concerns regarding the safety and accuracy of content,” a spokesperson said. The move from the nation’s largest school system could have ripple effects as districts and schools across the country grapple with how to respond to the arrival of the dynamic new technology…

    • #2515144

      This is for the NON-BELIVERS out there!

      My Query:
      Write a PowerShell program to install USBDLM

      Here is a PowerShell script that will install the USBDLM software on a Windows machine:

      Code:
      # Check if USBDLM is already installed
      $installed = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "USBDLM*"}
      if ($installed) {
          # USBDLM is already installed
          Write-Output "USBDLM is already installed on this system."
      } else {
          # Download the USBDLM installer
          Invoke-WebRequest -Uri "https://www.uwe-sieber.de/usbdlm_e.html" -OutFile "usbdlm.exe"
      
          # Install USBDLM
          Start-Process -FilePath .\usbdlm.exe -ArgumentList '/S' -Wait
      
          # Clean up the installer file
          Remove-Item .\usbdlm.exe
      }
      

      This script will check if USBDLM is already installed on the system. If it is, it will display a message saying that it is already installed. If it is not installed, the script will download the USBDLM installer from the official website and then run it with the ‘/S’ argument to perform a silent installation. Finally, it will clean up the installer file by deleting it.

      Note that this script assumes that you have an internet connection and that you have the necessary permissions to install software on the system.

      Now that goes above and beyond what I asked it to do including finding the program on the internet!

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #2515159

      Ok,

      It ain’t perfect! The code has two problems:

      1. The program is not an .exe but rather a service. Thus you have to check for services to see if it is already installed.
      2. The download package I wanted to use is a .msi (Microsoft Installer) thus I had to make the appropriate changes to the download file and the use of it.

      Once that was done it worked flawlessly.

      Changing the request to:
      Write a PowerShell program to install USBDLM service using a msi package for 64 bit

      Fixed problem #2 but still tried to check installation the wrong way.

      Not quite sure how to get it to check services vs installed programs.

      For those who might be interested here is the fully correct answer:

      Code:
      # Check if USBDLM is already installed
      $installed = Get-Service -Name "USBDLM*"
        
      if ($installed) {
          # USBDLM is already installed
          Write-Output "USBDLM is already installed on this system."
      } else {
          # Download the USBDLM installer
          $IWRArgs = @{Uri = "https://www.uwe-sieber.de/files/usbdlm_x64.msi" 
                       OutFile = "usbdlm_x64.msi"}
          Invoke-WebRequest @IWRArgs
      
          # Install USBDLM
          Start-Process -FilePath .\usbdlm_x64.msi -ArgumentList '/Q' -Wait
      
          # Clean up the installer file
              Remove-Item .\usbdlm_x64.msi
      }
      

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      1 user thanked author for this post.
      • #2515287

        The code looks elegant: software poetry.

        Carpe Diem {with backup and coffee}
        offline▸ Win10Pro 2004.19041.572 x64 i3-3220 RAM8GB HDD Firefox83.0b3 WindowsDefender
        offline▸ Acer TravelMate P215-52 RAM8GB Win11Pro 22H2.22621.1265 x64 i5-10210U SSD Firefox106.0 MicrosoftDefender
        online▸ Win11Pro 22H2.22621.1413 x64 i5-9400 RAM16GB HDD Firefox112.0b3 MicrosoftDefender
    • #2515172

      Hey RG… I can see that Open AI has peaked your interest. It’s good to read.

      I think we all need to have something grab our attention and make us think… “hey, how far can I take this… it intrigues me!”

      Keep posting. 🙂

      1 user thanked author for this post.
    • #2530277

      Google’s MusicLM to write music for you from text.

      We introduce MusicLM, a model generating high-fidelity music from text descriptions such as “a calming violin melody backed by a distorted guitar riff”. MusicLM casts the process of conditional music generation as a hierarchical sequence-to-sequence modeling task, and it generates music at 24 kHz that remains consistent over several minutes. Our experiments show that MusicLM outperforms previous systems both in audio quality and adherence to the text description. Moreover, we demonstrate that MusicLM can be conditioned on both text and a melody in that it can transform whistled and hummed melodies according to the style described in a text caption. To support future research, we publicly release MusicCaps, a dataset composed of 5.5k music-text pairs, with rich text descriptions provided by human experts

    • #2530947

      Hey Y’all,

      Here’s my latest attempt to get AI to write good code. It took a couple of tries but the feature of ChatGPT that allows you to add refinements to previous queries seems to work quite well. You just keep adding information until it get’s it the way you want it. Of course, this does require that you have a clue as to what you want!

      Initial Query:
      write a powershell program to add a series of folders to a base folder and include error checking for existing directories so they are not overwritten

      Initial Response:
      Here’s a PowerShell script to add a series of folders to a base folder and check for existing directories to avoid overwriting:

      Code:
      $baseFolder = "C:\Example\Base"
      $folderNames = @("Folder1", "Folder2", "Folder3")
      
      foreach ($folderName in $folderNames) {
      $fullPath = Join-Path $baseFolder $folderName
      if (Test-Path $fullPath) {
      Write-Warning "The folder $fullPath already exists. Skipping creation."
      } else {
      New-Item -ItemType Directory -Path $fullPath
      Write-Host "The folder $fullPath was created."
      }
      }
      

      This script creates a base folder at C:\Example\Base and an array of folder names, $folderNames, which you can modify as needed. The foreach loop iterates over each folder name and creates the full path by joining the base folder and the folder name using the Join-Path cmdlet.

      The Test-Path cmdlet is used to check if the folder already exists. If it does, the script displays a warning message using the Write-Warning cmdlet. If it doesn’t exist, the script creates the folder using the New-Item cmdlet with the -ItemType parameter set to Directory and the -Path parameter set to the full path. The script then displays a message to indicate that the folder was created.

      Refinement #1:catch errors if folder creation failsResponse to refinement #1

      Here’s an updated version of the PowerShell script that includes error handling for failed folder creation:

      Code:
      $baseFolder = "C:\Example\Base"
      $folderNames = @("Folder1", "Folder2", "Folder3")
      
      foreach ($folderName in $folderNames) {
      $fullPath = Join-Path $baseFolder $folderName
      if (Test-Path $fullPath) {
      Write-Warning "The folder $fullPath already exists. Skipping creation."
      } else {
      try {
      New-Item -ItemType Directory -Path $fullPath
      Write-Host "The folder $fullPath was created."
      } catch {
      Write-Error "An error occurred while creating the folder $fullPath. Error message: $_"
      }
      }
      }
      

      This script includes error handling using a try-catch block. The try block creates the folder using the New-Item cmdlet, and if an error occurs, the catch block captures the error and displays an error message using the Write-Error cmdlet, including the error message generated by the system.

      This way, if there’s an issue with folder creation, you will be notified and able to take appropriate action to resolve the issue.

      Refinement #2:
      include the -ErrorAction parameter on the New-Item command and use splatting for the arguments to New-Item

      Response to refinement #2
      Here’s the updated version of the PowerShell script that uses the -ErrorAction parameter and splatting for the arguments to New-Item:

      Code:
      $baseFolder = "C:\Example\Base"
      $folderNames = @("Folder1", "Folder2", "Folder3")
      
      foreach ($folderName in $folderNames) {
      $fullPath = Join-Path $baseFolder $folderName
      if (Test-Path $fullPath) {
      Write-Warning "The folder $fullPath already exists. Skipping creation."
      } else {
      $arguments = @{
      ItemType = "Directory"
      Path = $fullPath
      ErrorAction = "Stop"
      }
      try {
      New-Item @arguments
      Write-Host "The folder $fullPath was created."
      } catch {
      Write-Error "An error occurred while creating the folder $fullPath. Error message: $_"
      }
      }
      }
      

      In this version of the script, the arguments to New-Item are stored in a hash table, $arguments, and passed to the New-Item cmdlet using splatting (the @ symbol before the variable name). The -ErrorAction parameter is set to “Stop”, which means that if an error occurs, the script will stop and throw an error, instead of continuing to the next iteration.

      This way, if there’s an issue with folder creation, the script will stop and display an error message, allowing you to take appropriate action to resolve the issue.

      Refinement #3:
      convert the code to a function that receives a list of folders to create

      Response to Refinement #3:
      Here’s the PowerShell script converted to a function that receives a list of folders to create:

      Code:
      function Create-Folders {
      [CmdletBinding()]
      param (
      [Parameter(Mandatory=$true)]
      [string]$BaseFolder,
      
      [Parameter(Mandatory=$true)]
      [string[]]$FolderNames
      )
      
      foreach ($folderName in $FolderNames) {
      $fullPath = Join-Path $BaseFolder $folderName
      if (Test-Path $fullPath) {
      Write-Warning "The folder $fullPath already exists. Skipping creation."
      } else {
      $arguments = @{
      ItemType = "Directory"
      Path = $fullPath
      ErrorAction = "Stop"
      }
      try {
      New-Item @arguments
      Write-Host "The folder $fullPath was created."
      } catch {
      Write-Error "An error occurred while creating the folder $fullPath. Error message: $_"
      }
      }
      }
      }
      

      The function, Create-Folders, takes two mandatory parameters: $BaseFolder and $FolderNames. $BaseFolder is the base folder where the new folders will be created, and $FolderNames is an array of strings that represents the names of the folders to create.

      The function uses the same logic as the previous script to create the folders and handle errors. To use the function, simply call it and pass in the desired $BaseFolder and $FolderNames:

      It even provided the calling sequence!

      Code:
      Create-Folders -BaseFolder "C:\Example\Base" -FolderNames @("Folder1", "Folder2", "Folder3")
      

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      1 user thanked author for this post.
    Viewing 11 reply threads
    Reply To: Use Open AI to write code for you?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: