FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Using free AI power from our Harbour apps !!!
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Using free AI power from our Harbour apps !!!
Posted: Fri Mar 31, 2023 07:07 PM
Dear friends,

This is the fastest free AI available at the moment (GPT4All):
https://wormhole.app/p4LxB#Do1u8TMntAycXyxfg2X5vA

I do appreciate if you download it and check if the EXE is running for you.

You can also, alternatively, download the same files from the github repo:
https://github.com/nomic-ai/gpt4all/blob/main/chat/gpt4all-lora-quantized-win64.exe
https://the-eye.eu/public/AI/models/nomic-ai/gpt4all/gpt4all-lora-quantized.bin (I use an uncensored version in my download)

If you can, I prefeer if you use my files, so we asure we are all using the same files (for the start)

This morning meanwhile I was testing and helping on some python code of GPT4All dev team I realized (I saw and debugged the code) that they just were creating a process with the EXE and routing stdin and stdout, so I thought it is a perfect ocassion to use the great processes functions developed by Przemek!

Next we are going to use it as a process from Harbour:
go.bat
Code (fw): Select all Collapse
@setlocal
@call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
c:\harbour\bin\win\msvc64\hbmk2 gpt4all.prg -comp=msvc64
gpt4all.exe
@endlocal
gpt4all.prg
Code (fw): Select all Collapse
function Main()

   local hProcess, hStdIn, hStdOut, hStdErr, cBuffer, nSize := 1024, cMsg := ""

   hProcess = hb_processOpen( "gpt4all-lora-quantized-win64.exe", @hStdIn, @hStdOut, @hStdErr, .t. )
   ? "GPT4All running..."

   cBuffer = Space( 1024 )
   while ( nReaded := hb_PRead( hStdOut, @cBuffer, nSize, 500 ) ) == 0 
      InKey( 0.1 )
   end
   ? nReaded, AllTrim( cBuffer ), "Hi my friend, how are you ?"

   FWrite( hStdIn, "Hi my friend, how are you ?" + Chr( 13 ) )  

   while ( nReaded := hb_PRead( hStdOut, @cBuffer, nSize, 500 ) ) == 0 
      InKey( 0.1 )
   end
   ? nReaded, AllTrim( cBuffer )

   while .t.
      cBuffer = Space( nSize )
      nReaded = hb_PRead( hStdOut, @cBuffer, nSize, 500 )

      if nReaded > 0
         cMsg += Left( cBuffer, nReaded )
      endif 

      if nReaded < 0   
         exit   
      endif   
   end

   ? cMsg

   hb_processClose( hProcess, .t. )
   FClose( hStdIn )
   FClose( hStdOut )
   FClose( hStdErr )
   
return nil
We need your help to fine tune it, so we can use our own data from our Harbour apps to query the free AI :-D
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sat Apr 01, 2023 07:21 AM
Enhanced version. You can already see the output of the AI from the Harbour app!
GPT4All running...
> Hi my friend, how are you ?
I'm doing great thanks for asking! How about yourself?
> great thanks for asking! How about yourself
gpt4all.prg
Code (fw): Select all Collapse
function Main()

   local hProcess, hStdIn, hStdOut, hStdErr, cBuffer, nSize := 1024

   hProcess = hb_processOpen( "gpt4all-lora-quantized-win64.exe", @hStdIn, @hStdOut, @hStdErr, .T. )
   ? "GPT4All running..."

   cBuffer = Space( 1024 )
   while ( nReaded := hb_PRead( hStdOut, @cBuffer, nSize, 500 ) ) == 0 
      InKey( 0.1 )
   end

   ?? RemoveANSIEscapeCodes( AllTrim( cBuffer ) ), "Hi my friend, how are you ?"
   ?

   FWrite( hStdIn, "Hi my friend, how are you ?" + hb_Eol() )

   while ! Empty( cBuffer )   
      while ( nReaded := hb_PRead( hStdOut, @cBuffer, nSize, 500 ) ) == 0 
         InKey( 0.1 )
      end

      ?? RemoveANSIEscapeCodes( AllTrim( cBuffer ) )
      Alert( RemoveANSIEscapeCodes( AllTrim( cBuffer ) ) )
   end   

   hb_processClose( hProcess, .t. )
   FClose( hStdIn )
   FClose( hStdOut )
   FClose( hStdErr )

   InKey( 0 )

return nil

function RemoveANSIEscapeCodes( cString )

   local cCleanString := "", n

   for n := 1 to Len( cString )
      cChar := SubStr( cString, n, 1 )
      if cChar == Chr( 27 )
         while cChar != "m"
            n++
            cChar = SubStr( cString, n, 1 )
         end      
         cChar = ""
      endif   

      cCleanString := cCleanString + cChar
   next

return cCleanString
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sat Apr 01, 2023 08:38 AM

I just read this in the discord chat for GPT4All:

gpt4all is much better than llama 7b (facebook data) because it's been fine tuned. That's the whole point

Regardless of all this, be aware that the llama models are released under a non-commercial license, so you are not meant to ever use them (or any models derived from them) in any commercial production setting

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sat Apr 01, 2023 09:32 AM

random sample from the GPT-J model (that you can use commercially!) we will be releasing tonight tomorrow morning

just readed in discord chat

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sat Apr 01, 2023 07:28 PM
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sat Apr 01, 2023 07:54 PM

el navegador opera permite usar un vpn gratuito, por lo que es tan sencillo como elegir otro pais...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sat Apr 01, 2023 11:00 PM
Versión funcionando !!!
GPT4All running...
> Hi my friend, how are you ?
I ' m doing great thanks for asking ! How about yourself ?
>
gpt4all.prg
Code (fw): Select all Collapse
function Main()

   local hProcess, hStdIn, hStdOut, hStdErr, cBuffer, nSize := 1024

   hProcess = hb_processOpen( "gpt4all-lora-quantized-win64.exe", @hStdIn, @hStdOut, @hStdErr, .F. )
   ? "GPT4All running..."

   cBuffer = Space( nSize )
   while ( nReaded := hb_PRead( hStdOut, @cBuffer, nSize, 500 ) ) == 0 
      InKey( 0.1 )
   end

   ?? RemoveANSIEscapeCodes( AllTrim( cBuffer ) ), "Hi my friend, how are you ?"
   ?

   FWrite( hStdIn, "Hi my friend, how are you ?" + hb_Eol() )

   while ! Empty( cBuffer )   
      cBuffer = Space( nSize )
      while ( nReaded := hb_PRead( hStdOut, @cBuffer, nSize, 500 ) ) == 0 
      end

      ?? RemoveANSIEscapeCodes( AllTrim( cBuffer ) )
      ?? " "
   end   

   if ! hb_processClose( hProcess, .T. )
      ? "can't close GPT4All process..."
   end
   FClose( hStdIn )
   FClose( hStdOut )
   FClose( hStdErr )

return nil

function RemoveANSIEscapeCodes( cString )

   local cCleanString := "", n

   for n := 1 TO Len( cString )
      cChar := SubStr( cString, n, 1 )
      if cChar == Chr( 27 )
         while cChar != "m"
            n++
            cChar = SubStr( cString, n, 1 )
         end      
         cChar = ""
      endif   

      cCleanString := cCleanString + cChar
   next

return cCleanString
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sun Apr 02, 2023 12:18 AM
Enhanced version:

gpt4all.prg
Code (fw): Select all Collapse
function Main()

   local hProcess, hStdIn, hStdOut, hStdErr, cBuffer, nSize := 1024, cChar, cQuestion

   hProcess = hb_processOpen( "gpt4all-lora-quantized-win64.exe", @hStdIn, @hStdOut, @hStdErr )
   ? "GPT4All running..."

   cBuffer = Space( nSize )
   while ( nReaded := hb_PRead( hStdOut, @cBuffer, nSize, 500 ) ) == 0 
   end

   ?? RemoveANSIEscapeCodes( AllTrim( cBuffer ) ), "What is a galaxy ?"
   ?

   FWrite( hStdIn, "What is a galaxy ?" + hb_Eol() )

   while ! Empty( cBuffer )   
      cBuffer = Space( nSize )
      nReaded = 0
      while ( nReaded += hb_PRead( hStdOut, @cBuffer, nSize, 1000 ) ) == 0 
      end

      ?? RemoveANSIEscapeCodes( SubStr( cBuffer, 1, nReaded ) )
   end   

   while .t.
      cQuestion = ""
      while cChar != Chr( 13 )
         cChar = InKey( 0 )
         cQuestion += cChar
      end   
      if Empty( cQuestion )
         exit
      endif    

      FWrite( hStdIn, cQuestion + hb_Eol() )

      Buffer = "x"
      while ! Empty( cBuffer )   
         cBuffer = Space( nSize )
         nReaded = 0
         while ( nReaded += hb_PRead( hStdOut, @cBuffer, nSize, 500 ) ) == 0 
         end

      ?? RemoveANSIEscapeCodes( SubStr( cBuffer, 1, nReaded ) )
      end   
   end   

   if ! hb_processClose( hProcess, .T. )
      ? "can't close GPT4All process..."
   end
   FClose( hStdIn )
   FClose( hStdOut )
   FClose( hStdErr )

return nil

function RemoveANSIEscapeCodes( cString )

   local cCleanString := "", n

   for n := 1 TO Len( cString )
      cChar := SubStr( cString, n, 1 )
      if cChar == Chr( 27 )
         while cChar != "m"
            n++
            cChar = SubStr( cString, n, 1 )
         end      
         cChar = ""
      endif   

      cCleanString := cCleanString + cChar
   next

return cCleanString
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sun Apr 02, 2023 07:49 AM
Trying to converting it into a Class. Not working yet:

gpt4all.prg
Code (fw): Select all Collapse
#include "hbclass.ch"
#include "FileIO.ch"

function Main()

   local dummy := QOut( "GPT4All running..." )
   local oAI := GPT4All():New() 

   oAI:Read()
   oAI:Write( "Which is the largest city in the world ?" )
   // oAI:Read()

   oAI:End()

return nil   

#define BUFFER_SIZE  1024
#define LOGFILE_NAME "GPT4All.log"

CLASS GPT4All

   DATA   hProcess
   DATA   hStdIn, hStdOut, hStdErr

   METHOD New()
   METHOD Write( cText ) INLINE ::Log( "write: " + cText ), FWrite( ::hStdIn, cText + hb_eol() )
   METHOD Read()
   METHOD End()
   METHOD Log( cMsg )

ENDCLASS   

METHOD New( cPrompt ) CLASS GPT4All

   local hStdIn, hStdOut

   ::hProcess = hb_processOpen( "gpt4all-lora-quantized-win64.exe", @hStdIn, @hStdOut, @::hStdErr )

   ::hStdIn = hStdIn
   ::hStdOut = hStdOut 

   FErase( LOGFILE_NAME )
   ::Log( "process: " + AllTrim( Str( ::hProcess ) ) )
   ::Log( "stdin: " + AllTrim( Str( ::hStdIn ) ) )
   ::Log( "stdout: " + AllTrim( Str( ::hStdOut ) ) )

return Self

METHOD Read() CLASS GPT4All

   local nReaded, cBuffer, cResult

   cBuffer = "x"

   while ! Empty( cBuffer )  
      cBuffer = Space( BUFFER_SIZE )
      nReaded = 0
      while ( nReaded += hb_PRead( ::hStdOut, @cBuffer, BUFFER_SIZE, 1000 ) ) == 0
      end

      ?? RemoveANSIEscapeCodes( SubStr( cBuffer, 1, nReaded ) )
   end 

   ::Log( "after read" )

return 

METHOD End() CLASS GPT4All

   local nResult := hb_processClose( ::hProcess )

   FClose( ::hStdIn )
   FClose( ::hStdOut )
   FClose( ::hStdErr )

   ::Log( "End" )

return nResult   

METHOD Log( cMsg ) CLASS GPT4All 

   local hLogFile

   if ! File( LOGFILE_NAME )
      FClose( FCreate( LOGFILE_NAME ) )
   endif      

   if( ( hLogFile := FOpen( LOGFILE_NAME, FO_WRITE ) ) != -1 )
      FSeek( hLogFile, 0, FS_END )
      FWrite( hLogFile, cMsg + hb_eol(), Len( cMsg ) + Len( hb_eol() ) )
      FClose( hLogFile )
   endif

return nil   

function RemoveANSIEscapeCodes( cString )

   local cCleanString := "", n

   for n := 1 TO Len( cString )
      cChar := SubStr( cString, n, 1 )
      if cChar == Chr( 27 )
         while cChar != "m"
            n++
            cChar = SubStr( cString, n, 1 )
         end      
         cChar = ""
      endif   

      cCleanString := cCleanString + cChar
   next

return cCleanString
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sun Apr 02, 2023 09:02 AM
Enhanced Class version, still we need some fine tunning

gpt4all.prg
Code (fw): Select all Collapse
#include "hbclass.ch"
#include "FileIO.ch"

function Main()

   local dummy := QOut( "GPT4All running..." )
   local oAI := GPT4All():New() 

   oAI:Read()
   ?? "Which is the largest city in the world ?"
   oAI:Write( "Which is the largest city in the world ?" )
   ?
   oAI:Read()

   oAI:End()

return nil   

#define BUFFER_SIZE  1024
#define LOGFILE_NAME "GPT4All.log"

CLASS GPT4All

   DATA   hProcess
   DATA   hStdIn, hStdOut, hStdErr

   METHOD New()
   METHOD Write( cText ) INLINE ::Log( "write: " + cText ), FWrite( ::hStdIn, cText + hb_eol() )
   METHOD Read()
   METHOD End()
   METHOD Log( cMsg )

ENDCLASS   

METHOD New( cPrompt ) CLASS GPT4All

   local hStdIn, hStdOut

   ::hProcess = hb_processOpen( "gpt4all-lora-quantized-win64.exe", @hStdIn, @hStdOut, @::hStdErr )

   ::hStdIn = hStdIn
   ::hStdOut = hStdOut 

   FErase( LOGFILE_NAME )
   ::Log( "process: " + AllTrim( Str( ::hProcess ) ) )
   ::Log( "stdin: " + AllTrim( Str( ::hStdIn ) ) )
   ::Log( "stdout: " + AllTrim( Str( ::hStdOut ) ) )

return Self

METHOD Read() CLASS GPT4All

   local nTotal := 0, nReaded := 1, cBuffer, cResult, nTries

   cBuffer = "x"

   while nReaded > 0
      cBuffer = Space( BUFFER_SIZE )
      nReaded = 0
      nTries = 0
      while ( nReaded += hb_PRead( ::hStdOut, @cBuffer, BUFFER_SIZE, 1000 ) ) == 0
         if ++nTries > 10
            exit
         endif   
      end

      ?? RemoveANSIEscapeCodes( SubStr( cBuffer, 1, nReaded ) )
      ::Log( SubStr( cBuffer, 1, nReaded ) )
   end  

   ::Log( "after read" )

return 

METHOD End() CLASS GPT4All

   local nResult := hb_processClose( ::hProcess )

   FClose( ::hStdIn )
   FClose( ::hStdOut )
   FClose( ::hStdErr )

   ::Log( "End" )

return nResult   

METHOD Log( cMsg ) CLASS GPT4All 

   local hLogFile

   if ! File( LOGFILE_NAME )
      FClose( FCreate( LOGFILE_NAME ) )
   endif      

   if( ( hLogFile := FOpen( LOGFILE_NAME, FO_WRITE ) ) != -1 )
      FSeek( hLogFile, 0, FS_END )
      FWrite( hLogFile, cMsg + hb_eol(), Len( cMsg ) + Len( hb_eol() ) )
      FClose( hLogFile )
   endif

return nil   

function RemoveANSIEscapeCodes( cString )

   local cCleanString := "", n

   for n := 1 TO Len( cString )
      cChar := SubStr( cString, n, 1 )
      if cChar == Chr( 27 )
         while cChar != "m"
            n++
            cChar = SubStr( cString, n, 1 )
         end      
         cChar = ""
      endif   

      cCleanString := cCleanString + cChar
   next

return cCleanString
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sun Apr 02, 2023 02:30 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Sun Apr 02, 2023 02:57 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Using free AI power from our Harbour apps !!!
Posted: Mon Apr 03, 2023 04:39 AM

Will this work with Borland C or just with Microsoft C ONLY ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Mon Apr 03, 2023 06:06 AM

Dear Anser,

It must be a 64 bits EXE only thats why we prefer to use MSVC

The process to create is a 64 bits process, thats why our app must be a 64 bits one

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Using free AI power from our Harbour apps !!!
Posted: Mon Apr 03, 2023 10:25 AM
Look how simple is the new code of gpt4all.prg: You can query the oAI without user intervention too :-)
Code (fw): Select all Collapse
#include "hbclass.ch"
#include "FileIO.ch"

function Main()

   local dummy := QOut( "Loading GPT4All... cpu speed: " + AllTrim( CPUSpeed() ),;
                        If( ! CpuHasAvx2(), "not", "" ) + " AVX2 support. Type exit to finish" )
   local oAI := GPT4All():New(), cMsg

   oAI:Read()
   while ! Empty( cMsg := oAI:Input() ) 
      if cMsg != "exit"
         oAI:Write( cMsg )
         oAI:Read()
      else
         exit
      end      
   end   

   oAI:End()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com