Recent

Author Topic: TCHATGPT — An Artificial Intelligence Component Package for Lazarus / Free Pasca  (Read 1714 times)

marcelomaurinmartins@gmai

  • New Member
  • *
  • Posts: 26
Hello Lazarus community,

I would like to introduce my open source project:

https://github.com/marcelomaurin/CHATGPT/

TCHATGPT is an Artificial Intelligence component package for Lazarus / Free Pascal, created to bring modern AI resources closer to traditional component-based Lazarus development.

The purpose of the project is to allow Lazarus applications to integrate AI in a practical way, using both external resources and local features.

Today the project already integrates Python with Lazarus and allows the use of several libraries and technologies related to AI, computer vision, image processing, voice, automation, local models and LLM services.

Besides Python integration, the project is also evolving with native Free Pascal resources, aiming to reduce external dependencies in some areas and create its own components for classification, pipeline organization, document generation, automation and local system integration.

The main areas being integrated and developed are:

LLMs and AI APIs
Local models
Python integration with Lazarus
Computer vision
Image processing
Voice and audio
Document generation
Graphs and local classification
AI agents
Automation, IoT and industrial systems
Native Free Pascal resources

The project is still under active development, with functional components, examples, beta areas and experimental modules. The idea is to build a modular suite where developers can install and use only the resources required by each application.

The documentation is also being prepared with translations into several languages, including Portuguese, English, Spanish, French, Italian, Arabic, Chinese, Russian and Japanese, making the project more accessible to the international community.

The goal of TCHATGPT is to show that Lazarus / Free Pascal remains a viable platform for modern applications, including Artificial Intelligence, automation, computer vision and integration with local or cloud-based models.

Feedback, testing, suggestions and contributions are very welcome.

Repository:

https://github.com/marcelomaurin/CHATGPT/


Dzandaa

  • Hero Member
  • *****
  • Posts: 557
  • From C# to Lazarus
Hi,

@marcelomaurinmartins:

I don't think introducing GPT chat into Pascal Lazarus is a good idea.

It's better to use your brain rather than a tool that isn't always reliable. See the article in "The Harvard Gazette".

https://news.harvard.edu/gazette/story/2025/11/is-ai-dulling-our-minds/

AI is trained on data provided by humans; it has a learning curve. If you give it incorrect data and tell it's true, the result is that in testing, if you input incorrect data, the AI ​​will accept it as true. Using chatbots to create a program is easy, but our brains don't train, and in the long run, this risks introducing a deficiency (laziness) in our brains.

And in the future, we won't need programmers anymore, just technicians.

Just my opinion; my wife works on programming neural networks :)

B->
Regards,
Dzandaa

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12608
  • Debugger - SynEdit - and more
    • wiki
Please be reminded of https://forum.lazarus.freepascal.org/index.php/topic,73827.0.html

This thread is about introducing a package. It can be discussed how it can be efficiently used, what it provides, and ideas how to improve it.

This thread should not be turned into a general discussion about should AI be used at all.
That would not be a Pascal related topic, but rather a huge field of its own, which would way exceed the boundaries of this forum. For general, non Pascal related AI versus no-AI we recommand finding a forum that specializes on that question.

Thanks for understanding.



Welcome to marcelomaurinmartins

marcelomaurinmartins@gmai

  • New Member
  • *
  • Posts: 26
Here's the list of components in development.
They are at different stages of maturity.

I ask that you check the links and especially the screenshots, as they help to conceptualize the project.

https://github.com/marcelomaurin/CHATGPT/tree/main/screenshots

https://github.com/marcelomaurin/CHATGPT/tree/main/pacote

Weiss

  • Sr. Member
  • ****
  • Posts: 257
Hello Lazarus community,

I would like to introduce my open source project:

https://github.com/marcelomaurin/CHATGPT/
..
The purpose of the project is to allow Lazarus applications to integrate AI in a practical way, using both external resources and local features.
..

The documentation is also being prepared with translations into several languages, .., English,..

The goal of TCHATGPT is to show that Lazarus / Free Pascal remains a viable platform for modern applications, including Artificial Intelligence, automation, computer vision and integration with local or cloud-based models.

Feedback, testing, suggestions and contributions are very welcome.

Repository:

https://github.com/marcelomaurin/CHATGPT/

A link to documentation would be breat. Is it something like local LLM which can be integrated into application? Can it be trained on a specific engineering tasks? I opened your git and instantly got lost, there is so much in there. From what you are saying, it sounds good, something I kept thinking about

marcelomaurinmartins@gmai

  • New Member
  • *
  • Posts: 26
Actually, it's not an LLM; it's a set of components for building AI applications. For example, I'm currently writing a module for creating a data dictionary, which can be used in conjunction with an LLM to create dynamic reports in the application. In other words, using two components, `AI_dictionary_base` creates a data dictionary, and with the `chatgpt` component, you can create the data structure so the user can specify what needs to be related. The bot then dynamically performs the SQL query. This is just one example of use. But there are other components that can be integrated in different ways. In fact, my project isn't a solution; it's more of a toolbox for building applications. I hope my explanation was clear.

Hello Lazarus community,

I would like to introduce my open source project:

https://github.com/marcelomaurin/CHATGPT/
..
The purpose of the project is to allow Lazarus applications to integrate AI in a practical way, using both external resources and local features.
..

The documentation is also being prepared with translations into several languages, .., English,..

The goal of TCHATGPT is to show that Lazarus / Free Pascal remains a viable platform for modern applications, including Artificial Intelligence, automation, computer vision and integration with local or cloud-based models.

Feedback, testing, suggestions and contributions are very welcome.

Repository:

https://github.com/marcelomaurin/CHATGPT/

A link to documentation would be breat. Is it something like local LLM which can be integrated into application? Can it be trained on a specific engineering tasks? I opened your git and instantly got lost, there is so much in there. From what you are saying, it sounds good, something I kept thinking about
« Last Edit: June 20, 2026, 01:55:31 pm by marcelomaurinmartins@gmai »

marcelomaurinmartins@gmai

  • New Member
  • *
  • Posts: 26
Another important example is the Python communication component.

We all know that Python is a very powerful language, with a huge ecosystem of libraries and integrations. With this in mind, I developed a Lazarus component that allows Pascal applications to integrate with Python in a simple and practical way.

In addition to connecting the application to the Python interpreter, the component can also work with its own runtime environment, allowing the required Python packages to be distributed together with the application. This makes it possible to create a complete installer containing everything the application needs to run, without requiring additional installations or manual configuration on the user’s computer.

The main idea is to simplify distribution: the setup installs the application, the Python runtime, and all required dependencies, leaving the environment ready to use.

With this approach, it becomes possible to develop applications in Lazarus while also taking advantage of Python’s advanced capabilities, greatly reducing the challenges related to dependency distribution.

So far, I have tested the component on Windows. To be fully transparent, it still needs to be validated on Linux, but Linux compatibility is part of the project’s goal.


Hello Lazarus community,

I would like to introduce my open source project:

https://github.com/marcelomaurin/CHATGPT/
..
The purpose of the project is to allow Lazarus applications to integrate AI in a practical way, using both external resources and local features.
..

The documentation is also being prepared with translations into several languages, .., English,..

The goal of TCHATGPT is to show that Lazarus / Free Pascal remains a viable platform for modern applications, including Artificial Intelligence, automation, computer vision and integration with local or cloud-based models.

Feedback, testing, suggestions and contributions are very welcome.

Repository:

https://github.com/marcelomaurin/CHATGPT/

A link to documentation would be breat. Is it something like local LLM which can be integrated into application? Can it be trained on a specific engineering tasks? I opened your git and instantly got lost, there is so much in there. From what you are saying, it sounds good, something I kept thinking about

marcelomaurinmartins@gmai

  • New Member
  • *
  • Posts: 26
Yes, it is possible to redistribute Python together with your own application.

The official Python license, maintained by the Python Software Foundation, allows the use, copying, modification, and redistribution of Python in source code or binary form. This means an application can include an embedded Python runtime with its files, making installation easier and avoiding the need for the end user to manually install dependencies.

This model is especially useful for desktop applications, such as projects developed with Lazarus, Delphi, or other languages, where Python can be used as an automation engine, data processing layer, AI integration, scientific library interface, or internal script execution environment.

The main precaution is to keep the Python license files included with the application and also verify the licenses of any additional Python packages distributed with it, such as NumPy, OpenCV, TensorFlow, Pillow, Requests, or other modules.

Official reference:
https://docs.python.org/3/license.html

There is also a clear confirmation on the official Python website stating that Python is free even for commercial use, including resale, without copyleft restrictions:
https://www.python.org/doc/copyright/ 

Another important example is the Python communication component.

We all know that Python is a very powerful language, with a huge ecosystem of libraries and integrations. With this in mind, I developed a Lazarus component that allows Pascal applications to integrate with Python in a simple and practical way.

In addition to connecting the application to the Python interpreter, the component can also work with its own runtime environment, allowing the required Python packages to be distributed together with the application. This makes it possible to create a complete installer containing everything the application needs to run, without requiring additional installations or manual configuration on the user’s computer.

The main idea is to simplify distribution: the setup installs the application, the Python runtime, and all required dependencies, leaving the environment ready to use.

With this approach, it becomes possible to develop applications in Lazarus while also taking advantage of Python’s advanced capabilities, greatly reducing the challenges related to dependency distribution.

So far, I have tested the component on Windows. To be fully transparent, it still needs to be validated on Linux, but Linux compatibility is part of the project’s goal.


Hello Lazarus community,

I would like to introduce my open source project:

https://github.com/marcelomaurin/CHATGPT/
..
The purpose of the project is to allow Lazarus applications to integrate AI in a practical way, using both external resources and local features.
..

The documentation is also being prepared with translations into several languages, .., English,..

The goal of TCHATGPT is to show that Lazarus / Free Pascal remains a viable platform for modern applications, including Artificial Intelligence, automation, computer vision and integration with local or cloud-based models.

Feedback, testing, suggestions and contributions are very welcome.

Repository:

https://github.com/marcelomaurin/CHATGPT/

A link to documentation would be breat. Is it something like local LLM which can be integrated into application? Can it be trained on a specific engineering tasks? I opened your git and instantly got lost, there is so much in there. From what you are saying, it sounds good, something I kept thinking about

marcelomaurinmartins@gmai

  • New Member
  • *
  • Posts: 26
Chromium Capture Demo: Lazarus integrated with Chromium

In the CHATGPT for Lazarus/Free Pascal project, I created the chromium_capture_demo sample using the TAIChromiumBrowser component integrated with Chromium/CEF4Delphi.

The goal is to allow a Lazarus application to open real web pages, interact with the DOM, execute JavaScript, capture HTML, and automate browser actions.

This enables several practical use cases:

website validation;
automated testing;
form filling;
data extraction;
technical page analysis;
support for authorized security audits;
integration between web systems and desktop applications.

In the healthcare area, this type of tool can be very useful for validating exam portals, appointment scheduling systems, administrative screens, registration forms, and internal pages that often do not provide an available API.

With Chromium embedded in Lazarus, it becomes possible to create desktop solutions capable of navigating, testing, capturing, and analyzing information from real web systems.

This sample shows how Lazarus remains a living, practical, and powerful tool for building modern applications, including AI-integrated solutions.

GitHub:
https://github.com/marcelomaurin/CHATGPT

#Lazarus #FreePascal #Chromium #CEF4Delphi #Automation #SoftwareTesting #DigitalHealth #HealthTech #OpenSource #ArtificialIntelligence #Pascal

schuler

  • Sr. Member
  • ****
  • Posts: 382
Besides Python integration, the project is also evolving with native Free Pascal resources, aiming to reduce external dependencies in some areas and create its own components for classification, pipeline organization, document generation, automation and local system integration.

In the case that you are interested, you could use/integrate my own api: https://github.com/joaopauloschuler/neural-api/

The following LLM models have already been tested:
https://huggingface.co/posts/schuler/260451033437289

I am currently testing the Qwen 3.6 27B and its MOE in both CPU and GPU. Qwen 3.6 support should be added to the master branch very soon. It has awesome benchmarks: https://qwen.ai/blog?id=qwen3.6-27b
« Last Edit: July 18, 2026, 10:02:44 pm by schuler »

marcelomaurinmartins@gmai

  • New Member
  • *
  • Posts: 26
Thank you very much for the recommendation and for your willingness to help.

The Neural API seems to be strongly aligned with the goals of the CHATGPT project, especially its focus on expanding the use of native Free Pascal resources and reducing external dependencies.

I will study the library architecture in more detail and evaluate a possible integration as an optional inference backend. The idea would be to allow the project components to use different mechanisms, such as external APIs, llama.cpp, Python, or a native Free Pascal solution.

I also found the support for Qwen models and the possibility of running them on both CPU and GPU very interesting. A first test could involve text or email classification using a smaller model, evaluating memory usage, performance, and ease of integration.

Once I port the integration to your architecture, I will post the results and implementation details here in this forum.

Congratulations on your work with the Neural API. Running modern AI models directly in Free Pascal is a very important contribution to the Pascal ecosystem.

Thaddy

  • Hero Member
  • *****
  • Posts: 19606
  • Glad to be alive.
In the case that you are interested, you could use/integrate my own api: https://github.com/joaopauloschuler/neural-api/

The following LLM models have already been tested:
https://huggingface.co/posts/schuler/260451033437289

I am currently testing the Qwen 3.6 27B and its MOE in both CPU and GPU. Qwen 3.6 support should be added to the master branch very soon. It has awesome benchmarks: https://qwen.ai/blog?id=qwen3.6-27b
I started testing and I must say QWEN 3.7 (which is the above?) is an impressive model.
Input:"OAUTH2 test written in freepascal 3.2.2 or 3.3.1 using only standard units from fcl-web and fcl-net."
It took just three sessions to come up with this:
Code: Pascal  [Select][+][-]
  1. program OAuth2AuthCodeFlowTest;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes, SysUtils,
  7.   // fcl-net units
  8.   fphttpclient,
  9.   // fcl-web units
  10.   fphttpserver, httpdefs, httpprotocol,
  11.   // fcl-base units
  12.   fpjson, jsonparser;
  13.  
  14. const
  15.   // --- CONFIGURATION ---
  16.   AuthEndpoint  = 'https://your-identity-provider.com/oauth2/authorize';
  17.   TokenEndpoint = 'https://your-identity-provider.com/oauth2/token';
  18.   ClientId      = 'your_client_id';
  19.   ClientSecret  = 'your_client_secret';
  20.  
  21.   RedirectUri   = 'http://127.0.0.1:8080/callback';
  22.   ListenPort    = 8080;
  23.   Scope         = 'openid profile email';
  24.  
  25. // 1. TYPE DECLARATIONS MUST COME BEFORE VARIABLES THAT USE THEM
  26. type
  27.   TCallbackHandler = class
  28.   public
  29.     procedure HandleRequest(Sender: TObject; var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse);
  30.   end;
  31.  
  32. var
  33.   ReceivedCode: string = '';
  34.   ReceivedState: string = '';
  35.   ExpectedState: string;
  36.   AccessToken: string = '';
  37.   AuthURL: string;
  38.   Server: TFPHTTPServer;
  39.   Handler: TCallbackHandler; // Now the compiler knows what TCallbackHandler is
  40.  
  41. // Generates a random string for the 'state' parameter to prevent CSRF
  42. function GenerateRandomString(ALength: Integer): string;
  43. const
  44.   Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  45. var
  46.   I: Integer;
  47. begin
  48.   Result := '';
  49.   for I := 1 to ALength do
  50.     Result := Result + Chars[Random(Length(Chars)) + 1];
  51. end;
  52.  
  53. // HTTP Request Handler for the local callback server
  54. procedure TCallbackHandler.HandleRequest(Sender: TObject; var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse);
  55. begin
  56.   if ARequest.URL = '/callback' then
  57.   begin
  58.     ReceivedCode := ARequest.QueryFields.Values['code'];
  59.     ReceivedState := ARequest.QueryFields.Values['state'];
  60.    
  61.     AResponse.Code := 200;
  62.     AResponse.ContentType := 'text/html';
  63.    
  64.     if (ReceivedCode <> '') and (ReceivedState = ExpectedState) then
  65.     begin
  66.       AResponse.Content := '<html><body><h2 style="color:green;">Authentication Successful!</h2>' +
  67.                            '<p>You can close this window and return to the console.</p></body></html>';
  68.     end
  69.     else
  70.     begin
  71.       AResponse.Content := '<html><body><h2 style="color:red;">Authentication Failed!</h2>' +
  72.                            '<p>State mismatch or missing code.</p></body></html>';
  73.       ReceivedCode := ''; // Invalidate code if state fails
  74.     end;
  75.    
  76.     // Stop the server to unblock the main thread
  77.     TFPHTTPServer(Sender).Active := False;
  78.   end
  79.   else
  80.   begin
  81.     AResponse.Code := 404;
  82.     AResponse.Content := 'Not Found';
  83.   end;
  84. end;
  85.  
  86. // Exchanges the Authorization Code for an Access Token using fcl-net
  87. procedure ExchangeCodeForToken;
  88. var
  89.   Client: TFPHTTPClient;
  90.   PostData: TStringList;
  91.   Response: string;
  92.   JSONData: TJSONData;
  93.   JSONObject: TJSONObject;
  94. begin
  95.   Client := TFPHTTPClient.Create(nil);
  96.   PostData := TStringList.Create;
  97.   try
  98.     Client.AddHeader('Accept', 'application/json');
  99.    
  100.     PostData.Add('grant_type=authorization_code');
  101.     PostData.Add('code=' + ReceivedCode);
  102.     PostData.Add('redirect_uri=' + RedirectUri);
  103.     PostData.Add('client_id=' + ClientId);
  104.     PostData.Add('client_secret=' + ClientSecret);
  105.  
  106.     WriteLn('Exchanging code for token at: ', TokenEndpoint);
  107.     Response := Client.FormPost(TokenEndpoint, PostData);
  108.    
  109.     WriteLn('Token Response: ', Response);
  110.  
  111.     // Parse the JSON response safely
  112.     JSONData := GetJSON(Response);
  113.     try
  114.       if JSONData is TJSONObject then
  115.       begin
  116.         JSONObject := TJSONObject(JSONData);
  117.         if JSONObject.IndexOfName('access_token') <> -1 then
  118.         begin
  119.           AccessToken := JSONObject.Get('access_token');
  120.           WriteLn(#10 + 'SUCCESS! Access Token: ', AccessToken);
  121.         end
  122.         else
  123.           WriteLn(#10 + 'ERROR: "access_token" not found in JSON response.');
  124.       end;
  125.     finally
  126.       JSONData.Free;
  127.     end;
  128.   except
  129.     on E: Exception do
  130.       WriteLn('HTTP Error during token exchange: ', E.Message);
  131.   end;
  132.  
  133.   PostData.Free;
  134.   Client.Free;
  135. end;
  136.  
  137. procedure OpenBrowser(const URL: string);
  138. begin
  139.   WriteLn('Opening browser for authentication...');
  140.   {$IFDEF MSWINDOWS}
  141.   SysUtils.ExecuteProcess('cmd.exe', ['/c', 'start', URL], []);
  142.   {$ELSE}
  143.     {$IFDEF DARWIN}
  144.     SysUtils.ExecuteProcess('/usr/bin/open', [URL], []);
  145.     {$ELSE}
  146.     SysUtils.ExecuteProcess('/usr/bin/xdg-open', [URL], []);
  147.     {$ENDIF}
  148.   {$ENDIF}
  149. end;
  150.  
  151. begin
  152.   Randomize;
  153.   ExpectedState := GenerateRandomString(32);
  154.  
  155.   // 1. Build the Authorization URL
  156.   AuthURL := AuthEndpoint +
  157.              '?response_type=code' +
  158.              '&client_id=' + EncodeURLElement(ClientId) +
  159.              '&redirect_uri=' + EncodeURLElement(RedirectUri) +
  160.              '&scope=' + EncodeURLElement(Scope) +
  161.              '&state=' + EncodeURLElement(ExpectedState);
  162.  
  163.   WriteLn('--- OAuth2 Authorization Code Flow Test ---');
  164.  
  165.   // 2. Open the browser FIRST
  166.   OpenBrowser(AuthURL);
  167.  
  168.   // 3. Setup and start the local HTTP server
  169.   Handler := TCallbackHandler.Create;
  170.   Server := TFPHTTPServer.Create(nil);
  171.   try
  172.     Server.Port := ListenPort;
  173.     Server.OnRequest := @Handler.HandleRequest;
  174.    
  175.     WriteLn('Listening for callback on port ', ListenPort, '...');
  176.     WriteLn('Waiting for authentication...');
  177.    
  178.     // This call blocks the main thread until Server.Active is set to False
  179.     // inside the HandleRequest method.
  180.     Server.Active := True;
  181.   finally
  182.     Server.Free;
  183.     Handler.Free;
  184.   end;
  185.  
  186.   WriteLn('Callback received. Processing...');
  187.  
  188.   // 4. Exchange the code for a token
  189.   if ReceivedCode <> '' then
  190.     ExchangeCodeForToken
  191.   else
  192.     WriteLn('Authentication was cancelled or failed.');
  193.  
  194.   WriteLn(#10 + 'Press Enter to exit...');
  195.   ReadLn;
  196. end.
Which is clean and working code in less than 200 lines and beats my own code..
The errors were assumptions, it mixed up with Synapse, not necessary hallucination. Once corrected I got the above.
It often mixes up Delphi and FPC syntax, though. It tended to use inline vars...
The above code is untouched by me.
(testers should fill in the const block with their own credentials and provider)
« Last Edit: July 22, 2026, 09:39:31 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

schuler

  • Sr. Member
  • ****
  • Posts: 382
I started testing and I must say QWEN 3.7 ... is an impressive model.
I agree. The benchmarks look good too: https://qwen.ai/blog?id=qwen3.7.

(which is the above?)

I am still optimizing code to speed up Qwen 3.6 27B in my own API. It already runs. But it could run faster:
Code: Pascal  [Select][+][-]
  1. git clone https://github.com/joaopauloschuler/neural-api.git
  2. hf download Qwen/Qwen3.6-27B --local-dir ./Qwen36-27
  3. lazbuild -B neural-api/examples/ChatTerminal/ChatTerminal.lpi
  4. neural-api/bin/x86_64-linux/bin/ChatTerminal Qwen36-27/ --stats --profile --greedy
« Last Edit: July 22, 2026, 01:51:01 pm by schuler »

marcelomaurinmartins@gmai

  • New Member
  • *
  • Posts: 26
Dear Schuler,

I have developed two applications for your project, and I really enjoyed working with it.

The first is a Windows installer. The second is a monitoring tool similar to the WampServer manager. I would like to share them with you so you can check whether they fit your vision for the project.

The repository is available here:

https://github.com/marcelomaurin/neural-api-install.git

I can also create versions for Linux and ARM if you are interested.

I am considering using your project at the Ribeirão Preto Municipal Health Department, in São Paulo, Brazil, for email classification.

Please let me know if you need any help. I may not yet have the expertise to contribute directly to the LLM development, but I can certainly assist with tools such as installers, monitoring applications, and system integration.

The repository contains two separate folders for the applications. You are welcome to incorporate them into your project if you find them useful.

schuler

  • Sr. Member
  • ****
  • Posts: 382
The first is a Windows installer. The second is a monitoring tool similar to the WampServer manager. I would like to share them with you so you can check whether they fit your vision for the project.

Dear Marcelo,
I've just forked it and gave it a star.

I am likely to propose some changes via a pull request.

 

TinyPortal © 2005-2018