News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Very scary AI

Started by top204, Apr 04, 2024, 01:46 PM

Previous topic - Next topic

top204

Wow... This AI stuff is very scary...

I was having big problems getting the COM ports and thier friendly names using Windows 10 and Windows 11, so I thought I would ask the advice of ChatGPT. After quite a long time with the code it generated being incorrect and not working as it should, it came back with valid Delphi 6 code. Listed below:

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  DWORD_PTR = DWORD;
  ULONG_PTR = DWORD;

  HDEVINFO = Pointer;
  SP_DEVINFO_DATA = packed record
    cbSize: DWORD;
    ClassGuid: TGUID;
    DevInst: DWORD;
    Reserved: ULONG_PTR;
  end;
  PSP_DEVINFO_DATA = ^SP_DEVINFO_DATA;

  TForm1 = class(TForm)
    Memo1: TMemo;
    Close_Button: TButton;
    procedure Close_ButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    function GetCOMPorts: TStringList;
  public
    { Public declarations }
  end;

var
    Form1: TForm1;

const
  DIGCF_PRESENT = $00000002;
  SPDRP_FRIENDLYNAME = $0000000C;
  INVALID_HANDLE_VALUE = HDEVINFO(-1); // Define INVALID_HANDLE_VALUE for Delphi 6
  GUID_DEVINTERFACE_COMPORT: TGUID = '{4d36e978-e325-11ce-bfc1-08002be10318}';

function SetupDiGetClassDevs(ClassGuid: PGUID; Enumerator: PAnsiChar; hwndParent: HWND; Flags: DWORD): HDEVINFO; stdcall; external 'SetupAPI.dll' name 'SetupDiGetClassDevsA';
function SetupDiEnumDeviceInfo(DeviceInfoSet: HDEVINFO; MemberIndex: DWORD; var DeviceInfoData: SP_DEVINFO_DATA): BOOL; stdcall; external 'SetupAPI.dll' name 'SetupDiEnumDeviceInfo';
function SetupDiGetDeviceRegistryProperty(DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA; Property_: DWORD; var PropertyRegDataType: DWORD; PropertyBuffer: PByte; PropertyBufferSize: DWORD; var RequiredSize: DWORD): BOOL; stdcall; external 'SetupAPI.dll' name 'SetupDiGetDeviceRegistryPropertyA';
procedure SetupDiDestroyDeviceInfoList(DeviceInfoSet: HDEVINFO); stdcall; external 'SetupAPI.dll';

implementation

{$R *.dfm}

function TForm1.GetCOMPorts: TStringList;
var
  DeviceInfoSet: HDEVINFO;
  DeviceInfoData: SP_DEVINFO_DATA;
  MemberIndex: DWORD;
  PropertyRegDataType: DWORD;
  RequiredSize: DWORD;
  FriendlyName: array [0..1023] of Char;
  COMPorts: TStringList;
begin
  COMPorts := TStringList.Create;
  DeviceInfoSet := SetupDiGetClassDevs(@GUID_DEVINTERFACE_COMPORT, nil, 0, DIGCF_PRESENT);
  try
    if DeviceInfoSet <> HDEVINFO(INVALID_HANDLE_VALUE) then
    begin
      MemberIndex := 0;
      repeat
        ZeroMemory(@DeviceInfoData, SizeOf(DeviceInfoData));
        DeviceInfoData.cbSize := SizeOf(DeviceInfoData);
        if SetupDiEnumDeviceInfo(DeviceInfoSet, MemberIndex, DeviceInfoData) then
        begin
          if SetupDiGetDeviceRegistryProperty(DeviceInfoSet, @DeviceInfoData, SPDRP_FRIENDLYNAME,
            PropertyRegDataType, @FriendlyName, SizeOf(FriendlyName), RequiredSize) then
          begin
            COMPorts.Add(FriendlyName);
          end;
        end;
        Inc(MemberIndex);
      until not SetupDiEnumDeviceInfo(DeviceInfoSet, MemberIndex, DeviceInfoData);
      SetupDiDestroyDeviceInfoList(DeviceInfoSet);
    end
    else
      Memo1.Lines.Add('Error: Unable to retrieve device information');
  except
    COMPorts.Free;
    raise;
  end;
  Result := COMPorts;
end;

procedure TForm1.Close_ButtonClick(Sender: TObject);
begin
    Close();
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  COMPorts: TStringList;
  i: Integer;
begin
  COMPorts := GetCOMPorts;
  try
    Memo1.Lines.Add('COM Ports:');
    if COMPorts.Count > 0 then
    begin
      for i := 0 to COMPorts.Count - 1 do
        Memo1.Lines.Add(IntToStr(i + 1) + ': ' + COMPorts[i]);
    end
    else
      Memo1.Lines.Add('No COM Ports found');
  finally
    COMPorts.Free;
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Memo1.Clear;
end;

end.

However, the code it kept creating was very wrong and I had to ask it again and again why this was not working and what to do now with the GUID not valid for windows 10 or 11 and using a particular windows version and delphi version etc, and it still got it wrong until finally it got it right! I even asked it why it gave the original incorrect GUID value and it came back with an excuse for getting it incorrect? It also kept using DWORD_PTR and ULONG_PTR and I kept telling these were not valid in the delphi version I asked it to write for, and 'eventually, it code back with the DWORD correction, so why did it write DWORD_PTR and ULONG_PTR in the first place, when it knew they were not valid for Delphi 6? This is scary in the real world when AI are doing things on their own.

It is an incredible the piece of code it produced, but very scary that it has to be asked over and over again to correct it, when the original request had all the information it required. i.e. Delphi version, windows version etc...

But now, the above delphi program will display the COM port numbers and their friendly names on Windows 10 and Windows 11, so I can add its mechanism to my serial programs, but make it more efficient because the code produced by it is very inefficient and cumbersome. Searching for valid COM ports was a whole lot easier to do up until Windows 7, but the idiots at micro$oft changed so much stuff that did not need changing at all in the registry, and removed important sections from it for peripherals attached to the computer and hidden them behind non-descript GUIDs?. Why?

It looks like C and C++ and Delphi and Java and Python coders days are numbered, unfortunately. A non-programmer can ask the right questions on commonly used languages and the AI will produce the code for them (eventually). The same will be for a lot more professions. For example, an AI will eventually know all the querks for all the loop-holes for accountancy and book-keeping etc, so brokers, accountants, solicitors, estate agents and the rest of them will no longer be needed. Very scary indeed, but YEY!!!, we might eventually get rid of the legal crooks of our society!

JonW

It's the sheer speed at which it writes the code!  I have used it for some complex math routines, and the errors seem to be in how it interprets the question.  It is also expert at code conversion or breaking down sections of code.

Even for simple routines, you can't even type as fast as it prints the code out!!


ricardourio

For now, I think AI has more cunning than intelligence, but there is a worrying future ahead. Anyway, there are a lot of fake AI products, using a good code inside, with good algorithms around data and statitics, but nothing of intelligence, other than the developer. Just math.

Ricardo Urio

trastikata

#3
AI is just a new fancy word for programming, that goes around for companies and universities to obtain extra cash and grants.

No doubt the programs and the databases get ever more complex, the available processing power is increasing because of the virtual currency mining is going down and manufacturers have to create new markets ... which is AI. Other than that the AI is simply a complex program that does what the programming team embedded in it.

The fuss around the word will disappear and will be changed by another fancy word of the day like all others before that ... do you remember:

- NANO - one and a half decade ago it was so popular, everybody was investing in NANO, and even detergents were with NANO technology :)

- BIO - short-lived catch word, but everything was BIO, even the salt and the chairs ....

- ECO - replaced the BIO, quite a market that was created around this word, ECO-food, ECO-building, ECO-....

- GREEN - penultimate catchy phrase - the Europe's big corporate plunder of public funds for ultimately inefficient technologies, but Hey, how can you not be green?

- AI - now everything is AI, even the fridge ... well, IoT did not catch the mass public and is being replaced by the AI word. Soon when it gets fancy enough, the fridge with a network connection will be advertised and sold to the public Fridge with AI.

I am wondering what would be the next marketing "catch phrase" that will be sold for money ...

david

Time to bring back Fuzzy Logic.  It's been almost two generations since that appeared.  At my age, all my logic is a bit fuzzy.

top204

#5
That's just what I thought of the AI until I actually used it. I thought it is just another buzz word for the marketing crooks to use, but wow! It is a whole lot more than an "expert system" as they used to have.

After it created code, I would ask it to change a bit of it, but not actually give it all the question again, and it did it within seconds. I asked it why it did something and it gave a reason. It even appologised a few times when it got something wrong, then corrected it.

I actually felt uncomfortable telling it, it was wrong and actually felt it was a being of some sort, and that is not like me. :-) I have worked with electronics and technology all my life, but never have I come across something as powerful, and uncomfortable, as this. And this is only just the starting period of AI. I cannot imagine what it will be like in a few years, never mind a few decades. Have humans actually created what will bring about their own extinction? About bloody time, before they destroy the planet altogether and it takes evolution another 200 million years to get it back to normal. ;-)

So I asked it to create an isometric maze map on a 128x64 graphic LCD in C for an 18F device, the same game as the old 3D Ant Attack on the dear old ZX Spectrum in 1983, and it came back with bare minimum code for it and got quite a few things wrong, so I went through it and asked it to fill this in and that in and it eventually created a nearly full maze mechanism with isometrics and perspective and a small portion of the maze on the LCD that could be moved around! And all in about 20 minutes! No programmer on this planet could do that.

OK, the maze code does not work, but it is close, and I will try to fill in the pieces based upon my 2D maze that does the same, that I wrote back in 2008, once I have converted the C code to Positron8.

Sommi

Hello!

I had a similar (simple) experience, I asked this question:


"I need a program in proton basic for calculation of absolute humidity based on relative humidity and temperature"

The answer:

"Sure! Here's an example program in Proton BASIC for calculating absolute humidity based on relative humidity and temperature:"



vbnet

' Proton BASIC code for calculating absolute humidity
' based on relative humidity and temperature

' Set the variables for temperature and relative humidity
Dim temperature As Float
Dim relativeHumidity As Float

' Set the constants for the molecular weight of water and the gas constant
Const molecularWeightWater As Float = 18.01528
Const gasConstant As Float = 8.3144621

' Set the variables for saturation vapor pressure and actual vapor pressure
Dim saturationVaporPressure As Float
Dim actualVaporPressure As Float

' Set the variable for absolute humidity
Dim absoluteHumidity As Float

' Get the temperature and relative humidity values from the user
Input "Enter temperature in Celsius: ", temperature
Input "Enter relative humidity in percent: ", relativeHumidity

' Calculate the saturation vapor pressure using the temperature value
saturationVaporPressure = 610.78 * Exp((temperature / (temperature + 238.3)) * 17.2694)

' Calculate the actual vapor pressure using the relative humidity and saturation vapor pressure values
actualVaporPressure = (relativeHumidity / 100) * saturationVaporPressure

' Calculate the absolute humidity using the actual vapor pressure, molecular weight of water, and gas constant values
absoluteHumidity = (actualVaporPressure * molecularWeightWater) / (gasConstant * (temperature + 273.15))

' Print the absolute humidity value to the screen
Print "The absolute humidity is "; absoluteHumidity; " g/m3"



I copy/pasted the code, changed a few things and presto, just works.
Would have taken me 2-3 days to get into the topic.

Enjoy the weekend

Sommi
KISS - keep it simple and stupid

charliecoutas

Scary indeed.

Could somebody familiar with playing chess using the d2 to d3 format try playing ChatGPT? It used to be poor and made illegal moves. I'm not good enough and it would take me a long time. I wonder if it has "learned".

Charlie


Colin G3YHV

Hey guys. We could put chatGPT into robots. give them guns and pepper spray
and we would not need police !  Imagine....
Colin G3YHV

trastikata

Quote from: charliecoutas on Apr 06, 2024, 10:55 AMCould somebody familiar with playing chess using the d2 to d3 format try playing ChatGPT? It used to be poor and made illegal moves. I'm not good enough and it would take me a long time. I wonder if it has "learned".

Probably 20 years ago I played chess online on Yahoo with other online players. At some point I got fed up loosing and decided to install Chessmaster on my PC and make the same moves on-line as the Chessmaster on my PC.

To my suprise I still lost games on regular basis ... then I came to the conclusion that other on-line players have faster computers than me.  ;D

So it would be interesting to see a chat between AI by just copy and paste whatever one or the other says.  ;D

Colin G3YHV

I just asked it who designed positron basic for pic chips and got some strange answers.
So I tried to re- educate it. with strange results!
Colin

Colin G3YHV

I asked for a poem about pic chips
Rather good I thought
Colin

In circuits small, where wonders gleam,
Lies the heart of innovation's dream.
Within the silicon's silent grip,
Lies the power of the PIC chip.

With lines of code, a digital dance,
It breathes life into every chance.
On circuits etched with meticulous art,
It plays its role, a vital part.

From sensors sensing to motors whirring,
In every task, its presence stirring.
In bytes and bits, it finds its place,
A tiny titan in the race.

With every pulse, a world it spins,
Where logic reigns and light begins.
In circuits small, yet mighty bold,
The PIC chip's story is proudly told.

RGV250

#12
QuoteWe could put chatGPT into robots. give them guns and pepper spray
and we would not need police !  Imagine....

Have you not seen ED209 in Robocop https://villains.fandom.com/wiki/ED-209

Bob

top204

When the word BASIC is mentioned to it, it generally creates Visual BASIC type code, because that is still the most commonly used BASIC on PCs around the world. Even though micro$oft foolishly abandoned it for no reason at all.

I never liked Visual BASIC because of its bulk, but it was a very capable language.

It did not recognise Positron when I first asked it a few weeks ago, so I pointed it to the forum and my web site and it stated it would "try to find out more about it" and thanked me for new information. :-)

Scary!

Stephen Moss

Quote from: top204 on Apr 06, 2024, 02:25 PMWhen the word BASIC is mentioned to it, it generally creates Visual BASIC type code, because that is still the most commonly used BASIC on PCs around the world. Even though micro$oft foolishly abandoned it for no reason at all.
I guess it might depend on your interpretation of what constitues Visual BASIC, as I code in VB often at work.
 
My recollection may be wrong here but instead of it being a separate language, as I recall Microsoft folded all thier visual languages (BASIC, C#, F#) into .NET
As a result of being able to code in several languages from the one IDE its name was essentially changed to Visual Studio (Windows only), I think Visual Studio does now support coding in some other langaues as well depending on the opions you choose at installation.

There is probably a VB plugin/extension for the Visual Studio Code IDE but am not entriely sure as I have not really looked at it. Although, unlike Visual Studio, Visual Studio Code has the advantage that it will also run on the Linux and Mac OS's directly.